Menge
Modular Pedestrian Simulation Framework for Research and Development
|
A number generator based on a weighted probability of a discrete value set. More...
#include <RandGenerator.h>
Public Member Functions | |
WeightedIntGenerator () | |
Constructor. | |
WeightedIntGenerator (const WeightedIntGenerator &gen) | |
Copy constructor. More... | |
virtual int | getValue () const |
Return a value based on the integer generation rules. More... | |
virtual int | getValueConcurrent () const |
Return a value based on the integer generation rules - performed in a thread-safe manner. More... | |
void | addValue (int value, float weight) |
Add a value to the set. More... | |
virtual void | print (Logger &out) const |
Function for converting the generator to a string on a output stream. More... | |
virtual IntGenerator * | copy () const |
Create a copy of itself. More... | |
void | finalize () |
Finalizes the generator so that it can generate values. More... | |
Public Member Functions inherited from Menge::Math::IntGenerator | |
IntGenerator () | |
Constructor. | |
virtual | ~IntGenerator () |
Virtual destructor. | |
Protected Attributes | |
UniformFloatGenerator | _dice |
A uniform float generator for "rolling the dice". | |
std::vector< WeightedInt > | _pairs |
The weighted values to select from. | |
SimpleLock | _lock |
The lock for guaranteeing threadsafe random number generation. | |
Friends | |
Logger & | operator<< (Logger &out, const WeightedIntGenerator &gen) |
Friend function for writing string representation to an output stream. More... | |
A number generator based on a weighted probability of a discrete value set.
Each value in the set is associated with a weight. The relative probability of any given value is that value's weight, divided by the summed weight of all values.
Menge::Math::WeightedIntGenerator::WeightedIntGenerator | ( | const WeightedIntGenerator & | gen | ) |
Copy constructor.
The constructed copy should not share the same seed as the original.
gen | The generator to copy. |
void Menge::Math::WeightedIntGenerator::addValue | ( | int | value, |
float | weight | ||
) |
Add a value to the set.
value | The value to add to the set. |
weight | The weight of the corresponding value. |
|
virtual |
Create a copy of itself.
This should only be called after the generator has been finalized. Otherwise, the copy will need to be finalized as well.
Implements Menge::Math::IntGenerator.
void Menge::Math::WeightedIntGenerator::finalize | ( | ) |
Finalizes the generator so that it can generate values.
When finished adding points, call this function to post-process them. Calling WeightedIntGenerator::getValue before calling this will lead to unpredictable results. Furthermore, calling WeightedIntGenerator::addValue after calling finalize will likewise lead to unpredictable results.
|
virtual |
Return a value based on the integer generation rules.
Implements Menge::Math::IntGenerator.
|
virtual |
Return a value based on the integer generation rules - performed in a thread-safe manner.
This is the basic functionality that must be overwridden by derived classes.
Implements Menge::Math::IntGenerator.
|
virtual |
Function for converting the generator to a string on a output stream.
out | The output stream to write the string representation to. |
Implements Menge::Math::IntGenerator.
|
friend |
Friend function for writing string representation to an output stream.
out | The output stream. |
gen | An instance of the generator to represent as a string. |