#include <RandomDistributor.h>
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.
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. | |
| T | 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 | |
| RandomDistributor< T >::RandomDistributor | ( | ) | [inline] |
Constructor for an empty distribution.
Definition at line 55 of file RandomDistributor.h.
00055 : myProb(0) { }
| RandomDistributor< T >::~RandomDistributor | ( | ) | [inline] |
| void RandomDistributor< T >::add | ( | SUMOReal | prob, | |
| T | 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).
| [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 }
| 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().
| T RandomDistributor< T >::get | ( | ) | const [inline] |
Draw a sample of the distribution.
A random sample is drawn according to the assigned probabilities.
Definition at line 91 of file RandomDistributor.h.
Referenced by MSEmitter::MSEmitter_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSCalibrator::MSCalibrator_FileTriggeredChild::buildAndScheduleFlowVehicle(), ROJTREdge::chooseNext(), ODDistrict::getRandomSink(), ODDistrict::getRandomSource(), MSEmitter::MSEmitterChild::getRndRoute(), MSCalibrator::MSCalibratorChild::getRndRoute(), MSEmitter::MSEmitterChild::getRndVType(), MSCalibrator::MSCalibratorChild::getRndVType(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), MSTriggeredRerouter::reroute(), GUIEmitter::GUIEmitterChild_UserTriggeredChild::wrappedExecute(), and RODFDetector::writeEmitterDefinition().
00091 { 00092 if (myProb==0) { 00093 throw OutOfBoundsException(); 00094 } 00095 SUMOReal prob = RandHelper::rand(myProb); 00096 for (size_t i=0; i<myVals.size(); i++) { 00097 if (prob<myProbs[i]) { 00098 return myVals[i]; 00099 } 00100 prob -= myProbs[i]; 00101 } 00102 return myVals.back(); 00103 }
| 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.
Definition at line 111 of file RandomDistributor.h.
Referenced by MSEmitter::MSEmitter_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSCalibrator::MSCalibrator_FileTriggeredChild::buildAndScheduleFlowVehicle(), ROJTREdge::chooseNext(), MSRouteHandler::closeRouteDistribution(), MSRouteHandler::closeVehicleTypeDistribution(), MSEmitter::MSEmitterChild::hasRoutes(), MSCalibrator::MSCalibratorChild::hasRoutes(), MSEmitter::MSEmitterChild::hasVTypes(), MSCalibrator::MSCalibratorChild::hasVTypes(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), MSTriggeredRerouter::reroute(), GUIEmitter::GUIEmitterChild_UserTriggeredChild::wrappedExecute(), RODFDetector::writeEmitterDefinition(), and MSRouteProbe::writeXMLOutput().
00111 { 00112 return myProb; 00113 }
| 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.
Definition at line 140 of file RandomDistributor.h.
Referenced by GUIEmitter::getEdgeProbs(), and MSRouteProbe::writeXMLOutput().
00140 { 00141 return myProbs; 00142 }
| const std::vector<T>& RandomDistributor< T >::getVals | ( | ) | const [inline] |
Returns the members of the distribution.
See getProbs for the corresponding probabilities.
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 }
SUMOReal RandomDistributor< T >::myProb [private] |
the total probability
Definition at line 146 of file RandomDistributor.h.
Referenced by RandomDistributor< MSVehicleType * >::add(), RandomDistributor< MSVehicleType * >::clear(), RandomDistributor< MSVehicleType * >::get(), and RandomDistributor< MSVehicleType * >::getOverallProb().
std::vector<SUMOReal> RandomDistributor< T >::myProbs [private] |
the corresponding probabilities
Definition at line 150 of file RandomDistributor.h.
Referenced by RandomDistributor< MSVehicleType * >::add(), RandomDistributor< MSVehicleType * >::clear(), RandomDistributor< MSVehicleType * >::get(), and RandomDistributor< MSVehicleType * >::getProbs().
std::vector<T> RandomDistributor< T >::myVals [private] |
the members
Definition at line 148 of file RandomDistributor.h.
Referenced by RandomDistributor< MSVehicleType * >::add(), RandomDistributor< MSVehicleType * >::clear(), RandomDistributor< MSVehicleType * >::get(), and RandomDistributor< MSVehicleType * >::getVals().
1.5.6