Advertisement
Guest User

bad_sim

a guest
Feb 19th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1.  float runSim(vector<float> cromo)
  2.     {
  3.         nnet.init(16,10,2);
  4.         nnet.setWeights(cromo);
  5.  
  6.         std::string worldFile = "/home/alex/Stage/worlds/simple.world";
  7.         const int popsize = 1;
  8.         char *ptest[2];
  9.         int ntest = 1;
  10.         ptest[0]="0";
  11.         char **pptest=ptest;
  12.         char ***ppptest = &pptest;
  13.         // initialize libstage
  14.         Stg::Init( &ntest, ppptest );
  15.  
  16.  
  17.         float simFitnessTotal = 0;
  18.         //run three trials and get the average fitness
  19.         for (int i=0; i<3; i++)
  20.         {
  21.             Stg::World* world = new Stg::World("Stage Benchmark Program");
  22.             world->Load( worldFile );
  23.  
  24.             if (world->PastQuitTime())
  25.             {
  26.                 cout << "past quit time" << endl;
  27.             }
  28.  
  29.             // create the logic and connect it to the world
  30.             Logic logic(popsize);
  31.             logic.setnnet(nnet);
  32.             logic.connect(world);
  33.  
  34.             world->Run();
  35.  
  36.             simFitnessTotal += logic.trialFitness();
  37.         }
  38.         float finalFitness = simFitnessTotal/3;
  39.         cout << "final fitness: " << finalFitness << endl;
  40.         return finalFitness;
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement