diff --git a/trunk/paradiseo-mo/src/mo.h b/trunk/paradiseo-mo/src/mo.h index a12401ce2..a58229445 100755 --- a/trunk/paradiseo-mo/src/mo.h +++ b/trunk/paradiseo-mo/src/mo.h @@ -147,7 +147,8 @@ #include #include #include -#include +#include +#include #include #include diff --git a/trunk/paradiseo-mo/src/sampling/moMHFitnessCloudSampling.h b/trunk/paradiseo-mo/src/sampling/moMHRndFitnessCloudSampling.h similarity index 73% rename from trunk/paradiseo-mo/src/sampling/moMHFitnessCloudSampling.h rename to trunk/paradiseo-mo/src/sampling/moMHRndFitnessCloudSampling.h index e644c9ec6..78909a15b 100644 --- a/trunk/paradiseo-mo/src/sampling/moMHFitnessCloudSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moMHRndFitnessCloudSampling.h @@ -1,5 +1,5 @@ /* - + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau @@ -32,21 +32,21 @@ Contact: paradiseo-help@lists.gforge.inria.fr */ -#ifndef moMHFitnessCloudSampling_h -#define moMHFitnessCloudSampling_h +#ifndef moMHRndFitnessCloudSampling_h +#define moMHRndFitnessCloudSampling_h #include #include #include #include #include -#include #include -#include +#include /** * To compute an estimation of the fitness cloud, * i.e. the scatter plot of solution fitness versus neighbor fitness: + * * Here solution are sampled with Metropolis-Hasting method * * Sample the fitness of solutions from Metropolis-Hasting sampling @@ -56,12 +56,16 @@ * */ template -class moMHFitnessCloudSampling : public moSampling +class moMHRndFitnessCloudSampling : public moFitnessCloudSampling { public: typedef typename Neighbor::EOT EOT ; using moSampling::localSearch; + using moSampling::checkpoint; + using moSampling::monitorVec; + using moSampling::continuator; + using moFitnessCloudSampling::fitnessStat; /** * Default Constructor @@ -71,27 +75,36 @@ public: * @param _eval neighbor evaluation, incremental evaluation function * @param _nbStep Number of step of the MH sampling */ - moMHFitnessCloudSampling(eoInit & _init, + moMHRndFitnessCloudSampling(eoInit & _init, moNeighborhood & _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep) : - moSampling(_init, * new moMetropolisHasting(_neighborhood, _fullEval, _eval, _nbStep), fitnessStat), + moFitnessCloudSampling(_init, _neighborhood, _fullEval, _eval, _nbStep), neighborFitnessStat(_neighborhood, _eval) { + // delete the dummy local search + delete localSearch; + + // random sampling + localSearch = new moMetropolisHasting(_neighborhood, _fullEval, _eval, _nbStep); + + // delete the checkpoint with the wrong continuator + delete checkpoint; + + // set the continuator + continuator = localSearch->getContinuator(); + + // re-construction of the checkpoint + checkpoint = new moCheckpoint(*continuator); + checkpoint->add(fitnessStat); + checkpoint->add(*monitorVec[0]); + + // one random neighbor add(neighborFitnessStat); } - /** - * default destructor - */ - ~moMHFitnessCloudSampling() { - // delete the pointer on the local search which has been constructed in the constructor - delete &localSearch; - } - protected: - moFitnessStat fitnessStat; moNeighborFitnessStat< Neighbor > neighborFitnessStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moRndRndFitnessCloudSampling.h b/trunk/paradiseo-mo/src/sampling/moRndRndFitnessCloudSampling.h index 61da261c6..e13173d08 100644 --- a/trunk/paradiseo-mo/src/sampling/moRndRndFitnessCloudSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moRndRndFitnessCloudSampling.h @@ -60,6 +60,10 @@ public: typedef typename Neighbor::EOT EOT ; using moSampling::localSearch; + using moSampling::checkpoint; + using moSampling::monitorVec; + using moSampling::continuator; + using moFitnessCloudSampling::fitnessStat; /** * Default Constructor @@ -83,6 +87,17 @@ public: // random sampling localSearch = new moRandomSearch(_init, _fullEval, _nbSol); + // delete the checkpoint with the wrong continuator + delete checkpoint; + + // set the continuator + continuator = localSearch->getContinuator(); + + // re-construction of the checkpoint + checkpoint = new moCheckpoint(*continuator); + checkpoint->add(fitnessStat); + checkpoint->add(*monitorVec[0]); + // one random neighbor add(neighborFitnessStat); } diff --git a/trunk/paradiseo-mo/src/sampling/moSampling.h b/trunk/paradiseo-mo/src/sampling/moSampling.h index 4afe19c03..2cb90a66a 100644 --- a/trunk/paradiseo-mo/src/sampling/moSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moSampling.h @@ -93,7 +93,7 @@ public: checkpoint->add(_stat); if (_monitoring) { - moVectorMonitor * monitor = new moVectorMonitor(_stat); // attention fuite memoire a la descruction ! + moVectorMonitor * monitor = new moVectorMonitor(_stat); monitorVec.push_back(monitor); checkpoint->add(*monitor); } @@ -117,8 +117,6 @@ public: // initialisation of the solution init(solution); - std::cout << localSearch->className() << std::endl; - // compute the sampling (*localSearch)(solution); diff --git a/trunk/paradiseo-mo/tutorial/Lesson6/fitnessCloud.cpp b/trunk/paradiseo-mo/tutorial/Lesson6/fitnessCloud.cpp index bb476ed5e..e1e809110 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson6/fitnessCloud.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson6/fitnessCloud.cpp @@ -38,7 +38,7 @@ using namespace std; //----------------------------------------------------------------------------- // the sampling class #include -//#include +#include // Declaration of types //----------------------------------------------------------------------------- @@ -165,8 +165,8 @@ void main_function(int argc, char **argv) // - neighbor evaluation // - number of solutions to sample - moRndRndFitnessCloudSampling sampling(random, neighborhood, fullEval, neighborEval, nbSol); - //moMHFitnessCloudSampling sampling(random, neighborhood, fullEval, neighborEval, nbSol); + // moRndRndFitnessCloudSampling sampling(random, neighborhood, fullEval, neighborEval, nbSol); + moMHRndFitnessCloudSampling sampling(random, neighborhood, fullEval, neighborEval, nbSol); /* ========================================================= *