-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEcoSim.cpp
101 lines (77 loc) · 3.04 KB
/
EcoSim.cpp
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
/*
* Entry point for the simulation
* - Creates the ecosystem
* - Updates the ecosystem every time step
*/
#include <iostream>
#include "Ecosystem.h"
using namespace std;
int main() {
Ecosystem * eco = new Ecosystem();
while (1) {
//-- for synchronization of diffrent runs
//if (eco->generation > 25000)
//break;
if (eco->IsWithoutPredator == 0){
//cout << endl << "With Predator..." << endl;
//-- Termination if one of prey or predatore dead out
if (((int)eco->wolves.size() == 0) || ((int)eco->rabbits.size() == 0)){
cout << endl << "Terminated because of deth of all individuals..." << endl;
break;
}
}
else{
//MRE without predator run
//cout << endl << "Without Predator..." << endl;
if ((int)eco->rabbits.size() == 0){
cout << endl << "Terminated because of deth of all individuals..." << endl;
break;
}
}
//-- Updeate ecosystem
eco->updateEco();
//-- Finish recording time elapsed for generation
time(&eco->gEnd);
cout << " * Time to complete GEN:" << flush;
eco->printTime(eco->gStart, eco->gEnd);
//-- Write the results stats file
eco->getStat()->writeStat(eco);
eco->getStat()->reset(); //-- Reset the stats
//-- Write the results stats per species file
if (eco->perspeciesPreyFlag == 1) { eco->statSpeciesPrey->writeSpeciesStat(eco, 0); } //male
if (eco->perspeciesPredFlag == 1) { eco->statSpeciesPred->writeSpeciesStat(eco, 0); } //male
//-- Write the results stats per species file
if (eco->perspeciesPreyFlag == 1) { eco->statSpeciesPrey->writeSpeciesStat(eco, 1); } //female
if (eco->perspeciesPredFlag == 1) { eco->statSpeciesPred->writeSpeciesStat(eco, 1); } //female
//-- Write the results stats per species file
if (eco->perspeciesPreyFlag == 1) { eco->statSpeciesPrey->writeSpeciesStat(eco, 2); } //all
if (eco->perspeciesPredFlag == 1) { eco->statSpeciesPred->writeSpeciesStat(eco, 2); } //all
//-- Full save to restore the simulation for restoration
#ifdef HDF5_COMPILE
if (eco->maxSaveFlag != 0 && eco->generation % eco->maxSaveFlag == 0) { eco->maxSave_HDF5(); }
#else
if (eco->maxSaveFlag != 0 && eco->generation % eco->maxSaveFlag == 0) { eco->maxSave(); }
#endif // HDF5
//-- Min save or compresed Min save for stats
#ifdef HDF5_COMPILE
if (eco->minSaveFlag != 0 && eco->generation % eco->minSaveFlag == 0) { eco->minWorld_HDF5(); }
#else
if (eco->minSaveFlag != 0 && eco->generation % eco->minSaveFlag == 0) { eco->minSave(); }
#endif // HDF5
#ifdef HDF5_COMPILE
if (eco->minSaveCompressedFlag != 0 && eco->generation % eco->minSaveCompressedFlag == 0) { eco->minSave_Compressed_HDF5(); }
#else
if (eco->minSaveCompressedFlag != 0 && eco->generation % eco->minSaveCompressedFlag == 0) { eco->minSave_Compressed(); }
#endif
#ifndef HDF5_COMPILE
if (eco->worldSaveFlag) { eco->worldSave(); }
#endif // HDF5
//-- Increment generation number
eco->generation = eco->generation + 1;
//-- Tar the previous folder of MinSave and World
#ifndef HDF5_COMPILE
if (eco->tarMinSaveWorldFlag) { eco->doTarLastFolder(); }
#endif // HDF5
}
return 0;
}