-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgenerator_v6.cpp
More file actions
49 lines (42 loc) · 1.34 KB
/
generator_v6.cpp
File metadata and controls
49 lines (42 loc) · 1.34 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
#include "gen/generator_v6.hpp"
#include "lang/parser.hpp"
#include "lang/program_util.hpp"
#include "seq/managed_seq.hpp"
#include "sys/log.hpp"
GeneratorV6::GeneratorV6(const Config &config, const Stats &stats)
: Generator(config, stats),
scheduler(60), // 1 minute; magic number
mutator(stats, config.mutation_rate) {
// get first program template
nextProgram();
}
Program GeneratorV6::generateProgram() {
if (scheduler.isTargetReached()) {
scheduler.reset();
nextProgram();
}
Program result(program);
mutator.mutateRandom(result);
return result;
}
void GeneratorV6::nextProgram() {
Parser parser;
for (int64_t i = 0; i < 10; i++) {
const auto id = random_program_ids.get();
const std::string path = ProgramUtil::getProgramPath(id);
try {
program = parser.parse(path);
ProgramUtil::removeOps(program, Operation::Type::NOP);
// Log::get().info("Loaded template: " + path);
return;
} catch (std::exception &) {
Log::get().warn("Cannot load program " + path);
}
}
Log::get().error("Error loading template for generator v6", true);
}
std::pair<Operation, double> GeneratorV6::generateOperation() {
throw std::runtime_error("unsupported operation");
}
bool GeneratorV6::supportsRestart() const { return true; }
bool GeneratorV6::isFinished() const { return false; };