Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
RandomDistributor< T > Class Template Reference

Represents a generic random distribution. More...

#include <RandomDistributor.h>

Public Member Functions

bool add (T val, double prob, bool checkDuplicates=true)
 Adds a value with an assigned probability to the distribution.
 
void clear ()
 Clears the distribution.
 
get (SumoRNG *which=nullptr) const
 Draw a sample of the distribution.
 
double getOverallProb () const
 Return the sum of the probabilites assigned to the members.
 
const std::vector< double > & getProbs () const
 Returns the probabilities assigned to the members of the distribution.
 
const std::vector< T > & getVals () const
 Returns the members of the distribution.
 
 RandomDistributor ()
 Constructor for an empty distribution.
 
bool remove (T val)
 Removes a value with an assigned probability from the distribution.
 
 ~RandomDistributor ()
 Destructor.
 

Private Attributes

double myProb
 the total probability
 
std::vector< double > myProbs
 the corresponding probabilities
 
std::vector< T > myVals
 the members
 

Detailed Description

template<class T>
class RandomDistributor< T >

Represents a generic random distribution.

This class allows to create random distributions by assigning arbitrary (non-negative) probabilities to its elements. The random number generator used is specified in RandHelper.

See also
RandHelper

Definition at line 46 of file RandomDistributor.h.

Constructor & Destructor Documentation

◆ RandomDistributor()

template<class T >
RandomDistributor< T >::RandomDistributor ( )
inline

Constructor for an empty distribution.

Definition at line 50 of file RandomDistributor.h.

◆ ~RandomDistributor()

template<class T >
RandomDistributor< T >::~RandomDistributor ( )
inline

Destructor.

Definition at line 55 of file RandomDistributor.h.

Member Function Documentation

◆ add()

template<class T >
bool RandomDistributor< T >::add ( val,
double  prob,
bool  checkDuplicates = true 
)
inline

Adds a value with an assigned probability to the distribution.

If the value is already member of the distribution and checkDuplicates is true (the default) the given probability is added to the current. The probability has to be non-negative but values larger than one are allowed (and scaled accordingly when an element is drawn).

Parameters
[in]valThe value to add to the distribution
[in]probThe probability assigned to the value
Returns
true if a new value was added, false if just the probability of an existing one was updated

Definition at line 68 of file RandomDistributor.h.

References RandomDistributor< T >::myProb, RandomDistributor< T >::myProbs, and RandomDistributor< T >::myVals.

Referenced by GUIEdge::addRerouter(), ODDistrict::addSink(), ODDistrict::addSource(), buildNetwork(), ROJTREdge::chooseNext(), MSRouteHandler::closeRoute(), MSRouteHandler::closeVType(), RORouteHandler::closeVType(), GUISettingsHandler::getEventDistribution(), NIImporter_Vissim::NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition::myEndElement(), MSTriggeredRerouter::myStartElement(), MSRouteProbe::notifyEnter(), MSRouteHandler::openRouteDistribution(), MSRouteHandler::openVehicleTypeDistribution(), RORouteHandler::openVehicleTypeDistribution(), NIVissimSingleTypeParser_Geschwindigkeitsverteilungsdefinition::parse(), NIVissimSingleTypeParser_Laengenverteilungsdefinition::parse(), NIVissimSingleTypeParser_Zeitenverteilungsdefinition::parse(), and ODMatrix::parseTimeLine().

Here is the caller graph for this function:

◆ clear()

template<class T >
void RandomDistributor< T >::clear ( )
inline

Clears the distribution.

Definition at line 136 of file RandomDistributor.h.

References RandomDistributor< T >::myProb, RandomDistributor< T >::myProbs, and RandomDistributor< T >::myVals.

Referenced by MSRouteHandler::openRoute(), and RORouteHandler::openRoute().

Here is the caller graph for this function:

◆ get()

template<class T >
T RandomDistributor< T >::get ( SumoRNG which = nullptr) const
inline

Draw a sample of the distribution.

A random sample is drawn according to the assigned probabilities.

Parameters
[in]whichThe random number generator to use; the static one will be used if 0 is passed
Returns
the drawn member

Definition at line 111 of file RandomDistributor.h.

References RandomDistributor< T >::myProb, RandomDistributor< T >::myProbs, RandomDistributor< T >::myVals, and RandHelper::rand().

Referenced by GUIApplicationWindow::checkGamingEvents(), ROJTREdge::chooseNext(), NGRandomNetBuilder::createNewNode(), ODDistrict::getRandomSink(), ODDistrict::getRandomSource(), MSRouteProbe::sampleRoute(), MSTriggeredRerouter::triggerRouting(), and RODFDetector::writeEmitterDefinition().

Here is the caller graph for this function:

◆ getOverallProb()

template<class T >
double RandomDistributor< T >::getOverallProb ( ) const
inline

◆ getProbs()

template<class T >
const std::vector< double > & RandomDistributor< T >::getProbs ( ) const
inline

Returns the probabilities assigned to the members of the distribution.

See getVals for the corresponding members.

Returns
the probabilities assigned to the distribution
See also
RandomDistributor::getVals

Definition at line 160 of file RandomDistributor.h.

References RandomDistributor< T >::myProbs.

Referenced by ODMatrix::applyCurve(), GUITriggeredRerouter::GUITriggeredRerouterEdge::drawGL(), GUITriggeredRerouter::myEndElement(), MSRouteHandler::openRoute(), MSRouteHandler::openVehicleTypeDistribution(), RORouteHandler::openVehicleTypeDistribution(), MSTriggeredRerouter::rerouteParkingArea(), GUITriggeredRerouter::shiftProbs(), MSDevice_Vehroutes::writeOutput(), and MSRouteProbe::writeXMLOutput().

Here is the caller graph for this function:

◆ getVals()

template<class T >
const std::vector< T > & RandomDistributor< T >::getVals ( ) const
inline

◆ remove()

template<class T >
bool RandomDistributor< T >::remove ( val)
inline

Removes a value with an assigned probability from the distribution.

Parameters
[in]valThe value to remove from the distribution
Returns
true if a new value was added, false if just the probability of an existing one was updated

Definition at line 92 of file RandomDistributor.h.

References RandomDistributor< T >::myProb, RandomDistributor< T >::myProbs, and RandomDistributor< T >::myVals.

Referenced by MSTriggeredRerouter::triggerRouting().

Here is the caller graph for this function:

Field Documentation

◆ myProb

◆ myProbs

template<class T >
std::vector<double> RandomDistributor< T >::myProbs
private

◆ myVals


The documentation for this class was generated from the following file: