Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
RandHelper Class Reference

Utility functions for using a global, resetable random number generator. More...

#include <RandHelper.h>

Collaboration diagram for RandHelper:
[legend]

Static Public Member Functions

static long long int count ()
 
template<class T >
static const T & getRandomFrom (const std::vector< T > &v, SumoRNG *rng=nullptr)
 Returns a random element from the given vector.
 
static int getSeed (SumoRNG *which=nullptr)
 
static void initRand (SumoRNG *which=nullptr, const bool random=false, const int seed=23423)
 Initialises the random number generator with hardware randomness or seed.
 
static void loadState (const std::string &state, SumoRNG *rng=nullptr)
 load rng state from string
 
static uint32_t murmur3_32 (const std::string &key2, int seed)
 string hashing adapted from https://en.wikipedia.org/wiki/MurmurHash
 
static double rand (double maxV, SumoRNG *rng=nullptr)
 Returns a random real number in [0, maxV)
 
static double rand (double minV, double maxV, SumoRNG *rng=nullptr)
 Returns a random real number in [minV, maxV)
 
static int rand (int maxV, SumoRNG *rng=nullptr)
 Returns a random integer in [0, maxV-1].
 
static int rand (int minV, int maxV, SumoRNG *rng=nullptr)
 Returns a random integer in [minV, maxV-1].
 
static long long int rand (long long int maxV, SumoRNG *rng=nullptr)
 Returns a random 64 bit integer in [0, maxV-1].
 
static long long int rand (long long int minV, long long int maxV, SumoRNG *rng=nullptr)
 Returns a random 64 bit integer in [minV, maxV-1].
 
static double rand (SumoRNG *rng=nullptr)
 Returns a random real number in [0, 1)
 
static double randExp (double rate, SumoRNG *rng=nullptr)
 Access to a random number from an exponential distribution.
 
static double randHash (long long int x)
 return a value scrambled value from [0, 1]
 
static double randNorm (double mean, double variance, SumoRNG *rng=nullptr)
 Access to a random number from a normal distribution.
 
static std::string saveState (SumoRNG *rng=nullptr)
 save rng state to string
 
template<class T >
static void shuffle (std::vector< T > &v, SumoRNG *rng=nullptr)
 

Static Protected Member Functions

static uint32_t murmur_32_scramble (uint32_t k)
 helper function for murmur_32_scramble from https://en.wikipedia.org/wiki/MurmurHash
 

Static Protected Attributes

static SumoRNG myRandomNumberGenerator
 the default random number generator to use
 

Detailed Description

Utility functions for using a global, resetable random number generator.

Definition at line 127 of file RandHelper.h.

Member Function Documentation

◆ count()

static long long int RandHelper::count ( )
inlinestatic

Definition at line 252 of file RandHelper.h.

References SumoRNG::count, and myRandomNumberGenerator.

◆ getRandomFrom()

template<class T >
static const T & RandHelper::getRandomFrom ( const std::vector< T > &  v,
SumoRNG *  rng = nullptr 
)
inlinestatic

Returns a random element from the given vector.

Definition at line 213 of file RandHelper.h.

References rand().

Referenced by MSEdge::getDepartLane(), MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS(), AGCity::getRandomStreet(), and AGAdult::randomFreeWorkPosition().

Here is the caller graph for this function:

◆ getSeed()

int RandHelper::getSeed ( SumoRNG *  which = nullptr)
static

Definition at line 70 of file RandHelper.cpp.

References myRandomNumberGenerator, and SumoRNG::origSeed.

◆ initRand()

void RandHelper::initRand ( SumoRNG *  which = nullptr,
const bool  random = false,
const int  seed = 23423 
)
static

Initialises the random number generator with hardware randomness or seed.

Definition at line 57 of file RandHelper.cpp.

References myRandomNumberGenerator, and SumoRNG::setSeed().

Referenced by SystemFrame::initRandGlobal(), and MSLane::initRNGs().

Here is the caller graph for this function:

◆ loadState()

static void RandHelper::loadState ( const std::string &  state,
SumoRNG *  rng = nullptr 
)
inlinestatic

load rng state from string

Definition at line 232 of file RandHelper.h.

References myRandomNumberGenerator, and SAVE_ONLY_COUNT.

Referenced by MSLane::loadRNGState(), and MSStateHandler::myStartElement().

Here is the caller graph for this function:

◆ murmur3_32()

static uint32_t RandHelper::murmur3_32 ( const std::string &  key2,
int  seed 
)
inlinestatic

string hashing adapted from https://en.wikipedia.org/wiki/MurmurHash

Definition at line 266 of file RandHelper.h.

References murmur_32_scramble().

Referenced by MESegment::initSegment().

Here is the caller graph for this function:

◆ murmur_32_scramble()

static uint32_t RandHelper::murmur_32_scramble ( uint32_t  k)
inlinestaticprotected

helper function for murmur_32_scramble from https://en.wikipedia.org/wiki/MurmurHash

Definition at line 305 of file RandHelper.h.

Referenced by murmur3_32().

Here is the caller graph for this function:

◆ rand() [1/7]

static double RandHelper::rand ( double  maxV,
SumoRNG *  rng = nullptr 
)
inlinestatic

Returns a random real number in [0, maxV)

Definition at line 139 of file RandHelper.h.

References rand().

◆ rand() [2/7]

static double RandHelper::rand ( double  minV,
double  maxV,
SumoRNG *  rng = nullptr 
)
inlinestatic

Returns a random real number in [minV, maxV)

Definition at line 144 of file RandHelper.h.

References rand().

◆ rand() [3/7]

static int RandHelper::rand ( int  maxV,
SumoRNG *  rng = nullptr 
)
inlinestatic

Returns a random integer in [0, maxV-1].

Definition at line 149 of file RandHelper.h.

References SumoRNG::count, and myRandomNumberGenerator.

◆ rand() [4/7]

static int RandHelper::rand ( int  minV,
int  maxV,
SumoRNG *  rng = nullptr 
)
inlinestatic

Returns a random integer in [minV, maxV-1].

Definition at line 170 of file RandHelper.h.

References rand().

◆ rand() [5/7]

static long long int RandHelper::rand ( long long int  maxV,
SumoRNG *  rng = nullptr 
)
inlinestatic

Returns a random 64 bit integer in [0, maxV-1].

Definition at line 175 of file RandHelper.h.

References SumoRNG::count, myRandomNumberGenerator, and rand().

◆ rand() [6/7]

static long long int RandHelper::rand ( long long int  minV,
long long int  maxV,
SumoRNG *  rng = nullptr 
)
inlinestatic

Returns a random 64 bit integer in [minV, maxV-1].

Definition at line 200 of file RandHelper.h.

References rand().

◆ rand() [7/7]

double RandHelper::rand ( SumoRNG *  rng = nullptr)
static

Returns a random real number in [0, 1)

Definition at line 78 of file RandHelper.cpp.

References SumoRNG::count, gDebugFlag1, OutputDevice::getDevice(), SumoRNG::id, and myRandomNumberGenerator.

Referenced by MSPModel_JuPedSim::add(), MSPModel_JuPedSim_legacy::add(), RORouteDef::addAlternative(), RONet::addFlow(), MSRouteHandler::addFlowTransportable(), MSRouteHandler::addPersonTrip(), MSRouteHandler::addWalk(), MSAbstractLaneChangeModel::avoidOvertakeRight(), MSVehicle::betterContinuation(), MSLink::blockedAtTime(), NGEdge::buildNBEdge(), MSBaseVehicle::calculateArrivalParams(), RONet::checkFlows(), MSVehicle::checkLinkLeader(), MSSwarmTrafficLightLogic::choosePolicy(), RORouteHandler::closePersonFlow(), MSRouteHandler::closeTransportableFlow(), ODMatrix::computeDeparts(), MSInsertionControl::computeRandomDepartOffset(), NGRandomNetBuilder::createNet(), NGRandomNetBuilder::createNewNode(), MSCFModel_Kerner::createVehicleVariables(), MSCFModel_Daniel1::dawdle(), MSCFModel_KraussOrig1::dawdle(), MSCFModel_SmartSK::dawdle(), MSCFModel_Krauss::dawdle2(), MSCFModel_KraussX::dawdleX(), AGPerson::decide(), MSSwarmTrafficLightLogic::decidePolicy(), AGFreeTime::decideTypeOfTrip(), MSInsertionControl::determineCandidates(), MSDevice::equippedByDefaultAssignmentOptions(), MSPModel_JuPedSim::execute(), MSPModel_JuPedSim_legacy::execute(), MSCFModel_Kerner::finalizeSpeed(), MSCFModel_PWag2009::followSpeed(), MSCFModel_W99::followSpeed(), AGHousehold::generateCars(), AGWorkPosition::generateClosingTime(), AGWorkPosition::generateOpeningTime(), AGCity::generatePopulation(), AGActivities::generateRandomTraffic(), RandomDistributor< T >::get(), MSStoppingPlace::getAccessPos(), MSLane::getDepartPosLat(), MSLane::getDepartSpeed(), AGDataAndStatistics::getInverseExpRandomValue(), AGDataAndStatistics::getPoissonsNumberOfChildren(), AGDataAndStatistics::getRandom(), AGDataAndStatistics::getRandomCityGateByIncoming(), AGDataAndStatistics::getRandomCityGateByOutgoing(), getRandomFrom(), AGDataAndStatistics::getRandomPopDistributed(), MapMatcher< E, L, N >::getTaz(), IntermodalEdge< E, L, N, V >::getTravelTimeStaticRandomized(), MSIdling_RandomCircling::idle(), MSDevice_BTreceiver::inquiryDelaySlots(), MSLane::insertVehicle(), MSEdge::insertVehicle(), MSSOTLTrafficLightLogic::isThresholdPassed(), RouteCostCalculator< R, E, V >::keepRoute(), MSDevice_Bluelight::notifyMove(), RGBColor::parseColor(), SUMOVehicleParserHelper::parseWalkPos(), MSCFModel_NaSch::patchSpeedBeforeLC(), MSVehicle::planMoveInternal(), MSPModel_Striping::PState::PState(), rand(), rand(), rand(), rand(), rand(), randExp(), randNorm(), RGBColor::randomHue(), AGPosition::randomPositionInStreet(), AGActivity::randomTimeBetween(), MSStoppingPlaceRerouter::rerouteStoppingPlace(), MEVehicle::setApproaching(), MSVehicle::setApproachingForAllLinks(), MSStageDriving::setArrived(), MSStageTrip::setArrived(), MSBaseVehicle::setDepartAndArrivalEdge(), GUILane::setFunctionalColor(), shuffle(), SigmoidLogic::sigmoidLogic(), NGNet::toNB(), MSTriggeredRerouter::triggerRouting(), MSCFModel_SmartSK::updateMyHeadway(), MSPModel_Striping::PState::walk(), and RODFDetector::writeEmitterDefinition().

◆ randExp()

double RandHelper::randExp ( double  rate,
SumoRNG *  rng = nullptr 
)
static

Access to a random number from an exponential distribution.

Definition at line 134 of file RandHelper.cpp.

References rand().

Referenced by SUMOVehicleParameter::incrementFlow().

Here is the caller graph for this function:

◆ randHash()

static double RandHelper::randHash ( long long int  x)
inlinestatic

return a value scrambled value from [0, 1]

Definition at line 257 of file RandHelper.h.

References splitmix64().

Referenced by MSRoutingEngine::applyExtras(), ROEdge::getTravelTimeStaticPriorityFactorRandomized(), ROEdge::getTravelTimeStaticRandomized(), and MESegment::overtake().

Here is the caller graph for this function:

◆ randNorm()

double RandHelper::randNorm ( double  mean,
double  variance,
SumoRNG *  rng = nullptr 
)
static

Access to a random number from a normal distribution.

Definition at line 121 of file RandHelper.cpp.

References rand().

Referenced by MSCFModel_Wiedemann::_v(), MSCFModel_EIDM::finalizeSpeed(), MSDevice_Friction::notifyMove(), Distribution_Parameterized::sample(), MSDevice_ToC::sampleResponseTime(), OUProcess::step(), OUProcess::step(), and AGActivityGen::varDepTime().

Here is the caller graph for this function:

◆ saveState()

static std::string RandHelper::saveState ( SumoRNG *  rng = nullptr)
inlinestatic

save rng state to string

Definition at line 219 of file RandHelper.h.

References SumoRNG::count, myRandomNumberGenerator, and SAVE_ONLY_COUNT.

Referenced by MSStateHandler::saveRNGs(), and MSLane::saveRNGStates().

Here is the caller graph for this function:

◆ shuffle()

template<class T >
static void RandHelper::shuffle ( std::vector< T > &  v,
SumoRNG *  rng = nullptr 
)
inlinestatic

Definition at line 246 of file RandHelper.h.

References rand(), and std::swap().

Referenced by MSTrainHelper::computeUnboardingPositions().

Here is the caller graph for this function:

Field Documentation

◆ myRandomNumberGenerator

SumoRNG RandHelper::myRandomNumberGenerator
staticprotected

the default random number generator to use

Definition at line 299 of file RandHelper.h.

Referenced by count(), getSeed(), initRand(), loadState(), rand(), rand(), rand(), and saveState().


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