-
Notifications
You must be signed in to change notification settings - Fork 10
/
Model.h
176 lines (163 loc) · 6.25 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: SimulationModel.h
* Author: cancian
*
* Created on 21 de Junho de 2018, 15:01
*/
#ifndef SIMULATIONMODEL_H
#define SIMULATIONMODEL_H
#include "Util.h"
#include <string>
#include "List.h"
#include "ModelComponent.h"
#include "ModelInfrastructure.h"
#include "Event.h"
#include "Listener.h"
#include "ModelChecker_if.h"
#include "Parser_if.h"
class Simulator;
class Model {
public:
Model(Simulator* simulator);
Model(const Model& orig);
virtual ~Model();
public: // gets and sets
void setName(std::string _name);
std::string getName() const;
void setAnalystName(std::string _analystName);
std::string getAnalystName() const;
void setDescription(std::string _description);
std::string getDescription() const;
void setProjectTitle(std::string _projectTitle);
std::string getProjectTitle() const;
void setVersion(std::string _version);
std::string getVersion() const;
void setNumberOfReplications(unsigned int _numberOfReplications);
unsigned int getNumberOfReplications() const;
void setReplicationLength(double _replicationLength);
double getReplicationLength() const;
void setReplicationLengthTimeUnit(Util::TimeUnit _replicationLengthTimeUnit);
Util::TimeUnit getReplicationLengthTimeUnit() const;
void setWarmUpPeriod(double _warmUpPeriod);
double getWarmUpPeriod() const;
void setWarmUpPeriodTimeUnit(Util::TimeUnit _warmUpPeriodTimeUnit);
Util::TimeUnit getWarmUpPeriodTimeUnit() const;
void setTerminatingCondition(std::string _terminatingCondition);
std::string getTerminatingCondition() const;
void setTraceLevel(Util::TraceLevel _traceLevel);
Util::TraceLevel getTraceLevel() const;
void setStepByStep(bool _stepByStep);
bool isStepByStep() const;
void setInitializeStatistics(bool _initializeStatistics);
bool isInitializeStatistics() const;
void setInitializeSystem(bool _initializeSystem);
bool isInitializeSystem() const;
void setPauseOnReplication(bool _pauseBetweenReplications);
bool isPauseOnReplication() const;
public: // only gets
double getSimulatedTime() const;
bool isRunning() const;
bool isSaved() const;
Util::identitifcation getId() const;
List<ModelComponent*>* getComponents() const;
List<Event*>* getEvents() const;
List<Entity*>* getEntities() const;
List<ModelInfrastructure*>* getInfrastructures(std::string infraTypename) const;
ModelInfrastructure* getInfrastructure(std::string infraTypename, Util::identitifcation id);
ModelInfrastructure* getInfrastructure(std::string infraTypename, std::string name);
public: // simulation control
void startSimulation();
void pauseSimulation();
void stepSimulation();
void stopSimulation();
void restartSimulation();
void showReports();
void setPauseOnEvent(bool _pauseOnEvent);
bool isPauseOnEvent() const;
public: // model control
bool check();
void removeEntity(Entity* entity, bool collectStatistics);
void sendEntityToComponent(Entity* entity, ModelComponent* component, double timeDelay);
double parseExpression(const std::string expression);
public: // traces
void addTraceListener(traceListener traceListener);
void addTraceErrorListener(traceErrorListener traceErrorListener);
void addTraceReportListener(traceListener traceReportListener);
//void addTraceSimulationListener(traceListener traceListener);
void addTraceSimulationListener(traceSimulationListener traceSimulationListener);
void trace(Util::TraceLevel tracelevel, std::string text);
void traceError(std::exception e, std::string text);
//void traceSimulation(Util::TraceLevel tracelevel, std::string text);
void traceSimulation(Util::TraceLevel tracelevel, double time, Entity* entity, ModelComponent* component, std::string text);
void traceReport(Util::TraceLevel tracelevel, std::string text);
private: // simulation control
void _initSimulation();
void _initReplication(unsigned int currentReplicationNumber);
void _stepSimulation();
void _processEvent(Event* event);
void _showReplicationStatistics();
void _showSimulationStatistics();
private:
bool _finishReplicationCondition();
private:
std::list<traceListener>* _traceListeners = new std::list<traceListener>();
std::list<traceErrorListener>* _traceErrorListeners = new std::list<traceErrorListener>();
std::list<traceListener>* _traceReportListeners = new std::list<traceListener>();
std::list<traceSimulationListener>* _traceSimulationListeners = new std::list<traceSimulationListener>();
private: // with public access (get & set)
// model general information
std::string _name;
std::string _analystName;
std::string _description;
std::string _projectTitle;
std::string _version = "1.0";
// replication and warmup duration
unsigned int _numberOfReplications = 1;
double _replicationLength = 3600.0; // by default, 3600 s
Util::TimeUnit _replicationLengthTimeUnit = Util::TimeUnit::TU_second;
double _warmUpPeriod = 0.0;
Util::TimeUnit _warmUpPeriodTimeUnit = Util::TimeUnit::TU_second;
std::string _terminatingCondition = "";
// debug and statistics
Util::TraceLevel _traceLevel = Util::TraceLevel::TL_mostDetailed;
// list of double double _breakOnTimes;
// list of modules _breakOnModules;
bool _stepByStep = false;
bool _pauseOnReplication = false;
bool _pauseOnEvent = false;
bool _initializeStatisticsBetweenReplications = true;
bool _initializeSystem = true;
//
bool _checked = false;
private: // read only public access (gets)
Util::identitifcation _id;
double _simulatedTime = 1.0;
bool _running = false;
bool _saved = false;
// 1:n
List<ModelComponent*>* _components;
List<Event*>* _events;
// infrastructures
std::map<std::string, List<ModelInfrastructure*>*>* _infrastructures;
private: // no public access (no gets / sets)
Simulator* _simulator;
bool _pauseRequested = false;
bool _stopRequested = false;
bool _simulationIsInitiated = false;
bool _replicationIsInitiaded = false;
std::exception* _excepcionHandled = nullptr;
double _lastTimeTraceSimulation = -1.0;
Util::identitifcation _lastEntityTraceSimulation = 0;
Util::identitifcation _lastModuleTraceSimulation = 0;
// needed?
Entity* _currentEntity;
ModelComponent* _currentComponent;
Parser_if* _parser;
ModelChecker_if* _modelChecker;
};
#endif /* SIMULATIONMODEL_H */