-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsimulationResults.cpp
173 lines (150 loc) · 4.01 KB
/
simulationResults.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
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
#include <array>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include "blob.h"
#include "simulationResults.h"
double getMax(std::vector<double> &vector)
{
double max = vector[0];
for (int i = 0; i < vector.size(); i++)
{
if (max < vector[i])
{
max = vector[i];
}
}
return max;
}
simulationResults::simulationResults()
{
}
void simulationResults::recordAvgBlobStats(std::vector<Blob> &blobArray)
{
int pop{ static_cast<int>(blobArray.size()) };
double sumSize{ 0 }, sumSpeed{ 0 }, sumSense{ 0 };
double maxSize{ 0 }, maxSpeed{ 0 }, maxSense{ 0 };
double minSize{ 100 }, minSpeed{ 100 }, minSense{ 100 };
for (Blob blob : blobArray)
{
sumSize += blob.getSize();
sumSpeed += blob.getSpeed();
sumSense += blob.getSense();
if (maxSize < blob.getSize())
{
maxSize = blob.getSize();
}
if (maxSpeed < blob.getSpeed())
{
maxSpeed = blob.getSpeed();
}
if (maxSense < blob.getSense())
{
maxSense = blob.getSense();
}
if (minSize > blob.getSize())
{
minSize = blob.getSize();
}
if (minSpeed > blob.getSpeed())
{
minSpeed = blob.getSpeed();
}
if (minSense > blob.getSense())
{
minSense = blob.getSense();
}
}
double avgSize{ sumSize / pop };
double avgSpeed{ sumSpeed / pop };
double avgSense{ sumSense / pop };
std::array<double, 10> avgStatArray{ pop, avgSize, avgSpeed, avgSense,
maxSize, maxSpeed, maxSense, minSize, minSpeed, minSense };
m_avgBlobStats.push_back(avgStatArray);
}
void simulationResults::recordEachBlobStats(std::vector<Blob> &blobArray)
{
std::vector<double> speedList;
std::vector<double> sizeList;
std::vector<double> senseList;
//only holds single int but easiest way too pass through population information
std::vector<double> popVector;
double pop{ static_cast<double>(blobArray.size()) };
for (Blob blob : blobArray)
{
sizeList.push_back(blob.getSize());
speedList.push_back(blob.getSpeed());
senseList.push_back(blob.getSense());
}
popVector.push_back(pop);
std::vector<std::vector<double>> dayVector{ popVector, sizeList, speedList, senseList };
m_eachBlobStats.push_back(dayVector);
}
void simulationResults::recordBlobFrame(std::vector<Blob> &blobArray)
{
if (simCounter == 0)
{
for (Blob blob : blobArray)
{
std::array<double, 6> posAndStats{ blob.getXPosition(), blob.getYPosition(), blob.getSize(),
blob.getSpeed(), blob.getSense(), blob.getName()};
m_blobFrame.push_back(posAndStats);
}
m_blobFrameArray.push_back(m_blobFrame);
m_blobFrame.clear();
}
}
void simulationResults::pushBlobFrames()
{
if (simCounter == 0)
{
m_dailyBlobframes.push_back(m_blobFrameArray);
m_blobFrameArray.clear();
}
}
void simulationResults::recordFoodPositions(std::vector<Food> &foodArray)
{
m_eachFoodArray.push_back(foodArray);
}
void simulationResults::recordDay(std::vector<Blob> &blobArray, std::vector<Food> &foodArray)
{
recordAvgBlobStats(blobArray);
recordEachBlobStats(blobArray);
if (simCounter == 0)
{
recordFoodPositions(foodArray);
}
}
void simulationResults::recordSim()
{
++simCounter;
m_manySimAvg.push_back(m_avgBlobStats);
m_manySimEach.push_back(m_eachBlobStats);
m_avgBlobStats.clear();
m_eachBlobStats.clear();
}
std::vector<std::array<double, 10>>& simulationResults::getAvgBlobStats()
{
return m_avgBlobStats;
}
std::vector<std::vector<std::vector<double>>>& simulationResults::getEachBlobStats()
{
return m_eachBlobStats;
}
std::vector< std::vector<std::array<double, 10>>>& simulationResults::getManySimAvg()
{
return m_manySimAvg;
}
std::vector<std::vector<std::vector<std::vector<double>>>>& simulationResults::getManySimEach()
{
return m_manySimEach;
}
std::vector<std::vector<Food>>& simulationResults::getEachFoodArray()
{
return m_eachFoodArray;
}
std::vector<std::vector<std::vector<std::array<double, 6>>>>& simulationResults::getDailyBlobFrames()
{
return m_dailyBlobframes;
}