Skip to content

Commit a2d8e79

Browse files
committed
added 2018 test simulation
1 parent 2e69fa5 commit a2d8e79

16 files changed

+9193
-30
lines changed

RoyalSociety2018/load_data.py

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# import random
1313
import helper_funcs as hf
1414

15-
hf.dir_name = "./"
16-
1715

1816
def reload_single_run(show_plot=True, verbose=False):
1917
# N_muscles_perside = 24 # Number of muscles alongside the body

RoyalSociety2018/main.cpp

+27-21
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ double EvaluationFunctionB(TVector<double> &v, RandomState &rs)
158158

159159
ofstream bodyfile, actfile, curvfile, voltagefile, paramsfile;
160160
if (supArgs1.output){
161-
ofstream bodyfile, actfile, curvfile, voltagefile;
162161
bodyfile.open(supArgs1.rename_file("body.dat"));
163162
actfile.open(supArgs1.rename_file("act.dat"));
164163
curvfile.open(supArgs1.rename_file("curv.dat"));
@@ -195,6 +194,7 @@ if (supArgs1.output){
195194
w.Step(StepSize, 1);
196195
if (supArgs1.output)
197196
//#ifdef OUTPUT
197+
if (supArgs1.output)
198198
{
199199
w.Curvature(curvature);
200200
curvfile << curvature << endl;
@@ -315,10 +315,11 @@ int main (int argc, const char* argv[])
315315
if (argc == 2)
316316
randomseed += atoi(argv[1]);
317317

318-
if (argc>2) if (!supArgs1.setArgs(argc,argv,randomseed)) return 0;
318+
//supArgs1.max_gens = 40;
319+
//supArgs1.pop_size = 56;
319320

320-
//supArgs1.max_gens = 100;
321-
//supArgs1.pop_size = 26;
321+
supArgs1.randomseed = randomseed;
322+
if (argc>2) if (!supArgs1.setArgs(argc,argv,randomseed)) return 0;
322323

323324
if (supArgs1.do_evol){
324325

@@ -337,7 +338,7 @@ int main (int argc, const char* argv[])
337338
seedfile.close();
338339

339340
// configure the search
340-
s.SetRandomSeed(randomseed);
341+
s.SetRandomSeed(supArgs1.randomseed);
341342
s.SetPopulationStatisticsDisplayFunction(EvolutionaryRunDisplay);
342343
s.SetSearchResultsDisplayFunction(ResultsDisplay);
343344
s.SetSelectionMode(RANK_BASED); //{FITNESS_PROPORTIONATE,RANK_BASED}
@@ -356,9 +357,9 @@ int main (int argc, const char* argv[])
356357
// redirect standard output to a file
357358
//#ifdef PRINTTOFILE
358359
ofstream evolfile;
360+
std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf
359361
if (supArgs1.printToFile)
360362
{
361-
362363
evolfile.open (supArgs1.rename_file("fitness.dat"));
363364
cout.rdbuf(evolfile.rdbuf());
364365
}
@@ -390,32 +391,37 @@ if (supArgs1.evo_seed)
390391

391392
//#ifdef PRINTTOFILE
392393
if (supArgs1.printToFile)
394+
{
395+
std::cout.rdbuf(coutbuf); //reset to standard output again
393396
evolfile.close();
397+
398+
}
394399
//#endif
395400

396401

397402
}
398403

404+
supArgs1.output = 1;
405+
supArgs1.speedoutput = 1;
406+
RandomState rs;
407+
long seed = static_cast<long>(time(NULL));
408+
//rs.SetRandomSeed(seed);
409+
rs.SetRandomSeed(supArgs1.randomseed);
399410

400-
RandomState rs;
401-
long seed = static_cast<long>(time(NULL));
402-
//rs.SetRandomSeed(seed);
403-
rs.SetRandomSeed(supArgs1.randomseed);
411+
std::cout << std::setprecision(10);
412+
413+
// Code to run simulation:
414+
InitializeBodyConstants();
415+
416+
ifstream BestIndividualFile;
417+
TVector<double> bestVector(1, VectSize);
418+
BestIndividualFile.open(supArgs1.rename_file("best.gen.dat"));
419+
BestIndividualFile >> bestVector;
404420

405-
std::cout << std::setprecision(10);
406-
407-
// Code to run simulation:
408-
InitializeBodyConstants();
409-
410-
ifstream BestIndividualFile;
411-
TVector<double> bestVector(1, VectSize);
412-
BestIndividualFile.open(supArgs1.rename_file("best.gen.dat"));
413-
BestIndividualFile >> bestVector;
414421

415-
EvaluationFunctionB(bestVector, rs);
422+
EvaluationFunctionB(bestVector, rs);
416423

417424

418-
419425

420426

421427
return 0;

argUtils.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ SuppliedArgs::SuppliedArgs()
4343
do_nml = 0;
4444
traceDuration = 24;
4545
doOrigNS = 1;
46+
max_gens = 10;
4647
}
4748

4849
/* void SuppliedArgs::setDefaultArgs()
@@ -98,6 +99,7 @@ if (((argc-1) % 2) != 0)
9899

99100
for (int arg = 1; arg<argc; arg+=2)
100101
{
102+
if (strcmp(argv[arg],"--maxgens")==0) max_gens = atoi(argv[arg+1]);
101103
if (strcmp(argv[arg],"--doevol")==0) do_evol = atoi(argv[arg+1]);
102104
if (strcmp(argv[arg],"--dorandinit")==0) simRandomInit = atoi(argv[arg+1]);
103105
//if (strcmp(argv[arg],"--skipOrigSim")==0) skipOrigSim = atoi(argv[arg+1]);

exampleRunRS18/ExampleActivity.png

1.77 MB
Loading

exampleRunRS18/act.dat

+1,501
Large diffs are not rendered by default.

exampleRunRS18/best.gen.dat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-0.2415177823988463590154651683406 -0.26189026022013811578759145959339 -0.52768628636856884650541132941726 0.65175580694887491617350860906299 0.24487725171083202235777775968018 -1 -0.64660428038295925112777240428841 0.37728595870785025523375111333735 0.8550543158976344759736321066157 0.46634864120349805993726022279589 -0.36142866864574541008181540746591 -0.59599279479593392228053971848567 -0.9154116856622225295581074533402 0.35074996085865134398673603755014 -0.43984494955289260564867959146795 -0.013562306370710201786078386021472 -0.45712619182761232705658471786592 0.019865269858451821416434057709921 -0.43627078688422460395202051586239 0.15887720639729632776671053306927 0.118538515621293624735521632374 -0.34851768736851684860056366233039 0.10425012433931908628625961910075 1 -0.90452224648122836470065522007644 -0.8674549216254889838495500953286 -0.15174208466702515663016015423636 0.17107967759744743818650647426693 0.2623833703021077323747078935412 1

exampleRunRS18/body.dat

+1,501
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)