-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomSimulator.h
More file actions
66 lines (49 loc) · 1.3 KB
/
RandomSimulator.h
File metadata and controls
66 lines (49 loc) · 1.3 KB
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
/*
* randomSimulator.h
*
* Created on: 23 Jun 2014
* Author: rusty
*/
#ifndef RANDOMSIMULATOR_H_
#define RANDOMSIMULATOR_H_
#include <string.h>
using namespace std;
class RandomSimulator{
private:
int simID, unitCount, timestepCount;
double dt;
string modelType, responseType;
unsigned int seed;
Simulation* sim;
IUnitUpdater* updater;
public:
~RandomSimulator(){
delete sim;
delete updater;
}
RandomSimulator(int simID, int unitCount, int timestepCount, double dt, string modelType, string responseType, unsigned int seed=0, double updaterMin=0.01, double updaterDelta=1e-20)
:simID(simID),unitCount(unitCount), timestepCount(timestepCount), dt(dt), modelType(modelType), responseType(responseType), seed(seed){
sim = new Simulation(simID, unitCount, timestepCount, dt, modelType, responseType);
updater = new EulerUnitUpdater(updaterMin, updaterDelta);
}
bool runUntilStable(){
srand(seed);
bool finish = false;
while (!finish){
sim = new Simulation(simID, unitCount, timestepCount, dt, modelType, responseType);
if (!sim->run(updater)){
delete sim;
}
else {
// cout << "simulation run" << endl;
finish = true;
}
}
return true;
}
bool save(string saveSuffix=""){
sim->save(saveSuffix);
return true;
}
};
#endif /* RANDOMSIMULATOR_H_ */