RandomDistributor< T > Class Template Reference

#include <RandomDistributor.h>


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 52 of file 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< SUMOReal > myProbs
 the corresponding probabilities
std::vector< T > myVals
 the members

Constructor & Destructor Documentation

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

Constructor for an empty distribution.

Definition at line 55 of file RandomDistributor.h.

00055 : myProb(0) { }

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

Destructor.

Definition at line 58 of file RandomDistributor.h.

00058 { }


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] prob The probability assigned to the value
[in] val The value to add to the distribution

Definition at line 70 of file RandomDistributor.h.

Referenced by MSRouteProbe::addRoute(), ODDistrict::addSink(), ODDistrict::addSource(), ROJTREdge::chooseNext(), MSRouteHandler::closeRoute(), MSRouteHandler::myEndElement(), MSTriggeredRerouter::myStartElement(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), MSRouteHandler::openRouteDistribution(), and MSRouteHandler::openVehicleTypeDistribution().

00070                                                               {
00071         assert(prob>=0);
00072         myProb += prob;
00073         if (checkDuplicates) {
00074             for (size_t i=0; i<myVals.size(); i++) {
00075                 if (val==myVals[i]) {
00076                     myProbs[i] += prob;
00077                     return;
00078                 }
00079             }
00080         }
00081         myVals.push_back(val);
00082         myProbs.push_back(prob);
00083     }

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

Clears the distribution.

Definition at line 116 of file RandomDistributor.h.

Referenced by MSTriggeredRerouter::myEndElement(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), and MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement().

00116                  {
00117         myProb = 0;
00118         myVals.clear();
00119         myProbs.clear();
00120     }

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

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

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

Referenced by GUIEmitter::getEdgeProbs(), and MSRouteProbe::writeXMLOutput().

00140                                                 {
00141         return myProbs;
00142     }

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

Referenced by MSEmitControl::add(), MSEmitter::MSEmitterChild::getAllRoutes(), MSCalibrator::MSCalibratorChild::getAllRoutes(), GUIEmitter::getEdgeProbs(), ODDistrict::sinkNumber(), ODDistrict::sourceNumber(), and MSRouteProbe::writeXMLOutput().

00129                                         {
00130         return myVals;
00131     }


Field Documentation

template<class T>
SUMOReal RandomDistributor< T >::myProb [private]

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:

Generated on Wed May 5 00:06:59 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6