-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevolution_log.cpp
More file actions
36 lines (28 loc) · 1.16 KB
/
Copy pathevolution_log.cpp
File metadata and controls
36 lines (28 loc) · 1.16 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
#include "evolution_log.hpp"
#include "sim_runner.hpp"
#include <fstream>
#include <iostream>
void EvolutionLog::addEntry(unsigned int generationIndex, float score) {
EvolutionLogEntry entry(generationIndex, score);
entries.push_back(entry);
}
void EvolutionLog::addEntry(Simulation &simulation,
unsigned int generationIndex,
unsigned int stepCount) {
unsigned int numFoodSourcesRemaining = simulation.getNumFoodSources();
float foodConsumedPerStep =
stepCount <= 0 ? 0
: static_cast<float>(SimRunner::numFoodSources -
numFoodSourcesRemaining) /
static_cast<float>(stepCount);
addEntry(generationIndex, foodConsumedPerStep);
}
void EvolutionLog::clear() { entries.clear(); }
void EvolutionLog::save(std::string filename) {
std::cout << "Saving evolution log file " << filename << std::endl;
std::ofstream file(filename);
file << "generation, score" << std::endl;
for (auto &entry : entries) {
file << entry.generationIndex << ", " << entry.score << std::endl;
}
}