Line data Source code
1 : /////////////////////////////////////////////////////////////////////////// 2 : // Spetabaru - Berenger Bramas MPCDF - 2017 3 : // Under LGPL Licence, please you must read the LICENCE file. 4 : /////////////////////////////////////////////////////////////////////////// 5 : #ifndef SPPROBABILITY_HPP 6 : #define SPPROBABILITY_HPP 7 : 8 : #include <cassert> 9 : 10 : /** 11 : * This class should be used to inform the runtime 12 : * about the propability that a potential task will 13 : * modify its target data. 14 : */ 15 : class SpProbability{ 16 : bool activated; 17 : double probability; 18 : int includedProbabilities; 19 : public: 20 : explicit SpProbability(const double inProbability) 21 : : activated(true), probability(inProbability), includedProbabilities(1){ 22 : assert(0 <= probability && probability <= 1); 23 : } 24 : 25 1300 : explicit SpProbability() 26 1300 : : activated(false), probability(0), includedProbabilities(0){ 27 1300 : assert(0 <= probability && probability <= 1); 28 1300 : } 29 : 30 : double getProbability() const{ 31 : return probability; 32 : } 33 : 34 : bool isUsed() const{ 35 : return activated; 36 : } 37 : 38 0 : void append(const SpProbability& other){ 39 0 : if(activated == false){ 40 0 : (*this) = other; 41 : } 42 0 : else if(other.activated == true){ 43 0 : probability = (probability*includedProbabilities + other.probability)/includedProbabilities; 44 0 : includedProbabilities += 1; 45 : } 46 0 : } 47 : }; 48 : 49 : #endif 50 :