-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
114 lines (92 loc) · 2.8 KB
/
main.c
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
#include "tools/utils.h"
#include "tools/pcg_basic.h"
#include "data_structures/clist.h"
#include "data_structures/pool.h"
#include "data_structures/vector.h"
#include "neurolution/env_settings.h"
#include "neurolution/neuron.h"
#include "neurolution/specie.h"
#include "neurolution/agent.h"
#include "neurolution/agent_io.h"
#include "neurolution/neurolution.h"
#include "neurolution/mutations.h"
#include "neurolution/kmeans.h"
#include "CPPN/activations.h"
#include "tasks/XorEvaluator.h"
void onStart(int argc, char* argv[]);
void onExit(void);
bool test(int argc, char* argv[])
{
Agent* agent = load_agent("xor.genome");
printf("%lf\n", XorEvaluator(agent));
return true; // continue the program?
}
int main(int argc, char* argv[])
{
onStart(argc, argv);
if (!test(argc, argv)) return 0;
evolve(FITNESS_GOAL);
return EXIT_SUCCESS;
}
#ifdef _WIN32
#include <sys\timeb.h>
struct timeb progStart, progEnd;
#endif // !_WIN32
void onStart(int argc, char* argv[])
{
printf(
" _ _____ ____ _____ ____ \n"
"/ \\ /|/ __// _ \\/__ __\\ / _\\\n"
"| |\\ ||| \\ | / \\| / \\ | / \n"
"| | \\||| /_ | |-|| | | | \\__\n"
"\\_/ \\|\\____\\\\_/ \\| \\_/_____\\____/\n"
" \\____\\ \n\n");
// Add function on program exit event
atexit(&onExit);
// Setup the random number generator
pcg32_srandom((unsigned long long)time(NULL), (unsigned long long) & printf);
// Get the program binary path from the program arguments
setup_binpath(argv[0]);
#ifdef _WIN32
// Save the time when the program starts to get the execution time later
ftime(&progStart);
#endif // !_WIN32
// Handle program's argument
for (int i=1; i<argc; i++)
{
switch (argv[i][1])
{
// Plot agent from file
case 'p':
printf("Plotting agent from file: %s\n", argv[i+1]);
#ifdef _WIN32
char cmd[255] = "python ";
#else
char cmd[255] = "python3 ";
#endif // !_WIN32
strcat(cmd, BIN_PATH);
strcat(cmd, "plot.py ");
strcat(cmd, argv[i+1]);
system(cmd);
exit(0);
break;
default:
break;
}
}
}
void onExit(void)
{
free_neurolution();
#if USE_DEBUG_MALLOC
printLeaks();
#endif // !USE_DEBUG_MALLOC
#ifdef _WIN32
ftime(&progEnd);
printf("\n\n---------------------------------------------------------------------------------------------------------------------\n");
printf("Program ended in %.3f seconds.\n", (1000 * (progEnd.time - progStart.time) + (progEnd.millitm - progStart.millitm)) / 1000.f);
// system("pause");
// Clear temporary files created when ploting agents
plot_fileclear();
#endif // !_WIN32
}