-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
91 lines (75 loc) · 2.04 KB
/
main.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
#include <stdexcept>
#include <iostream>
//#include <vector>
//#include <random>
#include <string>
#include <cstdlib>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include "src/Simulation.h"
#include "src/Individual.h"
int main(int argc, char* argv[])
{
try
{
//std::vector<vigi::Individual> {10, 2}
std::string pathname = "../output/"; // default
if (argc > 1) pathname = argv[1];
std::ofstream ofsR(pathname + "resources_out.txt", std::ofstream::out);
if (!ofsR.is_open())
{
throw std::runtime_error("unable to open resources file " + pathname + "resources_out.txt");
}
std::ofstream ofsV(pathname + "vigilance_out.txt");
if (!ofsV.is_open())
{
std::cerr << "error: unable to open vigilance file\n";
exit(EXIT_FAILURE);
}
std::ofstream ofsE(pathname + "exploration_out.txt");
if (!ofsE.is_open())
{
std::cerr << "error: unable to open vigilance file\n";
exit(EXIT_FAILURE);
}
vigi::Simulation sim(pathname);
sim.setup();
sim.run();
sim.save(ofsR, ofsV, ofsE);
if (sim.vis())
{
try
{
system("Rscript ../anim-vigil/animate_sim.r ../output/");
//system("xdg-open ../output/vigilance_out.gif");
//system("xdg-open //.output/grid_out.gif");
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
}
/*
struct stat info;
if( stat( "anim-vigil/", &info ) != 0 )
throw std::runtime_error("cannot find R animation program. Is it in root?\n");
else if( info.st_mode & S_IFDIR )
{
system("Rscript anim-vigil/animate_sim.r");
system("xdg-open output/vigilance_out.gif");
system("xdg-open output/grid_out.gif");
} else
throw std::runtime_error(pathname + " is no directory\n"); */
}
return 0;
}
catch (const std::exception& err)
{
std::cerr << "Exception: " << err.what() << '\n';
}
catch (...)
{
std::cerr << "Unknown exception\n";
}
return -1;
}