-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.h
143 lines (90 loc) · 3.22 KB
/
model.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef MODEL_H
#define MODEL_H
#include "controller.h"
#include <map>
#include <vector>
#include <string>
#include <random>
using namespace std;
enum Mode { FOR_EACH_PARTICLE = 0, EACH_DIRECTION_EVENLY = 1 };
enum Border { NONE = 0, IMPENETRABLE = 1 };
class CA {
public:
const static unsigned initialCount = 1e7;
int mpi_rank = 0;
struct Cell {
//max starting value, may grow bigger afterwards
const unsigned int maxParticles = (unsigned)-1;
unsigned particles = 0;
Cell() { }
Cell(unsigned i) {
if (i <= maxParticles)
particles = i;
}
Cell &operator =(const Cell &);
};
CA() {}
~CA();
CA(const vector<size_t> &size, double p, vector<unsigned> values);
/*CA(vector<size_t> &size, double p);*/
static int cmd_step(const vector<string>& args, Controller &c);
static int cmd_delta(const vector<string>& args, Controller &c);
static int cmd_blank(const vector<string>& args, Controller &c);
static int cmd_mode(const vector<string>& args, Controller &c);
static int cmd_border(const vector<string>& args, Controller &c);
void set(const vector<size_t> &coord, unsigned value);
vector<size_t> getSize();
size_t getTotalSize();
double getPMove();
vector<unsigned> getParticles();
void stepBounds();
void stepNoBounds();
vector<unsigned> getLeftBorder();
vector<unsigned> getRightBorder();
void addToLeftBorder(const vector<unsigned>& values);
void addToRightBorder(const vector<unsigned>& values);
void finishStep();
bool testN(vector<size_t> &v) {
Cell &c = get(newGrid, v);
return c.particles != 0;
}
bool testO(vector<size_t> &v) {
Cell &c = get(grid, v);
return c.particles != 0;
}
static unsigned inc(vector<size_t> &coord, const vector<size_t> &size);
void save(string msg, string name);
static size_t getIndex(const vector<size_t> &coord, vector<size_t> &size);
private:
int debug = 0;
const static unsigned maxDimensions = 3;
unsigned dimensions;
const static size_t min_Size = 1, max_Size = 1000;
const size_t minSize[maxDimensions] = { min_Size, min_Size, min_Size },
maxSize[maxDimensions] = { max_Size, max_Size, max_Size };
size_t totalSize, crossSectionSize;
vector<size_t> size;
const static unsigned maxStep = -1;
double pMove;
vector<Cell> *grid, *newGrid;
uniform_real_distribution<double> urd;
uniform_int_distribution<> uid;
default_random_engine re;
Mode mode = EACH_DIRECTION_EVENLY;
Border border = NONE;
vector<size_t> coords(size_t index);
Cell &get(vector<Cell> *grid, size_t i);
Cell &get(vector<Cell> *grid, vector<size_t> &coord);
void set(vector<Cell> *grid, vector<size_t> &coord, unsigned value);
void stepN(unsigned count);
void step(size_t first, size_t last);
unsigned getMovingParticles(Cell &cell);
void moveParticleRandom(Cell &cell, vector<size_t> &coord);
void moveParticles(Cell &cell, vector<size_t> &coord, unsigned amount, int delta, unsigned dim);
double random01();
unsigned randomUInt();
static bool isInClosedInterval(long long x, long long min, long long max);
void inc(vector<size_t> &coord);
};
int cmd_green(const vector<string>& args, Controller &c);
#endif