SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RandomDistributor< T > Class Template Reference

Represents a generic random distribution. More...

#include <RandomDistributor.h>

Public Types

typedef void(* Operation )(const T)
 

Public Member Functions

void add (SUMOReal prob, T val, bool checkDuplicates=true)
 Adds a value with an assigned probability to the distribution. More...
 
void clear ()
 Clears the distribution. More...
 
get (MTRand *which=0) const
 Draw a sample of the distribution. More...
 
SUMOReal getOverallProb () const
 Return the sum of the probabilites assigned to the members. More...
 
const std::vector< SUMOReal > & getProbs () const
 Returns the probabilities assigned to the members of the distribution. More...
 
const std::vector< T > & getVals () const
 Returns the members of the distribution. More...
 
 RandomDistributor (unsigned int maximumSize=std::numeric_limits< unsigned int >::max(), Operation operation=&doNothing)
 Constructor for an empty distribution. More...
 
 ~RandomDistributor ()
 Destructor. More...
 

Static Public Member Functions

static void doNothing (const T)
 

Private Attributes

unsigned int myInsertionIndex
 the index at which the next element shall be inserted if maximumSize is exceeded More...
 
unsigned int myMaximumSize
 the maximumSize of the distribution that shall be maintained More...
 
Operation myOperation
 the operation to perform with replaced elements More...
 
SUMOReal myProb
 the total probability More...
 
std::vector< SUMORealmyProbs
 the corresponding probabilities (acts as a ring buffer if myMaximumSize is reached) More...
 
std::vector< T > myVals
 the members (acts as a ring buffer if myMaximumSize is reached) More...
 

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 55 of file RandomDistributor.h.

Member Typedef Documentation

template<class T>
typedef void(* RandomDistributor< T >::Operation)(const T)

Definition at line 57 of file RandomDistributor.h.

Constructor & Destructor Documentation

template<class T>
RandomDistributor< T >::RandomDistributor ( unsigned int  maximumSize = std::numeric_limits<unsigned int>::max(),
Operation  operation = &doNothing 
)
inline

Constructor for an empty distribution.

Parameters
[in]maximumSizeThe maximum size to maintain older entrys will be removed when adding more than the maximumSize

Definition at line 64 of file RandomDistributor.h.

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

Destructor.

Definition at line 73 of file RandomDistributor.h.

Member Function Documentation

template<class T>
void RandomDistributor< T >::add ( SUMOReal  prob,
val,
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]probThe probability assigned to the value
[in]valThe value to add to the distribution

Definition at line 85 of file RandomDistributor.h.

Referenced by ROJTREdge::chooseNext(), MSRouteHandler::closeRoute(), MSRouteHandler::myEndElement(), RORouteHandler::myEndElement(), MSStateHandler::myStartElement(), MSTriggeredRerouter::myStartElement(), MSRouteProbe::notifyEnter(), MSRouteHandler::openRouteDistribution(), MSRouteHandler::openVehicleTypeDistribution(), and RORouteHandler::openVehicleTypeDistribution().

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

Clears the distribution.

Definition at line 139 of file RandomDistributor.h.

Referenced by MSTriggeredRerouter::myEndElement().

template<class T>
static void RandomDistributor< T >::doNothing ( const T  )
inlinestatic

Definition at line 58 of file RandomDistributor.h.

template<class T>
T RandomDistributor< T >::get ( MTRand which = 0) 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 114 of file RandomDistributor.h.

Referenced by ROJTREdge::chooseNext(), MSTriggeredRerouter::notifyEnter(), and RODFDetector::writeEmitterDefinition().

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

Return the sum of the probabilites assigned to the members.

This should be zero if and only if the distribution is empty.

Returns
the total probability

Definition at line 134 of file RandomDistributor.h.

Referenced by ROJTREdge::chooseNext(), MSRouteHandler::closeRouteDistribution(), MSRouteHandler::closeVehicleTypeDistribution(), RORouteHandler::closeVehicleTypeDistribution(), MSTriggeredRerouter::notifyEnter(), RODFDetector::writeEmitterDefinition(), and MSRouteProbe::writeXMLOutput().

template<class T>
const std::vector<SUMOReal>& 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 166 of file RandomDistributor.h.

Referenced by MSRouteHandler::openRoute(), and MSRouteProbe::writeXMLOutput().

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

Returns the members of the distribution.

See getProbs for the corresponding probabilities.

Returns
the members of the distribution
See Also
RandomDistributor::getProbs

Definition at line 155 of file RandomDistributor.h.

Referenced by MSInsertionControl::add(), and MSRouteProbe::writeXMLOutput().

Field Documentation

template<class T>
unsigned int RandomDistributor< T >::myInsertionIndex
private

the index at which the next element shall be inserted if maximumSize is exceeded

Definition at line 176 of file RandomDistributor.h.

Referenced by RandomDistributor< std::const std::string >::add().

template<class T>
unsigned int RandomDistributor< T >::myMaximumSize
private

the maximumSize of the distribution that shall be maintained

Definition at line 174 of file RandomDistributor.h.

Referenced by RandomDistributor< std::const std::string >::add().

template<class T>
Operation RandomDistributor< T >::myOperation
private

the operation to perform with replaced elements

Definition at line 178 of file RandomDistributor.h.

Referenced by RandomDistributor< std::const std::string >::add(), and RandomDistributor< std::const std::string >::clear().

template<class T>
std::vector<SUMOReal> RandomDistributor< T >::myProbs
private
template<class T>
std::vector<T> RandomDistributor< T >::myVals
private

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