SUMO - Simulation of Urban MObility
RandomDistributor< T > Class Template Reference

Represents a generic random distribution. More...

#include <RandomDistributor.h>

Public Member Functions

void add (SUMOReal prob, T val, bool checkDuplicates=true)
 Adds a value with an assigned probability to the distribution.
void clear ()
 Clears the distribution.
get () const
 Draw a sample of the distribution.
SUMOReal getOverallProb () const
 Return the sum of the probabilites assigned to the members.
const std::vector< SUMOReal > & 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.
 ~RandomDistributor ()
 Destructor.

Private Attributes

SUMOReal myProb
 the total probability
std::vector< SUMORealmyProbs
 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 54 of file RandomDistributor.h.


Constructor & Destructor Documentation

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

Constructor for an empty distribution.

Definition at line 57 of file RandomDistributor.h.

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

Destructor.

Definition at line 60 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 72 of file RandomDistributor.h.

Referenced by ODDistrict::addSink(), ODDistrict::addSource(), ROJTREdge::chooseNext(), MSRouteHandler::closeRoute(), MSRouteHandler::myEndElement(), MSTriggeredRerouter::myStartElement(), MSRouteProbe::notifyEnter(), MSRouteHandler::openRouteDistribution(), and MSRouteHandler::openVehicleTypeDistribution().

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

Clears the distribution.

Definition at line 118 of file RandomDistributor.h.

Referenced by MSTriggeredRerouter::myEndElement().

template<class T>
T RandomDistributor< T >::get ( ) const [inline]

Draw a sample of the distribution.

A random sample is drawn according to the assigned probabilities.

Returns:
the drawn member

Definition at line 93 of file RandomDistributor.h.

Referenced by ROJTREdge::chooseNext(), ODDistrict::getRandomSink(), ODDistrict::getRandomSource(), 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 113 of file RandomDistributor.h.

Referenced by ROJTREdge::chooseNext(), MSRouteHandler::closeRouteDistribution(), MSRouteHandler::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 142 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 131 of file RandomDistributor.h.

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


Field Documentation


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines