21 #ifndef RandomDistributor_h
22 #define RandomDistributor_h
88 if (checkDuplicates) {
89 for (
size_t i = 0; i <
myVals.size(); i++) {
119 for (
size_t i = 0; i <
myVals.size(); i++) {
141 for (
size_t i = 0; i <
myVals.size(); i++) {
RandomDistributor(unsigned int maximumSize=std::numeric_limits< unsigned int >::max(), Operation operation=&doNothing)
Constructor for an empty distribution.
unsigned int myInsertionIndex
the index at which the next element shall be inserted if maximumSize is exceeded
const std::vector< SUMOReal > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
Represents a generic random distribution.
void(* Operation)(const T)
std::vector< T > myVals
the members (acts as a ring buffer if myMaximumSize is reached)
static SUMOReal rand()
Returns a random real number in [0, 1)
const std::vector< T > & getVals() const
Returns the members of the distribution.
SUMOReal myProb
the total probability
~RandomDistributor()
Destructor.
Operation myOperation
the operation to perform with replaced elements
std::vector< SUMOReal > myProbs
the corresponding probabilities (acts as a ring buffer if myMaximumSize is reached) ...
unsigned int myMaximumSize
the maximumSize of the distribution that shall be maintained
void clear()
Clears the distribution.
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.
static void doNothing(const T)
void add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.