-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolver.cpp
55 lines (48 loc) · 1.45 KB
/
solver.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
//library includes
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
//local includes
#include "DE-lib.h"
char configurationFile_default[] = "default.ini";
int main( int argc, char** argv){
char* configurationFile = new char[256];
if( argc > 1)
strcpy( configurationFile, argv[1]);
else
strcpy( configurationFile, configurationFile_default);
if( debug_messages)
printf("Loading configuration from '%s'\n",
configurationFile);
Configuration conf ( configurationFile);
delete[] configurationFile;
srand( time( NULL));
Population p( conf);
Reporter r( conf);
if( debug_messages) printf("Done loading configuration\n");
int G = conf.nGenerations;
if( debug_messages) printf("Starting evolution\n");
clock_t start = clock();
for( int i = 0; i < G; i++){
if( (i % 5) == 0 )
if( debug_progress) printf("Generation %d/%d\r", i, G);
r.capture( p, i);
//handle failure
if( r.fail){
printf("Data write failure occured. Terminating.\n");
break;}
p.evolve();}
float t = (float) (clock() - start) / ( CLOCKS_PER_SEC);
r.capture( p, G); //final capture
if( debug_progress) printf("Generation %d/%d\n", G, G);
r.finish();
if( debug_messages){
printf("Time taken: %f\n", t);
//printf("Best: "); p.findBest().print();
printf("Best Fitness: %f\n", p.best());
printf("Standard Deviation: %f\n", p.standardDeviation());}
else
printf("%f, %f, %f\n", t, p.best(), p.standardDeviation());
return 0;}