From 1bf3aeeefa7f97bee52e72b219f794c99006598a Mon Sep 17 00:00:00 2001 From: verel Date: Mon, 22 Feb 2010 10:55:27 +0000 Subject: [PATCH] Ajout du state saver dans testRndWalk git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1687 331e1502-861f-0410-8da2-ba01fb791d7f --- .../oneMax/application/testRandomWalk.cpp | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/branches/newMo/tutorial/oneMax/application/testRandomWalk.cpp b/branches/newMo/tutorial/oneMax/application/testRandomWalk.cpp index a94698d14..4d81da319 100644 --- a/branches/newMo/tutorial/oneMax/application/testRandomWalk.cpp +++ b/branches/newMo/tutorial/oneMax/application/testRandomWalk.cpp @@ -155,7 +155,7 @@ void main_function(int argc, char **argv) /* ========================================================= * - * the local search algorithm + * the continuator and the checkpoint * * ========================================================= */ @@ -167,20 +167,45 @@ void main_function(int argc, char **argv) moDistanceStat distStat(distance, bestSolution); // moSolutionStat solStat; - moCheckpoint checkpoint(continuator); - eoFileMonitor outputfile("out.dat", " "); - checkpoint.add(outputfile); checkpoint.add(fStat); checkpoint.add(distStat); // checkpoint.add(solStat); + eoValueParam genCounter(-1,"Gen"); eoIncrementor increm(genCounter.value()); checkpoint.add(increm); + + moCheckpoint checkpoint(continuator); + eoFileMonitor outputfile("out.dat", " "); + checkpoint.add(outputfile); + outputfile.add(genCounter); outputfile.add(fStat); outputfile.add(distStat); // outputfile.add(solStat); + // to save the solution at each iteration + eoState outState; + + // Register the algorithm into the state (so it has something to save!! + + Indi solution; // current solution of the search process + + outState.registerObject(solution); + + // and feed the state to state savers + // save state every 10th iteration + eoCountedStateSaver stateSaver(10, outState, "iteration"); + + // Don't forget to add the two savers to the checkpoint + checkpoint.add(stateSaver); + + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ + moLocalSearch< moRandomWalkExplorer > localSearch(explorer, checkpoint, eval); /* ========================================================= @@ -189,8 +214,6 @@ void main_function(int argc, char **argv) * * ========================================================= */ - Indi solution; - random(solution); //Can be eval here, else it will be done at the beginning of the localSearch