-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBugMM.mpp
More file actions
110 lines (86 loc) · 2.84 KB
/
BugMM.mpp
File metadata and controls
110 lines (86 loc) · 2.84 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
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
//LABEL(BugMM, EN) Core simulation functions
/* NOTE(BugMM, EN)
This module contains core simulation functions and definitions.
*/
// The model version number
version 1, 0, 0, 0;
// The model type
model_type time_based, just_in_time;
// The data type used to represent time
time_type double;
// Other data types
real_type float;
counter_type ushort;
integer_type short;
index_type ulong;
// The following option reduces memory use at the expense of speed
options packing_level=2;
// Supported languages
languages
{
EN // English
};
// The Simulation function is called by Modgen to simulate a replicate.
void Simulation()
{
// Buffer for reporting progress
const size_t nBufSize = 255;
char szBuffer[nBufSize];
// Note replicate number for progress reporting
int nReplicate = GetReplicate();
// Create the single ticker actor
Ticker *paTicker = new Ticker();
paTicker->Start();
// Create the starting population
sprintf_s(szBuffer, nBufSize, "%s %d: %s", ModelString("S_MODEL_REPLICATE"), nReplicate, ModelString("S_MODEL_START"));
ProgressMessage( szBuffer );
for ( int nJ = 0; nJ < StartingPopulationSize; nJ++ )
{
TsetseFly *paTsetseFly = new TsetseFly();
paTsetseFly->Start();
}
sprintf_s(szBuffer, nBufSize, "%s %d: %s", ModelString("S_MODEL_REPLICATE"), nReplicate, ModelString("S_MODEL_SIMULATION"));
ProgressMessage( szBuffer );
// event loop
double dCurrentTime = TIME_INFINITE;
double dStartTime = TIME_INFINITE;
int nLastProgressPercent = -1;
int nThisProgressPercent = -1;
while ( !gpoEventQueue->Empty() )
{
// get the time of next event, verify against the simulation end
dCurrentTime = gpoEventQueue->NextEvent();
// Note the start time (time of first event) for progress indicator
if ( dStartTime == TIME_INFINITE )
{
dStartTime = dCurrentTime;
}
if ( dCurrentTime > SIMULATION_END() || gbInterrupted || gbCancelled || gbErrors )
{
if (dCurrentTime > SIMULATION_END())
{
// age all actors to the simulation end time
gpoEventQueue->WaitUntilAllActors( SIMULATION_END() );
}
sprintf_s(szBuffer, nBufSize, "%s %d: %s", ModelString("S_MODEL_REPLICATE"), nReplicate, ModelString("S_MODEL_FINISH"));
ProgressMessage( szBuffer );
gpoEventQueue->FinishAllActors();
}
else
{
// age all actors to the time of next event
gpoEventQueue->WaitUntil( dCurrentTime );
// implement the next event
gpoEventQueue->Implement();
}
// Update progress indicator only if the integer percentage complete changes
// (updates to the progress bar at every event are expensive).
nThisProgressPercent = (int)( 100 * ( dCurrentTime - dStartTime ) /
( SIMULATION_END() - dStartTime ) );
if ( nThisProgressPercent > nLastProgressPercent )
{
TimeReport( dCurrentTime ); // update simulation progress
nLastProgressPercent = nThisProgressPercent;
}
}
}