Stride Reference Manual  - generated for commit 9643b11
RnMan.h
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2018, Kuylen E, Willem L, Broeckhove J
14  */
15 
21 #pragma once
22 
23 #include "RnInfo.h"
24 
25 #include <functional>
26 #include <memory>
27 #include <vector>
28 
29 namespace stride {
30 namespace util {
31 
32 class RnEngine;
33 
34 /*
35  * RnMan manages random engines and distribution to produce random generators.
36  * Can be used with (up to 32) parallel streams out of the engine.
37  */
38 class RnMan
39 {
40 public:
42  RnMan();
43 
45  explicit RnMan(const RnInfo& info);
46 
48  bool operator==(const RnMan& other);
49 
51  RnInfo GetInfo() const;
52 
54  std::function<double()> GetUniform01Generator(unsigned int i = 0U);
55 
57  std::function<int()> GetUniformIntGenerator(int a, int b, unsigned int i = 0U);
58 
60  std::function<int()> GetDiscreteGenerator(const std::vector<double>& weights, unsigned int i = 0U);
61 
63  bool MakeWeightedCoinFlip(double fraction, unsigned int i = 0U);
64 
66  void Initialize(const RnInfo& info);
67 
69  bool IsEmpty() const;
70 
72  void Shuffle(std::vector<unsigned int>& indices, unsigned int i);
73 
74 private:
75  std::shared_ptr<RnEngine> m_rn;
76 };
77 
78 } // namespace util
79 } // namespace stride
bool IsEmpty() const
Is this een empty (i.e. non-initialized Rn)?
Definition: RnMan.cpp:95
Interface of RnPcg.
std::function< int()> GetDiscreteGenerator(const std::vector< double > &weights, unsigned int i=0U)
Return generator for ints [0, n-1[ with non-negative weights p_j (i=0,..,n-1) using i-th random strea...
Definition: RnMan.cpp:79
void Initialize(const RnInfo &info)
Initalize with data in Info.
Definition: RnMan.cpp:93
std::function< int()> GetUniformIntGenerator(int a, int b, unsigned int i=0U)
Return a generator for uniform ints in [a, b[ (a < b) using i-th random stream.
Definition: RnMan.cpp:74
void Shuffle(std::vector< unsigned int > &indices, unsigned int i)
Random shuffle of vector of int indices using i-th random stream.
Definition: RnMan.cpp:97
RnMan()
Default constructor builds empty (uninitialized) manager.
Definition: RnMan.cpp:64
bool operator==(const RnMan &other)
Equality of states.
Definition: RnMan.cpp:68
std::function< double()> GetUniform01Generator(unsigned int i=0U)
Return a generator for uniform doubles in [0, 1[ using i-th random stream.
Definition: RnMan.cpp:72
RnInfo GetInfo() const
Return the state of the random engines.
Definition: RnMan.cpp:70
bool MakeWeightedCoinFlip(double fraction, unsigned int i=0U)
Make weighted coin flip: <fraction> of the flips need to come up true.
Definition: RnMan.cpp:84
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
Information on random number management state.
Definition: RnInfo.h:32
std::shared_ptr< RnEngine > m_rn
Definition: RnMan.h:75