some fixes [multithreading,..]

needed interface changes [new options]
logger for android
wifi-ap-optimization
new test-cases
This commit is contained in:
2016-09-28 12:19:14 +02:00
parent 91e3367372
commit 4f511d907e
62 changed files with 1418 additions and 175 deletions

View File

@@ -21,8 +21,11 @@ template <typename T> class DrawList {
/** the cumulative probability up to this element */
double cumProbability;
/** the element's own probability */
double probability;
/** ctor */
Entry(T element, const double cumProbability) : element(element), cumProbability(cumProbability) {;}
Entry(T element, const double cumProbability, const double probability) : element(element), cumProbability(cumProbability), probability(probability) {;}
/** compare for searches */
bool operator < (const double val) const {return cumProbability < val;}
@@ -37,13 +40,30 @@ private:
/** all contained elements */
std::vector<Entry> elements;
/** random number generator */
RandomGenerator gen;
/** the used random number generator */
RandomGenerator& gen;
private:
/** default random generator. fallback */
RandomGenerator defRndGen;
public:
/** ctor */
DrawList() : cumProbability(0) {
/** ctor with random seed */
DrawList() : cumProbability(0), gen(defRndGen) {
;
}
/** ctor with custom seed */
DrawList(const uint32_t seed) : cumProbability(0), gen(defRndGen(seed)) {
;
}
/** ctor with custom RandomNumberGenerator */
DrawList(RandomGenerator& gen) : cumProbability(0), gen(gen) {
;
}
@@ -58,15 +78,20 @@ public:
elements.clear();
}
/** adjust the reserved list size */
void reserve(const size_t numElements) {
elements.reserve(numElements);
}
/** add a new user-element and its probability */
void add(T element, const double probability) {
Assert::isTrue(probability >= 0, "probability must not be negative!");
cumProbability += probability;
elements.push_back(Entry(element, cumProbability));
elements.push_back(Entry(element, cumProbability, probability));
}
/** get a random element based on its probability */
T get() {
T get(double& elemProbability) {
// generate random number between [0:cumProbability]
std::uniform_real_distribution<> dist(0, cumProbability);
@@ -81,6 +106,7 @@ public:
Assert::isFalse(tmp == elements.end(), "draw() did not find a valid element");
// done
elemProbability = (*tmp).probability;
return (*tmp).element;
}