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

@@ -7,5 +7,6 @@
#include "distribution/Uniform.h"
#include "distribution/VonMises.h"
#include "distribution/Region.h"
#include "distribution/Triangle.h"
#endif // DISTRIBUTIONS_H

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;
}

View File

@@ -21,7 +21,7 @@ public:
RandomGenerator() : std::minstd_rand(RANDOM_SEED) {;}
/** ctor with custom seed */
RandomGenerator(result_type) : std::minstd_rand(RANDOM_SEED) {;}
RandomGenerator(result_type seed) : std::minstd_rand(seed) {;}
};

View File

@@ -0,0 +1,50 @@
#ifndef TRIANGLE_H
#define TRIANGLE_H
#include <cmath>
#include <random>
#include "../Random.h"
#include "../../Assertions.h"
#include "Normal.h"
namespace Distribution {
/**
* distribution that forms a triangle
* sigma defines the width (from mu to 0.0, half the width of the triangle's base)
* all values outside of the triangle are zero
*/
template <typename T> class Triangle {
private:
const T mu;
const T sigma;
const T area;
public:
/** ctor */
Triangle(const T mu, const T sigma) : mu(mu), sigma(sigma), area(sigma*sigma) {
}
/** get probability for the given value */
T getProbability(const T val) const {
const T diff = std::abs(val - mu);
if (diff > sigma) {return 0;} // outside of triangle
return (sigma - diff) / area; // inside the triangle
}
/** get the probability for the given value */
static T getProbability(const T mu, const T sigma, const T val) {
Triangle<T> dist(mu, sigma);
return dist.getProbability(val);
}
};
}
#endif // TRIANGLE_H