-
Notifications
You must be signed in to change notification settings - Fork 0
/
neatmain.cpp
263 lines (215 loc) · 7.58 KB
/
neatmain.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include <iostream>
#include <fstream>
using namespace std;
#include <tclap/CmdLine.h>
#include <cstring>
#include <vector>
#include <unistd.h>
#include "neat.h"
#include "population.h"
#include "experiments.h"
#include "biped.h"
using namespace TCLAP;
static bool biped=false;
int main(int argc, char **argv) {
//class Organism;
//sferes::eval::Mpi* mp = new sferes::eval::Mpi();
//sferes::eval::Mpi<Organism*>*
//evall= new sferes::eval::Mpi<Organism*>();
//NEAT::eval_t evall;
/* if (evall==0)
{}
// eval_t eval;
else*/
//NEAT::eval_t evall;
//cout<<"How many processes :"<<evall._world->size()<<endl;
if (evall._world->rank()==0)
{
//cout<<"How many processors :"<<evall._world->size()<<endl;
/* std::vector<int> test;
test.push_back(12);
test.push_back(52);
test.push_back(19);
test.push_back(45);
test.push_back(87);
test.push_back(20);
test.push_back(30);
test.push_back(40);
vector<Organism> pop2;
for (int j =0;j<pop->organisms.size();j++){
pop2.push_back(*pop->organisms[j]);
//cout<<"my fitness: "<<pop2[j].fitness<<endl;
}*/
//eval.eval(pop->organisms,0,pop->organisms.size());
// eval.eval(pop2,0,pop2.size());
CmdLine cmd("Maze evolution", ' ', "0.1");
ValueArg<string> maze("m","maze","Maze file",false,"medium_maze_list.txt","string");
cmd.add(maze);
ValueArg<string> mcmaze("","mcmaze","MC Maze file",false,"mcmaze.txt","string");
cmd.add(mcmaze);
ValueArg<string> genes("z","sg","Starter genes",false,"mazestart_orig","string");
cmd.add(genes);
SwitchArg EvoSwitch("e","evo","Enable Evo search",false);
cmd.add(EvoSwitch);
SwitchArg MultiSwitch("t","EPEB","Enable EP&EB multiobjective search",false);
cmd.add(MultiSwitch);
ValueArg<string> settings("s","settings","Settings file",false,"maze.ne","string");
cmd.add(settings);
ValueArg<string> output("o","output","Output directory",false,"./results","string");
cmd.add(output);
ValueArg<string> seed_genome("c","seed","Seed Genome",false,"","string");
cmd.add(seed_genome);
SwitchArg local_switch("","lc","Local competition",false);
cmd.add(local_switch);
SwitchArg biped_switch("","biped","Biped domain",false);
cmd.add(biped_switch);
SwitchArg remove_random("","remrand","Remove random individuak",false);
cmd.add(remove_random);
SwitchArg extinction("","extinct","Turn on random extinctions",false);
cmd.add(extinction);
SwitchArg goal_attract("","goalnotsticky","Goal is not attractor",false);
cmd.add(goal_attract);
SwitchArg area_of_interest("","aoi","Enforce pruning of behavior space",false);
cmd.add(area_of_interest);
SwitchArg noveltySwitch("n","novelty","Enable novelty search",false);
cmd.add(noveltySwitch);
SwitchArg evaluateSwitch("","eval","Evaluate a genome",false);
cmd.add(evaluateSwitch);
SwitchArg constraintSwitch("","constraint","Enable constraint-based NS",false);
cmd.add(constraintSwitch);
SwitchArg generationalSwitch("g","gen","Enable generational search",false);
cmd.add(generationalSwitch);
SwitchArg mcSwitch("","mc","Enable minimal criteria",false);
cmd.add(mcSwitch);
ValueArg<string> nov_measure("","nm","Novelty Measure",false,"std","string");
cmd.add(nov_measure);
ValueArg<string> fit_measure("f","fm","Fitness Measure",false,"goal","string");
cmd.add(fit_measure);
ValueArg<int> extra_param("p","parameter","Extra Parameter",false,0,"int");
cmd.add(extra_param);
ValueArg<int> num_samples("a","samples","Num Samples",false,1,"int");
cmd.add(num_samples);
ValueArg<int> time_steps("b","timesteps","Num Timesteps",false,400,"int");
cmd.add(time_steps);
ValueArg<int> rng_seed("r","random_seed","Random Seed",false,-1,"int");
cmd.add(rng_seed);
//cout<<"printting the contents of cmd \n";
//cmd.print_arglist();
cmd.parse(argc,argv);
//cout<<"printting the contents of cmd after parsing\n";
//cout<<"#########################\n";
//cmd.print_arglist();
char mazename[100]="hard_maze_list.txt";
char filename[100]="./runoutput_";
char settingsname[100]="maze.ne";
char startgenes[100]="mazestartgenes";
int param;
NEAT::Population *p;
//cout<<"this is the filename" <<filename<<"\n";
//***********RANDOM SETUP***************//
/* Seed the random-number generator with current time so that
the numbers will be different every time we run. */
srand( (unsigned)time( NULL ) + getpid());
if(rng_seed.getValue()!=-1)
srand((unsigned)rng_seed.getValue());
strcpy(settingsname,settings.getValue().c_str());
strcpy(mazename,maze.getValue().c_str());
strcpy(filename,output.getValue().c_str());
strcpy(startgenes,genes.getValue().c_str());
//cout<<"this is the filename" <<filename<<"\n";
NEAT::load_neat_params(settingsname,true);
if(local_switch.getValue())
NEAT::local_competition=true;
param = extra_param.getValue();
cout<<"loaded"<<endl;
//cout << "Maze: " << mazename << endl;
cout << "Start genes: " << startgenes << endl;
set_evaluate(evaluateSwitch.getValue());
set_extinction(extinction.getValue());
set_mcmaze(mcmaze.getValue());
set_fit_measure(fit_measure.getValue());
set_nov_measure(nov_measure.getValue());
set_aoi(area_of_interest.getValue());
set_random_replace(remove_random.getValue());
cout << "Timesteps: " << time_steps.getValue() << endl;
set_timesteps(time_steps.getValue());
cout << "Num Samples: " << num_samples.getValue() << endl;
set_samples(num_samples.getValue());
set_seed(seed_genome.getValue());
cout << "Goal not sticky? " << goal_attract.getValue() << endl;
set_goal_attract(!goal_attract.getValue());
cout << "Minimal criteria engaged? " << mcSwitch.getValue() << endl;
set_minimal_criteria(mcSwitch.getValue());
if(biped_switch.getValue())
biped=true;
set_constraint_switch(constraintSwitch.getValue());
if(!generationalSwitch.getValue())
{
if(!biped)
{
if(!noveltySwitch.getValue() && !EvoSwitch.getValue())
{
cout <<"Fitness search enabled \n";
p = maze_novelty_realtime(filename,mazename,param,startgenes,false, false);
}
else if (!noveltySwitch.getValue())
{
cout <<"Evo search enabled \n";
p = maze_novelty_realtime(filename,mazename,param,startgenes,false, true);
}
else
{
cout <<"Novelty search enabled \n";
p = maze_novelty_realtime(filename,mazename,param,startgenes,true, false);
}
}
else
{
//cout<<"Are in here \n";
if(!noveltySwitch.getValue() && !EvoSwitch.getValue())
{
cout <<"Fitness search enable for Biped \n";
p = biped_novelty_realtime(filename,mazename,param,startgenes,false,false);
}
else if (!noveltySwitch.getValue() && EvoSwitch.getValue())
{
cout <<"Evo search enabled for Biped\n";
p = biped_novelty_realtime(filename,mazename,param,startgenes,false, true);
}
else
{
cout <<"Novelty search enabled for Biped\n";
p = biped_novelty_realtime(filename,mazename,param,startgenes,true, false);
}
}
}
else
{
cout<<"you here right?"<<endl;
if(!biped){
if (!MultiSwitch.getValue())
{
cout<<"Generational novelty search Enabled!! \n";
p = maze_generational(filename,mazename,param,startgenes,1000,noveltySwitch.getValue());
}
else if (MultiSwitch.getValue())
{
cout<<"Multi-objective generational search with EP&EB is Enabled!! \n";
p = maze_generational(filename,mazename,param,startgenes,1000,noveltySwitch.getValue());
}
}
else
{
cout<<"Multi-objective on Biped domain";
p = biped_generational(filename,startgenes,1000,noveltySwitch.getValue());
}
}
}
else{
std::cout << "I am process " << evall._world->rank();
evall._slave_loop<NEAT::Organism*>();
//evall._world->barrier();
} /* else
evall->_finalize();*/
return 0;
}