-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRandom.hpp
49 lines (40 loc) · 1.08 KB
/
Random.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef RANDOM_HPP
#define RANDOM_HPP
#include <boost/random.hpp>
#include <boost/generator_iterator.hpp>
#include <boost/graph/random.hpp>
#include <fstream>
#include "graph_properties.hpp"
class Random
{
private:
boost::mt19937 rng;
boost::uniform_real<> real_dist;
boost::variate_generator<boost::mt19937&, boost::uniform_real<> > rand_real;
unsigned int counter;
std::ifstream inf;
public:
Random(unsigned int sd, const char* file = "")
: rng(sd), real_dist(0.0, 1.0), rand_real(rng, real_dist), counter(0), inf(file) {}
Graph::vertex_descriptor random_vertex(Graph& graph)
{
++counter;
return boost::random_vertex(graph, rng);
}
double rand()
{
++counter;
if (inf)
{
double res;
inf >> res;
return res;
}
return rand_real();
}
unsigned int get_count() const
{
return counter;
}
};
#endif