-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathModel.h
74 lines (55 loc) · 1.74 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
#pragma once
#include "NewOrder.h"
#include "Timeline.h"
#include "MonteCarlo.h"
#include "Module.h"
namespace no
{
class Environment;
class NEWORDER_EXPORT Model
{
public:
// deliberately use pre-C++11 enum - scope will be e.g. Model::RUN
enum RunState
{
NOT_STARTED,
RUNNING,
HALTED, // immediate exit without calling finalise
COMPLETED // reached end of timeline, finalise called
};
Model(no::Timeline &timeline, const py::function &seeder);
virtual ~Model() = default;
Model(const Model &) = delete;
Model &operator=(const Model &) = delete;
Model(Model &&) = delete;
Model &operator=(Model &&) = delete;
static bool run(Model &model);
// getters
Timeline &timeline() { return m_timeline; }
MonteCarlo &mc() { return m_monteCarlo; }
// functions to override
virtual void modify(); // optional, parallel runs only
virtual void step() = 0; // compulsory
virtual bool check(); // optional
virtual void finalise(); // optional
// set the halt flag
void halt();
// get the run state
RunState runState() const { return m_runState; }
private:
RunState m_runState;
Timeline &m_timeline;
py::object m_timeline_handle; // ensures above ref isnt deleted during the lifetime of this object
MonteCarlo m_monteCarlo;
};
class PyModel : private Model
{
using Model::Model;
using Model::operator=;
// trampoline methods
void modify() override { PYBIND11_OVERRIDE(void, Model, modify); }
void step() override { PYBIND11_OVERRIDE_PURE(void, Model, step); }
bool check() override { PYBIND11_OVERRIDE(bool, Model, check); }
void finalise() override { PYBIND11_OVERRIDE(void, Model, finalise); }
};
}