@@ -158,7 +158,6 @@ double EvaluationFunctionB(TVector<double> &v, RandomState &rs)
158
158
159
159
ofstream bodyfile, actfile, curvfile, voltagefile, paramsfile;
160
160
if (supArgs1.output ){
161
- ofstream bodyfile, actfile, curvfile, voltagefile;
162
161
bodyfile.open (supArgs1.rename_file (" body.dat" ));
163
162
actfile.open (supArgs1.rename_file (" act.dat" ));
164
163
curvfile.open (supArgs1.rename_file (" curv.dat" ));
@@ -195,6 +194,7 @@ if (supArgs1.output){
195
194
w.Step (StepSize, 1 );
196
195
if (supArgs1.output )
197
196
// #ifdef OUTPUT
197
+ if (supArgs1.output )
198
198
{
199
199
w.Curvature (curvature);
200
200
curvfile << curvature << endl;
@@ -315,10 +315,11 @@ int main (int argc, const char* argv[])
315
315
if (argc == 2 )
316
316
randomseed += atoi (argv[1 ]);
317
317
318
- if (argc>2 ) if (!supArgs1.setArgs (argc,argv,randomseed)) return 0 ;
318
+ // supArgs1.max_gens = 40;
319
+ // supArgs1.pop_size = 56;
319
320
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 ;
322
323
323
324
if (supArgs1.do_evol ){
324
325
@@ -337,7 +338,7 @@ int main (int argc, const char* argv[])
337
338
seedfile.close ();
338
339
339
340
// configure the search
340
- s.SetRandomSeed (randomseed);
341
+ s.SetRandomSeed (supArgs1. randomseed );
341
342
s.SetPopulationStatisticsDisplayFunction (EvolutionaryRunDisplay);
342
343
s.SetSearchResultsDisplayFunction (ResultsDisplay);
343
344
s.SetSelectionMode (RANK_BASED); // {FITNESS_PROPORTIONATE,RANK_BASED}
@@ -356,9 +357,9 @@ int main (int argc, const char* argv[])
356
357
// redirect standard output to a file
357
358
// #ifdef PRINTTOFILE
358
359
ofstream evolfile;
360
+ std::streambuf *coutbuf = std::cout.rdbuf (); // save old buf
359
361
if (supArgs1.printToFile )
360
362
{
361
-
362
363
evolfile.open (supArgs1.rename_file (" fitness.dat" ));
363
364
cout.rdbuf (evolfile.rdbuf ());
364
365
}
@@ -390,32 +391,37 @@ if (supArgs1.evo_seed)
390
391
391
392
// #ifdef PRINTTOFILE
392
393
if (supArgs1.printToFile )
394
+ {
395
+ std::cout.rdbuf (coutbuf); // reset to standard output again
393
396
evolfile.close ();
397
+
398
+ }
394
399
// #endif
395
400
396
401
397
402
}
398
403
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 );
399
410
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;
404
420
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;
414
421
415
- EvaluationFunctionB (bestVector, rs);
422
+ EvaluationFunctionB (bestVector, rs);
416
423
417
424
418
-
419
425
420
426
421
427
return 0 ;
0 commit comments