Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00504_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00504_source.php on line 2
The ARGoS Website

rng.h
Go to the documentation of this file.
1 
9 #ifndef ARGOS_RANDOM
10 #define ARGOS_RANDOM
11 
12 namespace argos {
13  class CRandom;
14 }
15 
16 #include <argos3/core/utility/math/angles.h>
17 #include <argos3/core/utility/math/range.h>
18 #include <map>
19 
20 namespace argos {
21 
81  class CRandom {
82 
83  public:
84 
90  class CRNG {
91 
92  public:
93 
100  CRNG(UInt32 un_seed);
101 
106  CRNG(const CRNG& c_rng);
107 
111  virtual ~CRNG();
112 
117  inline UInt32 GetSeed() const throw() {
118  return m_unSeed;
119  }
120 
127  inline void SetSeed(UInt32 un_seed) throw() {
128  m_unSeed = un_seed;
129  }
130 
135  void Reset();
136 
142  bool Bernoulli(Real f_true = 0.5);
143 
149  CRadians Uniform(const CRange<CRadians>& c_range);
150 
156  Real Uniform(const CRange<Real>& c_range);
157 
163  SInt32 Uniform(const CRange<SInt32>& c_range);
164 
170  UInt32 Uniform(const CRange<UInt32>& c_range);
171 
177  Real Exponential(Real f_mean);
178 
185  Real Gaussian(Real f_std_dev, Real f_mean = 0.0f);
186 
192  Real Rayleigh(Real f_sigma);
193 
200  Real Lognormal(Real f_sigma, Real f_mu);
201 
202  private:
203 
204  /*
205  * Generates a random 32bit unsigned integer.
206  * Used internally by all other functions.
207  */
208  UInt32 Uniform32bit();
209 
210  private:
211 
212  UInt32 m_unSeed;
213  UInt32* m_punState;
214  SInt32 m_nIndex;
215 
216  };
217 
222  class CCategory {
223 
224  public:
225 
231  CCategory(const std::string& str_id,
232  UInt32 un_seed);
233 
237  virtual ~CCategory();
238 
243  inline const std::string& GetId() const throw() {
244  return m_strId;
245  }
250  void SetId(const std::string& str_id) {
251  m_strId = str_id;
252  }
253 
258  inline UInt32 GetSeed() const {
259  return m_unSeed;
260  }
267  void SetSeed(UInt32 un_seed);
268 
273  CRNG* CreateRNG();
274 
278  void ResetRNGs();
279 
285  void ReseedRNGs();
286 
287  private:
288 
289  std::string m_strId;
290  std::vector<CRNG*> m_vecRNGList;
291  UInt32 m_unSeed;
292  CRNG m_cSeeder;
293  CRange<UInt32> m_cSeedRange;
294  };
295 
296  public:
297 
304  static bool CreateCategory(const std::string& str_category,
305  UInt32 un_seed);
311  static CCategory& GetCategory(const std::string& str_category);
312 
318  static bool ExistsCategory(const std::string& str_category);
319 
324  static void RemoveCategory(const std::string& str_category);
325 
331  static CRNG* CreateRNG(const std::string& str_category);
332 
338  static UInt32 GetSeedOf(const std::string& str_category);
339 
347  static void SetSeedOf(const std::string& str_category,
348  UInt32 un_seed);
349 
353  static void Reset();
354 
355  private:
356 
357  static std::map<std::string, CCategory*> m_mapCategories;
358  };
359 
360 }
361 
362 #endif
The RNG.
Definition: rng.h:90
bool Bernoulli(Real f_true=0.5)
Returns a random value from a Bernoulli distribution.
Definition: rng.cpp:80
signed int SInt32
32-bit signed integer.
Definition: datatypes.h:93
void ResetRNGs()
Resets the RNGs in this category.
Definition: rng.cpp:254
virtual ~CCategory()
Class destructor.
Definition: rng.cpp:225
UInt32 GetSeed() const
Returns the seed of this RNG.
Definition: rng.h:117
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
void SetId(const std::string &str_id)
Sets the new id of the category.
Definition: rng.h:250
static UInt32 GetSeedOf(const std::string &str_category)
Returns the seed of the wanted category.
Definition: rng.cpp:334
Real Lognormal(Real f_sigma, Real f_mu)
Returns a random value from a Lognormal distribution.
Definition: rng.cpp:167
void ReseedRNGs()
Sets new seed for the RNGs in this category.
Definition: rng.cpp:267
The RNG category.
Definition: rng.h:222
The ARGoS random number generator.
Definition: rng.h:81
void Reset()
Reset the RNG.
Definition: rng.cpp:68
virtual ~CRNG()
Class destructor.
Definition: rng.cpp:61
It defines the basic type CRadians, used to store an angle value in radians.
Definition: angles.h:42
static void Reset()
Resets all the RNG categories.
Definition: rng.cpp:351
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
CRadians Uniform(const CRange< CRadians > &c_range)
Returns a random value from a uniform distribution.
Definition: rng.cpp:87
CRNG(UInt32 un_seed)
Class constructor.
Definition: rng.cpp:41
CCategory(const std::string &str_id, UInt32 un_seed)
Class constructor.
Definition: rng.cpp:215
CRNG * CreateRNG()
Creates a new RNG inside this category.
Definition: rng.cpp:243
static void RemoveCategory(const std::string &str_category)
Removes the wanted category.
Definition: rng.cpp:317
static CCategory & GetCategory(const std::string &str_category)
Returns a reference to the wanted category.
Definition: rng.cpp:296
static bool ExistsCategory(const std::string &str_category)
Returns true if the given category exists in the pool.
Definition: rng.cpp:304
Real Exponential(Real f_mean)
Returns a random value from an exponential distribution.
Definition: rng.cpp:123
Real Gaussian(Real f_std_dev, Real f_mean=0.0f)
Returns a random value from a Gaussian distribution.
Definition: rng.cpp:131
void SetSeed(UInt32 un_seed)
Sets the seed of this RNG.
Definition: rng.h:127
static CRNG * CreateRNG(const std::string &str_category)
Creates a new RNG inside the given category.
Definition: rng.cpp:326
void SetSeed(UInt32 un_seed)
Sets the new seed of the category.
Definition: rng.cpp:235
static bool CreateCategory(const std::string &str_category, UInt32 un_seed)
Creates a new category.
Definition: rng.cpp:277
UInt32 GetSeed() const
Returns the seed of the category.
Definition: rng.h:258
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
Real Rayleigh(Real f_sigma)
Returns a random value from a Rayleigh distribution.
Definition: rng.cpp:150
static void SetSeedOf(const std::string &str_category, UInt32 un_seed)
Sets the new seed of the wanted category.
Definition: rng.cpp:342
const std::string & GetId() const
Returns the id of the category.
Definition: rng.h:243