diff --git a/trunk/paradiseo-mo/src/algo/moLocalSearch.h b/trunk/paradiseo-mo/src/algo/moLocalSearch.h index 3704944d1..bb3b75e78 100644 --- a/trunk/paradiseo-mo/src/algo/moLocalSearch.h +++ b/trunk/paradiseo-mo/src/algo/moLocalSearch.h @@ -49,7 +49,7 @@ public: typedef NHE NeighborhoodExplorer ; typedef typename NeighborhoodExplorer::EOT EOT ; typedef typename NeighborhoodExplorer::Neighborhood Neighborhood ; - + /** * Constructor of a moLocalSearch needs a NeighborhooExplorer and a Continuator @@ -61,40 +61,40 @@ public: * @param _solution the related solution */ virtual bool operator() (EOT & _solution) { - - if(_solution.invalid()) - fullEval(_solution); - - // initialization of the parameter of the search (for example fill empty the tabu list) - searchExplorer.initParam(_solution); - - // initialization of the external continuator (for example the time, or the number of generations) - continuator.init(_solution); - - bool b=continuator(_solution); - - do { - // explore the neighborhood of the solution - searchExplorer(_solution); - // if a solution in the neighborhood can be accepted - if (searchExplorer.accept(_solution)){ - searchExplorer.move(_solution); - searchExplorer.moveApplied(true); - } - else - searchExplorer.moveApplied(false); - - // update the parameter of the search (for ex. Temperature of the SA) - searchExplorer.updateParam(_solution); - - b=continuator(_solution); - } while (b && searchExplorer.isContinue(_solution)); - - searchExplorer.terminate(_solution); - - continuator.lastCall(_solution); - - return true; + + if (_solution.invalid()) + fullEval(_solution); + + // initialization of the parameter of the search (for example fill empty the tabu list) + searchExplorer.initParam(_solution); + + // initialization of the external continuator (for example the time, or the number of generations) + continuator.init(_solution); + + bool b=continuator(_solution); + + do { + // explore the neighborhood of the solution + searchExplorer(_solution); + // if a solution in the neighborhood can be accepted + if (searchExplorer.accept(_solution)) { + searchExplorer.move(_solution); + searchExplorer.moveApplied(true); + } + else + searchExplorer.moveApplied(false); + + // update the parameter of the search (for ex. Temperature of the SA) + searchExplorer.updateParam(_solution); + + b=continuator(_solution); + } while (b && searchExplorer.isContinue(_solution)); + + searchExplorer.terminate(_solution); + + continuator.lastCall(_solution); + + return true; }; private: diff --git a/trunk/paradiseo-mo/src/comparator/moComparator.h b/trunk/paradiseo-mo/src/comparator/moComparator.h index d33ad59a7..bd788a4ca 100644 --- a/trunk/paradiseo-mo/src/comparator/moComparator.h +++ b/trunk/paradiseo-mo/src/comparator/moComparator.h @@ -65,7 +65,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moComparator"; + return "moComparator"; } }; diff --git a/trunk/paradiseo-mo/src/comparator/moNeighborComparator.h b/trunk/paradiseo-mo/src/comparator/moNeighborComparator.h index 7a9358611..362443f2d 100644 --- a/trunk/paradiseo-mo/src/comparator/moNeighborComparator.h +++ b/trunk/paradiseo-mo/src/comparator/moNeighborComparator.h @@ -57,7 +57,7 @@ public: * @return true if the neighbor2 is better than neighbor1 */ virtual bool operator()(const Neighbor& _neighbor1, const Neighbor& _neighbor2) { - return (_neighbor1.fitness() < _neighbor2.fitness()); + return (_neighbor1.fitness() < _neighbor2.fitness()); } /** @@ -67,7 +67,7 @@ public: * @return true if the neighbor2 is equal to neighbor1 */ virtual bool equals(const Neighbor& _neighbor1, const Neighbor& _neighbor2) { - return (_neighbor1.fitness() == _neighbor2.fitness()); + return (_neighbor1.fitness() == _neighbor2.fitness()); } /** @@ -75,7 +75,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moNeighborComparator"; + return "moNeighborComparator"; } }; diff --git a/trunk/paradiseo-mo/src/comparator/moSolNeighborComparator.h b/trunk/paradiseo-mo/src/comparator/moSolNeighborComparator.h index 2e8027d98..cd131dd09 100644 --- a/trunk/paradiseo-mo/src/comparator/moSolNeighborComparator.h +++ b/trunk/paradiseo-mo/src/comparator/moSolNeighborComparator.h @@ -49,7 +49,7 @@ template< class Neighbor > class moSolNeighborComparator : public moComparator { public: - typedef typename Neighbor::EOT EOT ; + typedef typename Neighbor::EOT EOT ; /** * Compare two neighbors @@ -58,7 +58,7 @@ public: * @return true if the neighbor is better than sol */ virtual bool operator()(const EOT& _sol, const Neighbor& _neighbor) { - return (_sol.fitness() < _neighbor.fitness()); + return (_sol.fitness() < _neighbor.fitness()); } /** @@ -68,7 +68,7 @@ public: * @return true if the neighbor is equal to the solution */ virtual bool equals(const EOT& _sol, const Neighbor& _neighbor) { - return (_sol.fitness() == _neighbor.fitness()); + return (_sol.fitness() == _neighbor.fitness()); } /** @@ -76,7 +76,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moSolNeighborComparator"; + return "moSolNeighborComparator"; } }; diff --git a/trunk/paradiseo-mo/src/continuator/moCheckpoint.h b/trunk/paradiseo-mo/src/continuator/moCheckpoint.h index 69e879e8f..7d344c710 100644 --- a/trunk/paradiseo-mo/src/continuator/moCheckpoint.h +++ b/trunk/paradiseo-mo/src/continuator/moCheckpoint.h @@ -55,8 +55,8 @@ public : * @param _cont a continuator * @param _interval frequency to compute statistical operators */ - moCheckpoint(moContinuator& _cont, unsigned int _interval=1):interval(_interval), counter(0){ - continuators.push_back(&_cont); + moCheckpoint(moContinuator& _cont, unsigned int _interval=1):interval(_interval), counter(0) { + continuators.push_back(&_cont); } /** @@ -64,7 +64,7 @@ public : * @param _cont a continuator */ void add(moContinuator& _cont) { - continuators.push_back(&_cont); + continuators.push_back(&_cont); } /** @@ -72,7 +72,7 @@ public : * @param _stat a statistic operator */ void add(moStatBase& _stat) { - stats.push_back(&_stat); + stats.push_back(&_stat); } /** @@ -80,7 +80,7 @@ public : * @param _mon a monitor */ void add(eoMonitor& _mon) { - monitors.push_back(&_mon); + monitors.push_back(&_mon); } /** @@ -88,7 +88,7 @@ public : * @param _upd an updater */ void add(eoUpdater& _upd) { - updaters.push_back(&_upd); + updaters.push_back(&_upd); } /** @@ -96,60 +96,60 @@ public : * @param _sol the corresponding solution */ virtual void init(EOT& _sol) { - for(unsigned i = 0; i < continuators.size(); ++i) - continuators[i]->init(_sol); + for (unsigned i = 0; i < continuators.size(); ++i) + continuators[i]->init(_sol); } /** * @return class name */ virtual std::string className(void) const { - return "moCheckpoint"; + return "moCheckpoint"; } - /** - * apply operator of checkpoint's containers - * @param _sol reference of the solution - * @return true if all continuator return true - */ + /** + * apply operator of checkpoint's containers + * @param _sol reference of the solution + * @return true if all continuator return true + */ bool operator()(EOT & _sol) { - unsigned i; - bool bContinue = true; + unsigned i; + bool bContinue = true; - for (i = 0; i < stats.size(); ++i){ - if(counter % interval == 0) - (*stats[i])(_sol); - counter++; - } + for (i = 0; i < stats.size(); ++i) { + if (counter % interval == 0) + (*stats[i])(_sol); + counter++; + } - for (i = 0; i < updaters.size(); ++i) - (*updaters[i])(); + for (i = 0; i < updaters.size(); ++i) + (*updaters[i])(); - for (i = 0; i < monitors.size(); ++i) - (*monitors[i])(); + for (i = 0; i < monitors.size(); ++i) + (*monitors[i])(); - for (i = 0; i < continuators.size(); ++i) - if ( !(*continuators[i])(_sol) ) - bContinue = false; + for (i = 0; i < continuators.size(); ++i) + if ( !(*continuators[i])(_sol) ) + bContinue = false; - return bContinue; - } + return bContinue; + } /** * last call of statistic operators, monitors and updaters * @param _sol reference of the solution */ - void lastCall(EOT& _sol){ - unsigned int i; - for (i = 0; i < stats.size(); ++i) - stats[i]->lastCall(_sol); + void lastCall(EOT& _sol) { + unsigned int i; + for (i = 0; i < stats.size(); ++i) + stats[i]->lastCall(_sol); - for (i = 0; i < updaters.size(); ++i) - updaters[i]->lastCall(); + for (i = 0; i < updaters.size(); ++i) + updaters[i]->lastCall(); - for (i = 0; i < monitors.size(); ++i) - monitors[i]->lastCall(); - } + for (i = 0; i < monitors.size(); ++i) + monitors[i]->lastCall(); + } private : /** continuators vector */ diff --git a/trunk/paradiseo-mo/src/continuator/moContinuator.h b/trunk/paradiseo-mo/src/continuator/moContinuator.h index e2bef885c..fca36d424 100644 --- a/trunk/paradiseo-mo/src/continuator/moContinuator.h +++ b/trunk/paradiseo-mo/src/continuator/moContinuator.h @@ -51,13 +51,13 @@ public: * Init Continuator parameters * @param _solution the related solution */ - virtual void init(EOT& _solution){}; + virtual void init(EOT& _solution) {}; - /** - * Last Call to terminate the checkpoint - * @param _solution the related solution - */ - virtual void lastCall(EOT& _solution){}; + /** + * Last Call to terminate the checkpoint + * @param _solution the related solution + */ + virtual void lastCall(EOT& _solution) {}; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moCounterMonitorSaver.h b/trunk/paradiseo-mo/src/continuator/moCounterMonitorSaver.h index 3d42b9a3a..b6434969b 100644 --- a/trunk/paradiseo-mo/src/continuator/moCounterMonitorSaver.h +++ b/trunk/paradiseo-mo/src/continuator/moCounterMonitorSaver.h @@ -46,51 +46,53 @@ class moCounterMonitorSaver : public eoUpdater { public : - /** - * Default Constructor - * @param _interval frequency to call monitors - * @param _mon a monitor - */ - moCounterMonitorSaver(unsigned _interval, eoMonitor& _mon) : interval(_interval), counter(0) { - monitors.push_back(&_mon); - } + /** + * Default Constructor + * @param _interval frequency to call monitors + * @param _mon a monitor + */ + moCounterMonitorSaver(unsigned _interval, eoMonitor& _mon) : interval(_interval), counter(0) { + monitors.push_back(&_mon); + } - /** - * call monitors if interval is reach by a counter - */ - void operator()(void) { - if (counter++ % interval == 0) - for (unsigned i = 0; i < monitors.size(); i++) - (*monitors[i])(); - } + /** + * call monitors if interval is reach by a counter + */ + void operator()(void) { + if (counter++ % interval == 0) + for (unsigned i = 0; i < monitors.size(); i++) + (*monitors[i])(); + } - /** - * last call of monitors - */ - void lastCall(void) { - for (unsigned i = 0; i < monitors.size(); i++) - monitors[i]->lastCall(); - } + /** + * last call of monitors + */ + void lastCall(void) { + for (unsigned i = 0; i < monitors.size(); i++) + monitors[i]->lastCall(); + } - /** - * attach another monitor to this class - * @param _mon the monitor to attach - */ - void add(eoMonitor& _mon) { - monitors.push_back(&_mon); - } + /** + * attach another monitor to this class + * @param _mon the monitor to attach + */ + void add(eoMonitor& _mon) { + monitors.push_back(&_mon); + } - /** - * @return name of the class - */ - virtual std::string className(void) const { return "moCounterMonitorSaver"; } + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moCounterMonitorSaver"; + } private : - /** interval and counter value */ - unsigned int interval, counter; + /** interval and counter value */ + unsigned int interval, counter; - /** monitor's vector */ - std::vector monitors; + /** monitor's vector */ + std::vector monitors; }; diff --git a/trunk/paradiseo-mo/src/continuator/moDistanceStat.h b/trunk/paradiseo-mo/src/continuator/moDistanceStat.h index 61ab9ad04..beaa79931 100644 --- a/trunk/paradiseo-mo/src/continuator/moDistanceStat.h +++ b/trunk/paradiseo-mo/src/continuator/moDistanceStat.h @@ -54,20 +54,22 @@ public : * @param _dist a distance * @param _ref the reference solution */ - moDistanceStat(eoDistance & _dist, EOT & _ref): moStat(0, "distance"), dist(_dist), refSolution(_ref){} + moDistanceStat(eoDistance & _dist, EOT & _ref): moStat(0, "distance"), dist(_dist), refSolution(_ref) {} /** * Compute distance between a solution and the reference solution * @param _sol a solution */ - virtual void operator()(EOT & _sol){ - value() = dist(_sol, refSolution); + virtual void operator()(EOT & _sol) { + value() = dist(_sol, refSolution); } /** * @return name of the class */ - virtual std::string className(void) const { return "moDistanceStat"; } + virtual std::string className(void) const { + return "moDistanceStat"; + } private: /** the distance */ @@ -76,7 +78,7 @@ private: * the reference solution does not change during the run * it could be the best solution knowed of the problem */ - EOT refSolution; + EOT refSolution; }; diff --git a/trunk/paradiseo-mo/src/continuator/moFitnessStat.h b/trunk/paradiseo-mo/src/continuator/moFitnessStat.h index bf660055c..718a4e1c4 100644 --- a/trunk/paradiseo-mo/src/continuator/moFitnessStat.h +++ b/trunk/paradiseo-mo/src/continuator/moFitnessStat.h @@ -54,7 +54,7 @@ public : * @param _description a description of the stat */ moFitnessStat(std::string _description = "fitness"): - moStat(Fitness(), _description){} + moStat(Fitness(), _description) {} /** * store fitness value @@ -62,13 +62,15 @@ public : */ virtual void operator()(EOT & _sol) { - value() = _sol.fitness(); + value() = _sol.fitness(); } /** * @return the name of the class */ - virtual std::string className(void) const { return "moFitnessStat"; } + virtual std::string className(void) const { + return "moFitnessStat"; + } }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moMaxNeighborStat.h b/trunk/paradiseo-mo/src/continuator/moMaxNeighborStat.h index 9b54739b7..7decd5c02 100644 --- a/trunk/paradiseo-mo/src/continuator/moMaxNeighborStat.h +++ b/trunk/paradiseo-mo/src/continuator/moMaxNeighborStat.h @@ -45,34 +45,36 @@ template< class Neighborhood > class moMaxNeighborStat : public moStat { public : - typedef typename Neighborhood::EOT EOT ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighborhood::EOT EOT ; + typedef typename EOT::Fitness Fitness ; - using moStat< EOT, Fitness >::value; + using moStat< EOT, Fitness >::value; - /** - * Default Constructor - * @param _nhStat a neighborhoodStat - */ - moMaxNeighborStat(moNeighborhoodStat & _nhStat): - moStat(Fitness(), "min"), nhStat(_nhStat){} - - /** - * Set the max fitness in the neighborhood - * @param _sol the corresponding solution - */ - virtual void operator()(EOT & _sol){ - value() = nhStat.getMax(); - } - - /** - * @return the class name - */ - virtual std::string className(void) const { return "moMaxNeighborStat"; } + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moMaxNeighborStat(moNeighborhoodStat & _nhStat): + moStat(Fitness(), "min"), nhStat(_nhStat) {} + + /** + * Set the max fitness in the neighborhood + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value() = nhStat.getMax(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moMaxNeighborStat"; + } private: - /** moNeighborhoodStat */ - moNeighborhoodStat & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moMinNeighborStat.h b/trunk/paradiseo-mo/src/continuator/moMinNeighborStat.h index bfc215018..0967e335b 100644 --- a/trunk/paradiseo-mo/src/continuator/moMinNeighborStat.h +++ b/trunk/paradiseo-mo/src/continuator/moMinNeighborStat.h @@ -45,34 +45,36 @@ template< class Neighborhood > class moMinNeighborStat : public moStat { public : - typedef typename Neighborhood::EOT EOT ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighborhood::EOT EOT ; + typedef typename EOT::Fitness Fitness ; - using moStat< EOT, Fitness >::value; + using moStat< EOT, Fitness >::value; - /** - * Default Constructor - * @param _nhStat a neighborhoodStat - */ - moMinNeighborStat(moNeighborhoodStat & _nhStat): - moStat(Fitness(), "min"), nhStat(_nhStat){} - - /** - * Set the worst fitness in the neighborhood - * @param _sol the corresponding solution - */ - virtual void operator()(EOT & _sol){ - value() = nhStat.getMin(); - } + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moMinNeighborStat(moNeighborhoodStat & _nhStat): + moStat(Fitness(), "min"), nhStat(_nhStat) {} - /** - * @return the class name - */ - virtual std::string className(void) const { return "moMinNeighborStat"; } + /** + * Set the worst fitness in the neighborhood + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value() = nhStat.getMin(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moMinNeighborStat"; + } private: - /** moNeighborhoodStat */ - moNeighborhoodStat & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moNbInfNeighborStat.h b/trunk/paradiseo-mo/src/continuator/moNbInfNeighborStat.h index 9b40de5a8..0c62497cf 100644 --- a/trunk/paradiseo-mo/src/continuator/moNbInfNeighborStat.h +++ b/trunk/paradiseo-mo/src/continuator/moNbInfNeighborStat.h @@ -40,42 +40,44 @@ /** * - * From moNeighborhoodStat, to compute the number of solutions in the neighborhood + * From moNeighborhoodStat, to compute the number of solutions in the neighborhood * with (strictly) lower fitness than the current solution - * + * */ template< class Neighborhood > class moNbInfNeighborStat : public moStat { public : - typedef typename Neighborhood::EOT EOT ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighborhood::EOT EOT ; + typedef typename EOT::Fitness Fitness ; - using moStat< EOT, unsigned >::value; + using moStat< EOT, unsigned >::value; - /** - * Default Constructor - * @param _nhStat a neighborhoodStat - */ - moNbInfNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0, "nb inf"), nhStat(_nhStat){} - - /** - * Set the number of solutions in the neighborhood with (strictly) lower fitness than the current solution - * @param _sol the corresponding solution - */ - virtual void operator()(EOT & _sol){ - value() = nhStat.getNbInf(); - } + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moNbInfNeighborStat(moNeighborhoodStat & _nhStat): + moStat(0, "nb inf"), nhStat(_nhStat) {} - /** - * @return the class name - */ - virtual std::string className(void) const { return "moNbInfNeighborStat"; } + /** + * Set the number of solutions in the neighborhood with (strictly) lower fitness than the current solution + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value() = nhStat.getNbInf(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moNbInfNeighborStat"; + } private: - /** moNeighborhoodStat */ - moNeighborhoodStat & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moNbSupNeighborStat.h b/trunk/paradiseo-mo/src/continuator/moNbSupNeighborStat.h index 9e2fdfba2..ccba1a59a 100644 --- a/trunk/paradiseo-mo/src/continuator/moNbSupNeighborStat.h +++ b/trunk/paradiseo-mo/src/continuator/moNbSupNeighborStat.h @@ -40,42 +40,44 @@ /** * - * From moNeighborhoodStat, to compute the number of solutions in the neighborhood + * From moNeighborhoodStat, to compute the number of solutions in the neighborhood * with higher fitness than the current solution - * + * */ template< class Neighborhood > class moNbSupNeighborStat : public moStat { public : - typedef typename Neighborhood::EOT EOT ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighborhood::EOT EOT ; + typedef typename EOT::Fitness Fitness ; - using moStat< EOT, unsigned >::value; + using moStat< EOT, unsigned >::value; - /** - * Default Constructor - * @param _nhStat a neighborhoodStat - */ - moNbSupNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0, "nb sup"), nhStat(_nhStat){} - - /** - * Set the number of solutions in the neighborhood with better fitness than the current solution - * @param _sol the corresponding solution - */ - virtual void operator()(EOT & _sol){ - value() = nhStat.getNbSup(); - } - - /** - * @return the class name - */ - virtual std::string className(void) const { return "moNbSupNeighborStat"; } + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moNbSupNeighborStat(moNeighborhoodStat & _nhStat): + moStat(0, "nb sup"), nhStat(_nhStat) {} + + /** + * Set the number of solutions in the neighborhood with better fitness than the current solution + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value() = nhStat.getNbSup(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moNbSupNeighborStat"; + } private: - /** moNeighborhoodStat */ - moNeighborhoodStat & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moNeighborhoodStat.h b/trunk/paradiseo-mo/src/continuator/moNeighborhoodStat.h index 153c7970a..fd59abc02 100644 --- a/trunk/paradiseo-mo/src/continuator/moNeighborhoodStat.h +++ b/trunk/paradiseo-mo/src/continuator/moNeighborhoodStat.h @@ -49,187 +49,187 @@ template< class Neighborhood > class moNeighborhoodStat : public moStat { public : - typedef typename Neighborhood::EOT EOT ; - typedef typename Neighborhood::Neighbor Neighbor ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighborhood::EOT EOT ; + typedef typename Neighborhood::Neighbor Neighbor ; + typedef typename EOT::Fitness Fitness ; - using moStat< EOT, bool >::value; + using moStat< EOT, bool >::value; - /** - * Default Constructor - * @param _neighborhood a neighborhood - * @param _eval an evaluation function - * @param _neighborComparator a neighbor Comparator - * @param _solNeighborComparator a comparator between a solution and a neighbor - */ - moNeighborhoodStat(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator): - moStat(true, "neighborhood"), - neighborhood(_neighborhood), eval(_eval), - neighborComparator(_neighborComparator), - solNeighborComparator(_solNeighborComparator) - {} + /** + * Default Constructor + * @param _neighborhood a neighborhood + * @param _eval an evaluation function + * @param _neighborComparator a neighbor Comparator + * @param _solNeighborComparator a comparator between a solution and a neighbor + */ + moNeighborhoodStat(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator): + moStat(true, "neighborhood"), + neighborhood(_neighborhood), eval(_eval), + neighborComparator(_neighborComparator), + solNeighborComparator(_solNeighborComparator) + {} - /** - * Compute classical statistics of a solution's neighborhood - * @param _solution the corresponding solution - */ - virtual void operator()(EOT & _solution){ - Neighbor current ; - Neighbor best ; - Neighbor lowest ; + /** + * Compute classical statistics of a solution's neighborhood + * @param _solution the corresponding solution + */ + virtual void operator()(EOT & _solution) { + Neighbor current ; + Neighbor best ; + Neighbor lowest ; - if(neighborhood.hasNeighbor(_solution)){ - //init the first neighbor - neighborhood.init(_solution, current); + if (neighborhood.hasNeighbor(_solution)) { + //init the first neighbor + neighborhood.init(_solution, current); - //eval the _solution moved with the neighbor and stock the result in the neighbor - eval(_solution, current); - - // init the statistics - value() = true; + //eval the _solution moved with the neighbor and stock the result in the neighbor + eval(_solution, current); - mean = current.fitness(); - sd = mean * mean; - nb = 1; - nbInf = 0; - nbEqual = 0; - nbSup = 0; + // init the statistics + value() = true; - if (solNeighborComparator.equals(_solution, current)) - nbEqual++; - else if (solNeighborComparator(_solution, current)) - nbSup++; - else - nbInf++; + mean = current.fitness(); + sd = mean * mean; + nb = 1; + nbInf = 0; + nbEqual = 0; + nbSup = 0; - //initialize the best neighbor - best = current; - lowest = current; + if (solNeighborComparator.equals(_solution, current)) + nbEqual++; + else if (solNeighborComparator(_solution, current)) + nbSup++; + else + nbInf++; - //test all others neighbors - while (neighborhood.cont(_solution)) { - //next neighbor - neighborhood.next(_solution, current); - //eval - eval(_solution, current); + //initialize the best neighbor + best = current; + lowest = current; - mean += current.fitness(); - sd += current.fitness() * current.fitness(); - nb++; - - if (solNeighborComparator.equals(_solution, current)) - nbEqual++; - else if (solNeighborComparator(_solution, current)) - nbSup++; - else - nbInf++; + //test all others neighbors + while (neighborhood.cont(_solution)) { + //next neighbor + neighborhood.next(_solution, current); + //eval + eval(_solution, current); - //if we found a better neighbor, update the best - if (neighborComparator(best, current)) - best = current; - - if (neighborComparator(current, lowest)) - lowest = current; - } + mean += current.fitness(); + sd += current.fitness() * current.fitness(); + nb++; - max = best.fitness(); - min = lowest.fitness(); + if (solNeighborComparator.equals(_solution, current)) + nbEqual++; + else if (solNeighborComparator(_solution, current)) + nbSup++; + else + nbInf++; - mean /= nb; - if (nb > 1) - sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) ); - else - sd = 0.0; - } - else{ - //if _solution hasn't neighbor, - value() = false; - } - } + //if we found a better neighbor, update the best + if (neighborComparator(best, current)) + best = current; - /** - * @return the worst fitness value found in the neighborhood - */ - Fitness getMin(){ - return min; - } + if (neighborComparator(current, lowest)) + lowest = current; + } - /** - * @return the best fitness value found in the neighborhood - */ - Fitness getMax(){ - return max; - } + max = best.fitness(); + min = lowest.fitness(); - /** - * @return the mean fitness value of the neighborhood - */ - double getMean(){ - return mean; - } + mean /= nb; + if (nb > 1) + sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) ); + else + sd = 0.0; + } + else { + //if _solution hasn't neighbor, + value() = false; + } + } - /** - * @return the standard deviation value of the neighborhood - */ - double getSD(){ - return sd; - } + /** + * @return the worst fitness value found in the neighborhood + */ + Fitness getMin() { + return min; + } - /** - * @return the size of the neighborhood - */ - unsigned getSize(){ - return nb; - } + /** + * @return the best fitness value found in the neighborhood + */ + Fitness getMax() { + return max; + } - /** - * @return the number of neighbors having a better fitness than the current solution - */ - unsigned getNbSup(){ - return nbSup; - } + /** + * @return the mean fitness value of the neighborhood + */ + double getMean() { + return mean; + } - /** - * @return the number of neighbors having the same fitness than the current solution - */ - unsigned getNbEqual(){ - return nbEqual; - } - - /** - * @return the number of neighbors having a worst fitness than the current solution - */ - unsigned getNbInf() { - return nbInf; - } + /** + * @return the standard deviation value of the neighborhood + */ + double getSD() { + return sd; + } - /** - * @return the class name - */ - virtual std::string className(void) const { - return "moNeighborhoodStat"; - } + /** + * @return the size of the neighborhood + */ + unsigned getSize() { + return nb; + } + + /** + * @return the number of neighbors having a better fitness than the current solution + */ + unsigned getNbSup() { + return nbSup; + } + + /** + * @return the number of neighbors having the same fitness than the current solution + */ + unsigned getNbEqual() { + return nbEqual; + } + + /** + * @return the number of neighbors having a worst fitness than the current solution + */ + unsigned getNbInf() { + return nbInf; + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moNeighborhoodStat"; + } private: - // to explore the neighborhood - Neighborhood& neighborhood ; - moEval& eval; + // to explore the neighborhood + Neighborhood& neighborhood ; + moEval& eval; - // comparator betwenn solution and neighbor or between neighbors - moNeighborComparator& neighborComparator; - moSolNeighborComparator& solNeighborComparator; + // comparator betwenn solution and neighbor or between neighbors + moNeighborComparator& neighborComparator; + moSolNeighborComparator& solNeighborComparator; - // the stastics of the fitness - Fitness max, min; - //mean and standard deviation - double mean, sd ; + // the stastics of the fitness + Fitness max, min; + //mean and standard deviation + double mean, sd ; - // number of neighbors in the neighborhood; - unsigned int nb; + // number of neighbors in the neighborhood; + unsigned int nb; - // number of neighbors with lower, equal and higher fitness - unsigned int nbInf, nbEqual, nbSup ; + // number of neighbors with lower, equal and higher fitness + unsigned int nbInf, nbEqual, nbSup ; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moNeutralDegreeNeighborStat.h b/trunk/paradiseo-mo/src/continuator/moNeutralDegreeNeighborStat.h index d09994ed4..cdf64b11c 100644 --- a/trunk/paradiseo-mo/src/continuator/moNeutralDegreeNeighborStat.h +++ b/trunk/paradiseo-mo/src/continuator/moNeutralDegreeNeighborStat.h @@ -40,41 +40,43 @@ /** * From moNeighborhoodStat, to compute the neutral degree of the solution - * which is the number of solutions in the neighborhood - * with equals fitness + * which is the number of solutions in the neighborhood + * with equals fitness */ template< class Neighborhood > class moNeutralDegreeNeighborStat : public moStat { public : - typedef typename Neighborhood::EOT EOT ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighborhood::EOT EOT ; + typedef typename EOT::Fitness Fitness ; - using moStat< EOT, unsigned >::value; + using moStat< EOT, unsigned >::value; - /** - * Default Constructor - * @param _nhStat a neighborhoodStat - */ - moNeutralDegreeNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0, "neutral degree"), nhStat(_nhStat){} - - /** - * Set the neutral degree of the solution which is the number of solutions in the neighborhood with equals fitness - * @param _sol the corresponding solution - */ - virtual void operator()(EOT & _sol){ - value() = nhStat.getNbEqual(); - } - - /** - * @return the class name - */ - virtual std::string className(void) const { return "moNeutralDegreeNeighborStat"; } + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moNeutralDegreeNeighborStat(moNeighborhoodStat & _nhStat): + moStat(0, "neutral degree"), nhStat(_nhStat) {} + + /** + * Set the neutral degree of the solution which is the number of solutions in the neighborhood with equals fitness + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value() = nhStat.getNbEqual(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moNeutralDegreeNeighborStat"; + } private: - /** moNeighborhoodStat */ - moNeighborhoodStat & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moSecondMomentNeighborStat.h b/trunk/paradiseo-mo/src/continuator/moSecondMomentNeighborStat.h index e7ed41f41..125548f40 100644 --- a/trunk/paradiseo-mo/src/continuator/moSecondMomentNeighborStat.h +++ b/trunk/paradiseo-mo/src/continuator/moSecondMomentNeighborStat.h @@ -45,35 +45,37 @@ template< class Neighborhood > class moSecondMomentNeighborStat : public moStat > { public : - typedef typename Neighborhood::EOT EOT ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighborhood::EOT EOT ; + typedef typename EOT::Fitness Fitness ; - using moStat< EOT, std::pair >::value; + using moStat< EOT, std::pair >::value; - /** - * Default Constructor - * @param _nhStat a neighborhoodStat - */ - moSecondMomentNeighborStat(moNeighborhoodStat & _nhStat): - moStat >(std::make_pair(0.0,0.0), "average and stdev"), nhStat(_nhStat){} - - /** - * Set the average and the standard deviation of fitness in the neighborhood - * @param _sol the corresponding solution - */ - virtual void operator()(EOT & _sol){ - value().first = nhStat.getMean(); - value().second = nhStat.getSD(); - } - - /** - * @return the class name - */ - virtual std::string className(void) const { return "moSecondMomentNeighborStat"; } + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moSecondMomentNeighborStat(moNeighborhoodStat & _nhStat): + moStat >(std::make_pair(0.0,0.0), "average and stdev"), nhStat(_nhStat) {} + + /** + * Set the average and the standard deviation of fitness in the neighborhood + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value().first = nhStat.getMean(); + value().second = nhStat.getSD(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moSecondMomentNeighborStat"; + } private: - /** moNeighborhoodStat */ - moNeighborhoodStat & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moSizeNeighborStat.h b/trunk/paradiseo-mo/src/continuator/moSizeNeighborStat.h index 8f8d73dcc..37b0f95b4 100644 --- a/trunk/paradiseo-mo/src/continuator/moSizeNeighborStat.h +++ b/trunk/paradiseo-mo/src/continuator/moSizeNeighborStat.h @@ -40,40 +40,42 @@ /** * From moNeighborhoodStat, to compute the number of solutions in the neighborhood - * + * */ template< class Neighborhood > class moSizeNeighborStat : public moStat { public : - typedef typename Neighborhood::EOT EOT ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighborhood::EOT EOT ; + typedef typename EOT::Fitness Fitness ; - using moStat< EOT, unsigned >::value; + using moStat< EOT, unsigned >::value; - /** - * Default Constructor - * @param _nhStat a neighborhoodStat - */ - moSizeNeighborStat(moNeighborhoodStat & _nhStat): - moStat(0, "size"), nhStat(_nhStat){} - - /** - * Set the number of solutions in the neighborhood - * @param _sol the corresponding solution - */ - virtual void operator()(EOT & _sol){ - value() = nhStat.getSize(); - } - - /** - * @return the class name - */ - virtual std::string className(void) const { return "moSizeNeighborStat"; } + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moSizeNeighborStat(moNeighborhoodStat & _nhStat): + moStat(0, "size"), nhStat(_nhStat) {} + + /** + * Set the number of solutions in the neighborhood + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) { + value() = nhStat.getSize(); + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moSizeNeighborStat"; + } private: - /** moNeighborhoodStat */ - moNeighborhoodStat & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moSolutionStat.h b/trunk/paradiseo-mo/src/continuator/moSolutionStat.h index 92f1d353f..f8b5b9e07 100644 --- a/trunk/paradiseo-mo/src/continuator/moSolutionStat.h +++ b/trunk/paradiseo-mo/src/continuator/moSolutionStat.h @@ -40,7 +40,7 @@ /** * The statistic which only give the current solution * be careful, the solution is given by copy - * + * */ template class moSolutionStat : public moStat @@ -53,21 +53,21 @@ public : * @param _description a description of the parameter */ moSolutionStat(std::string _description = "solution"): - moStat(EOT(), _description){} + moStat(EOT(), _description) {} /** * Set the solution by copy * @param _sol the corresponding solution */ - virtual void operator()(EOT & _sol){ - value() = _sol; + virtual void operator()(EOT & _sol) { + value() = _sol; } /** * @return name of the class */ - virtual std::string className(void) const{ - return "moSolutionStat"; + virtual std::string className(void) const { + return "moSolutionStat"; } }; diff --git a/trunk/paradiseo-mo/src/continuator/moStat.h b/trunk/paradiseo-mo/src/continuator/moStat.h index 955aefeb0..3c4f0dfc2 100644 --- a/trunk/paradiseo-mo/src/continuator/moStat.h +++ b/trunk/paradiseo-mo/src/continuator/moStat.h @@ -47,19 +47,19 @@ class moStat : public eoValueParam, public moStatBase { public: - /** - * Default Constructor - * @param _value a default parameter's value - * @param _description a description of the parameter - */ + /** + * Default Constructor + * @param _value a default parameter's value + * @param _description a description of the parameter + */ moStat(T _value, std::string _description): - eoValueParam(_value, _description){} + eoValueParam(_value, _description) {} /** * @return name of the class */ - virtual std::string className(void) const{ - return "moStat"; + virtual std::string className(void) const { + return "moStat"; } }; diff --git a/trunk/paradiseo-mo/src/continuator/moStatBase.h b/trunk/paradiseo-mo/src/continuator/moStatBase.h index b6ef3afd2..965b16c9e 100644 --- a/trunk/paradiseo-mo/src/continuator/moStatBase.h +++ b/trunk/paradiseo-mo/src/continuator/moStatBase.h @@ -49,17 +49,17 @@ template class moStatBase : public eoUF { public: - /** - * last call of a statistical operator - */ - virtual void lastCall(EOT &) {} + /** + * last call of a statistical operator + */ + virtual void lastCall(EOT &) {} - /** - * @return name of the class - */ - virtual std::string className(void) const{ - return "moStatBase"; - } + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moStatBase"; + } }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moTrueContinuator.h b/trunk/paradiseo-mo/src/continuator/moTrueContinuator.h index bdf3a42fb..5b1c942ea 100644 --- a/trunk/paradiseo-mo/src/continuator/moTrueContinuator.h +++ b/trunk/paradiseo-mo/src/continuator/moTrueContinuator.h @@ -54,7 +54,7 @@ public: *@return always true */ virtual bool operator()(EOT & _solution) { - return true; + return true; } /** diff --git a/trunk/paradiseo-mo/src/eval/moEval.h b/trunk/paradiseo-mo/src/eval/moEval.h index 97fa07ed2..b1dac83a9 100644 --- a/trunk/paradiseo-mo/src/eval/moEval.h +++ b/trunk/paradiseo-mo/src/eval/moEval.h @@ -44,8 +44,8 @@ template class moEval : public eoBF { public: - typedef typename Neighbor::EOT EOT; - typedef typename EOT::Fitness Fitness; + typedef typename Neighbor::EOT EOT; + typedef typename EOT::Fitness Fitness; }; #endif diff --git a/trunk/paradiseo-mo/src/eval/moFullEvalByCopy.h b/trunk/paradiseo-mo/src/eval/moFullEvalByCopy.h index e5be31d1b..4c5fe2ae2 100644 --- a/trunk/paradiseo-mo/src/eval/moFullEvalByCopy.h +++ b/trunk/paradiseo-mo/src/eval/moFullEvalByCopy.h @@ -45,37 +45,37 @@ template class moFullEvalByCopy : public moEval { public: - typedef typename moEval::EOT EOT; - typedef typename moEval::Fitness Fitness; + typedef typename moEval::EOT EOT; + typedef typename moEval::Fitness Fitness; - /** - * Ctor - * @param _eval the full evaluation object - */ - moFullEvalByCopy(eoEvalFunc & _eval) : eval(_eval) {} + /** + * Ctor + * @param _eval the full evaluation object + */ + moFullEvalByCopy(eoEvalFunc & _eval) : eval(_eval) {} - /** - * Full evaluation of the neighbor by copy - * @param _sol current solution - * @param _neighbor the neighbor to be evaluated - */ - void operator()(EOT & _sol, Neighbor & _neighbor) - { - // tmp solution - EOT tmp(_sol); - // move tmp solution wrt _neighbor - _neighbor.move(tmp); - // eval copy - tmp.invalidate(); - eval(tmp); - // set the fitness value to the neighbor - _neighbor.fitness(tmp.fitness()); - } + /** + * Full evaluation of the neighbor by copy + * @param _sol current solution + * @param _neighbor the neighbor to be evaluated + */ + void operator()(EOT & _sol, Neighbor & _neighbor) + { + // tmp solution + EOT tmp(_sol); + // move tmp solution wrt _neighbor + _neighbor.move(tmp); + // eval copy + tmp.invalidate(); + eval(tmp); + // set the fitness value to the neighbor + _neighbor.fitness(tmp.fitness()); + } private: - /** the full evaluation object */ - eoEvalFunc & eval; + /** the full evaluation object */ + eoEvalFunc & eval; }; diff --git a/trunk/paradiseo-mo/src/eval/moFullEvalByModif.h b/trunk/paradiseo-mo/src/eval/moFullEvalByModif.h index 9567aa31d..8386cd494 100644 --- a/trunk/paradiseo-mo/src/eval/moFullEvalByModif.h +++ b/trunk/paradiseo-mo/src/eval/moFullEvalByModif.h @@ -45,50 +45,50 @@ template class moFullEvalByModif : public moEval { public: - typedef typename moEval::EOT EOT; - typedef typename moEval::Fitness Fitness; + typedef typename moEval::EOT EOT; + typedef typename moEval::Fitness Fitness; - /** - * Ctor - * @param _eval the full evaluation object - */ - moFullEvalByModif(eoEvalFunc& _eval) : eval(_eval) {} + /** + * Ctor + * @param _eval the full evaluation object + */ + moFullEvalByModif(eoEvalFunc& _eval) : eval(_eval) {} - /** - * Full evaluation of the neighbor by copy - * @param _sol current solution - * @param _neighbor the neighbor to be evaluated - */ - void operator()(EOT & _sol, BackableNeighbor & _neighbor) - { - // tmp fitness value of the current solution - Fitness tmpFit; + /** + * Full evaluation of the neighbor by copy + * @param _sol current solution + * @param _neighbor the neighbor to be evaluated + */ + void operator()(EOT & _sol, BackableNeighbor & _neighbor) + { + // tmp fitness value of the current solution + Fitness tmpFit; - // save current fitness value - tmpFit = _sol.fitness(); + // save current fitness value + tmpFit = _sol.fitness(); - // move the current solution wrt _neighbor - _neighbor.move(_sol); + // move the current solution wrt _neighbor + _neighbor.move(_sol); - // eval the modified solution - _sol.invalidate(); - eval(_sol); + // eval the modified solution + _sol.invalidate(); + eval(_sol); - // set the fitness value to the neighbor - _neighbor.fitness(_sol.fitness()); + // set the fitness value to the neighbor + _neighbor.fitness(_sol.fitness()); - // move the current solution back - _neighbor.moveBack(_sol); + // move the current solution back + _neighbor.moveBack(_sol); - // set the fitness back - _sol.fitness(tmpFit); - } + // set the fitness back + _sol.fitness(tmpFit); + } private: - /** the full evaluation object */ - eoEvalFunc & eval; + /** the full evaluation object */ + eoEvalFunc & eval; }; diff --git a/trunk/paradiseo-mo/src/explorer/moFirstImprExplorer.h b/trunk/paradiseo-mo/src/explorer/moFirstImprExplorer.h index 15710861c..98f82b80d 100644 --- a/trunk/paradiseo-mo/src/explorer/moFirstImprExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moFirstImprExplorer.h @@ -52,66 +52,66 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _neighborComparator a neighbor comparator - * @param _solNeighborComparator a solution vs neighbor comparator - */ + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @param _neighborComparator a neighbor comparator + * @param _solNeighborComparator a solution vs neighbor comparator + */ moFirstImprExplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) { - isAccept = false; - current=new Neighbor(); + isAccept = false; + current=new Neighbor(); } - /** - * Destructor - */ - ~moFirstImprExplorer(){ - delete current; + /** + * Destructor + */ + ~moFirstImprExplorer() { + delete current; } - /** - * initParam: NOTHING TO DO - */ - virtual void initParam(EOT & solution){}; + /** + * initParam: NOTHING TO DO + */ + virtual void initParam(EOT & solution) {}; - /** - * updateParam: NOTHING TO DO - */ - virtual void updateParam(EOT & solution){}; + /** + * updateParam: NOTHING TO DO + */ + virtual void updateParam(EOT & solution) {}; - /** - * terminate: NOTHING TO DO - */ - virtual void terminate(EOT & solution){}; + /** + * terminate: NOTHING TO DO + */ + virtual void terminate(EOT & solution) {}; /** * Explore the neighborhood of a solution * @param _solution */ - virtual void operator()(EOT & _solution){ + virtual void operator()(EOT & _solution) { - //Test if _solution has a Neighbor - if(neighborhood.hasNeighbor(_solution)){ - //init the first neighbor - neighborhood.init(_solution, (*current)); + //Test if _solution has a Neighbor + if (neighborhood.hasNeighbor(_solution)) { + //init the first neighbor + neighborhood.init(_solution, (*current)); - //eval the _solution moved with the neighbor and stock the result in the neighbor - eval(_solution, (*current)); + //eval the _solution moved with the neighbor and stock the result in the neighbor + eval(_solution, (*current)); - //test all others neighbors - while (! solNeighborComparator(_solution, *current) && neighborhood.cont(_solution)) { - //next neighbor - neighborhood.next(_solution, (*current)); - //eval - eval(_solution, (*current)); - } - } - else{ - //if _solution hasn't neighbor, - isAccept=false; - } + //test all others neighbors + while (! solNeighborComparator(_solution, *current) && neighborhood.cont(_solution)) { + //next neighbor + neighborhood.next(_solution, (*current)); + //eval + eval(_solution, (*current)); + } + } + else { + //if _solution hasn't neighbor, + isAccept=false; + } }; /** @@ -120,7 +120,7 @@ public: * @return true if an ameliorated neighbor was be found */ virtual bool isContinue(EOT & _solution) { - return isAccept ; + return isAccept ; }; /** @@ -128,10 +128,10 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - //move the solution - (*current).move(_solution); - //update its fitness - _solution.fitness((*current).fitness()); + //move the solution + (*current).move(_solution); + //update its fitness + _solution.fitness((*current).fitness()); }; /** @@ -140,10 +140,10 @@ public: * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { - if(neighborhood.hasNeighbor(_solution)){ - isAccept = solNeighborComparator(_solution, (*current)) ; - } - return isAccept; + if (neighborhood.hasNeighbor(_solution)) { + isAccept = solNeighborComparator(_solution, (*current)) ; + } + return isAccept; }; private: diff --git a/trunk/paradiseo-mo/src/explorer/moHCneutralExplorer.h b/trunk/paradiseo-mo/src/explorer/moHCneutralExplorer.h index 9176d1c0d..99b3c4a80 100644 --- a/trunk/paradiseo-mo/src/explorer/moHCneutralExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moHCneutralExplorer.h @@ -56,49 +56,49 @@ public: using moSimpleHCneutralExplorer::initParam; using moSimpleHCneutralExplorer::updateParam; - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _neighborComparator a neighbor comparator - * @param _solNeighborComparator a solution vs neighbor comparator - * @param _nbStep maximum step to do - */ + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @param _neighborComparator a neighbor comparator + * @param _solNeighborComparator a solution vs neighbor comparator + * @param _nbStep maximum step to do + */ moHCneutralExplorer(Neighborhood& _neighborhood, - moEval& _eval, - moNeighborComparator& _neighborComparator, - moSolNeighborComparator& _solNeighborComparator, - unsigned _nbStep) : - moSimpleHCneutralExplorer(_neighborhood, _eval, _neighborComparator, _solNeighborComparator), - nbStep(_nbStep){ - //Some cycle is possible with equals fitness solutions if the neighborhood is not random - if(!neighborhood.isRandom()){ - std::cout << "moHCneutralExplorer::Warning -> the neighborhood used is not random" << std::endl; - } + moEval& _eval, + moNeighborComparator& _neighborComparator, + moSolNeighborComparator& _solNeighborComparator, + unsigned _nbStep) : + moSimpleHCneutralExplorer(_neighborhood, _eval, _neighborComparator, _solNeighborComparator), + nbStep(_nbStep) { + //Some cycle is possible with equals fitness solutions if the neighborhood is not random + if (!neighborhood.isRandom()) { + std::cout << "moHCneutralExplorer::Warning -> the neighborhood used is not random" << std::endl; + } } - /** - * Destructor - */ - ~moHCneutralExplorer(){ + /** + * Destructor + */ + ~moHCneutralExplorer() { } - /** - * initial number of step - */ - virtual void initParam(EOT & solution){ - moSimpleHCneutralExplorer::initParam(solution); + /** + * initial number of step + */ + virtual void initParam(EOT & solution) { + moSimpleHCneutralExplorer::initParam(solution); - step = 0; + step = 0; }; - /** - * one more step - */ - virtual void updateParam(EOT & solution){ - moSimpleHCneutralExplorer::updateParam(solution); - - step++; + /** + * one more step + */ + virtual void updateParam(EOT & solution) { + moSimpleHCneutralExplorer::updateParam(solution); + + step++; }; /** @@ -107,7 +107,7 @@ public: * @return true there is some steps to do */ virtual bool isContinue(EOT & _solution) { - return (step < nbStep) && isAccept ; + return (step < nbStep) && isAccept ; }; /** @@ -116,9 +116,9 @@ public: * @return true if the best neighbor ameliorate the fitness or is equals */ virtual bool accept(EOT & _solution) { - if(neighborhood.hasNeighbor(_solution)) - isAccept = solNeighborComparator(_solution, bestVector[0]) || solNeighborComparator.equals(_solution, bestVector[0]) ; - return isAccept; + if (neighborhood.hasNeighbor(_solution)) + isAccept = solNeighborComparator(_solution, bestVector[0]) || solNeighborComparator.equals(_solution, bestVector[0]) ; + return isAccept; }; private: diff --git a/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h b/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h index 392091307..8c2b46e8d 100644 --- a/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moMetropolisHastingExplorer.h @@ -58,69 +58,69 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _neighborComparator a neighbor comparator - * @param _solNeighborComparator a solution vs neighbor comparator - * @param _nbStep maximum number of step to do - */ + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @param _neighborComparator a neighbor comparator + * @param _solNeighborComparator a solution vs neighbor comparator + * @param _nbStep maximum number of step to do + */ moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) { - isAccept = false; - current=new Neighbor(); - if(!neighborhood.isRandom()){ - std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl; - } + isAccept = false; + current=new Neighbor(); + if (!neighborhood.isRandom()) { + std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl; + } } - /** - * Destructor - */ - ~moMetropolisHastingExplorer(){ - delete current; + /** + * Destructor + */ + ~moMetropolisHastingExplorer() { + delete current; } - /** - * initialization of the number of step to be done - * @param _solution the solution (unused here) - */ - virtual void initParam(EOT & _solution){ - step = 0; - isAccept = true; + /** + * initialization of the number of step to be done + * @param _solution the solution (unused here) + */ + virtual void initParam(EOT & _solution) { + step = 0; + isAccept = true; }; - /** - * increase the number of step - * @param _solution the solution (unused here) - */ - virtual void updateParam(EOT & _solution){ - step++; + /** + * increase the number of step + * @param _solution the solution (unused here) + */ + virtual void updateParam(EOT & _solution) { + step++; }; - /** - * terminate: NOTHING TO DO - * @param _solution the solution (unused here) - */ - virtual void terminate(EOT & _solution){}; + /** + * terminate: NOTHING TO DO + * @param _solution the solution (unused here) + */ + virtual void terminate(EOT & _solution) {}; /** * Explore the neighborhood of a solution * @param _solution */ - virtual void operator()(EOT & _solution){ - //Test if _solution has a Neighbor - if(neighborhood.hasNeighbor(_solution)){ - //init the first neighbor - neighborhood.init(_solution, (*current)); + virtual void operator()(EOT & _solution) { + //Test if _solution has a Neighbor + if (neighborhood.hasNeighbor(_solution)) { + //init the first neighbor + neighborhood.init(_solution, (*current)); - //eval the _solution moved with the neighbor and stock the result in the neighbor - eval(_solution, (*current)); - } - else{ - //if _solution hasn't neighbor, - isAccept=false; - } + //eval the _solution moved with the neighbor and stock the result in the neighbor + eval(_solution, (*current)); + } + else { + //if _solution hasn't neighbor, + isAccept=false; + } }; /** @@ -129,7 +129,7 @@ public: * @return true there is some steps to do */ virtual bool isContinue(EOT & _solution) { - return (step < nbStep) ; + return (step < nbStep) ; }; /** @@ -137,10 +137,10 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - //move the solution - (*current).move(_solution); - //update its fitness - _solution.fitness((*current).fitness()); + //move the solution + (*current).move(_solution); + //update its fitness + _solution.fitness((*current).fitness()); }; /** @@ -149,27 +149,27 @@ public: * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { - double alpha=0.0; - if(neighborhood.hasNeighbor(_solution)){ - if (solNeighborComparator(_solution, *current)) - isAccept = true; - else{ - if(_solution.fitness() != 0){ - if( (double)current->fitness() < (double)_solution.fitness()) // maximizing - alpha = (double) current->fitness() / (double) _solution.fitness(); - else //minimizing - alpha = (double) _solution.fitness() / (double) current->fitness(); - isAccept = (rng.uniform() < alpha) ; - } - else{ - if( (double)current->fitness() < (double)_solution.fitness()) // maximizing - isAccept = true; - else - isAccept = false; - } - } - } - return isAccept; + double alpha=0.0; + if (neighborhood.hasNeighbor(_solution)) { + if (solNeighborComparator(_solution, *current)) + isAccept = true; + else { + if (_solution.fitness() != 0) { + if ( (double)current->fitness() < (double)_solution.fitness()) // maximizing + alpha = (double) current->fitness() / (double) _solution.fitness(); + else //minimizing + alpha = (double) _solution.fitness() / (double) current->fitness(); + isAccept = (rng.uniform() < alpha) ; + } + else { + if ( (double)current->fitness() < (double)_solution.fitness()) // maximizing + isAccept = true; + else + isAccept = false; + } + } + } + return isAccept; }; private: diff --git a/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h b/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h index 4a2a13f29..98c1c50da 100644 --- a/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moNeighborhoodExplorer.h @@ -102,16 +102,16 @@ public: * Getter for variable "isMoved" * @return true if move is applied */ - bool moveApplied(){ - return isMoved; + bool moveApplied() { + return isMoved; } /** * Setter for variable "isMoved" * @param _isMoved */ - void moveApplied(bool _isMoved){ - isMoved=_isMoved; + void moveApplied(bool _isMoved) { + isMoved=_isMoved; } /** @@ -119,7 +119,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moNeighborhoodExplorer"; + return "moNeighborhoodExplorer"; } protected: diff --git a/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h b/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h index e8cf78f38..f3a519bd1 100644 --- a/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h @@ -54,79 +54,79 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _solNeighborComparator a solution vs neighbor comparator - * @param _nbStep maximum number of step to do - */ + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @param _solNeighborComparator a solution vs neighbor comparator + * @param _nbStep maximum number of step to do + */ moRandomNeutralWalkExplorer(Neighborhood& _neighborhood, moEval& _eval, - moSolNeighborComparator& _solNeighborComparator, - unsigned _nbStep): - moNeighborhoodExplorer(_neighborhood, _eval), - solNeighborComparator(_solNeighborComparator), - nbStep(_nbStep) { - isAccept = false; - current=new Neighbor(); - if(!neighborhood.isRandom()){ - std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl; - } + moSolNeighborComparator& _solNeighborComparator, + unsigned _nbStep): + moNeighborhoodExplorer(_neighborhood, _eval), + solNeighborComparator(_solNeighborComparator), + nbStep(_nbStep) { + isAccept = false; + current=new Neighbor(); + if (!neighborhood.isRandom()) { + std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl; + } } - /** - * Destructor - */ - ~moRandomNeutralWalkExplorer(){ - delete current; + /** + * Destructor + */ + ~moRandomNeutralWalkExplorer() { + delete current; } - /** - * initialization of the number of step to be done - */ - virtual void initParam(EOT & solution){ - step = 0; - isAccept = true; + /** + * initialization of the number of step to be done + */ + virtual void initParam(EOT & solution) { + step = 0; + isAccept = true; }; - /** - * increase the number of step - */ - virtual void updateParam(EOT & solution){ - step++; + /** + * increase the number of step + */ + virtual void updateParam(EOT & solution) { + step++; }; - /** - * terminate: NOTHING TO DO - */ - virtual void terminate(EOT & solution){}; + /** + * terminate: NOTHING TO DO + */ + virtual void terminate(EOT & solution) {}; /** * Explore the neighborhood of a solution * @param _solution */ - virtual void operator()(EOT & _solution){ - //Test if _solution has a Neighbor - if(neighborhood.hasNeighbor(_solution)){ - //init the first neighbor - neighborhood.init(_solution, (*current)); + virtual void operator()(EOT & _solution) { + //Test if _solution has a Neighbor + if (neighborhood.hasNeighbor(_solution)) { + //init the first neighbor + neighborhood.init(_solution, (*current)); - //eval the _solution moved with the neighbor and stock the result in the neighbor - eval(_solution, (*current)); + //eval the _solution moved with the neighbor and stock the result in the neighbor + eval(_solution, (*current)); - //test all others neighbors - while (! solNeighborComparator.equals(_solution, *current) && neighborhood.cont(_solution)) { - //next neighbor - neighborhood.next(_solution, (*current)); - //eval - eval(_solution, (*current)); - } - } - else{ - //if _solution hasn't neighbor, - isAccept=false; - } - }; + //test all others neighbors + while (! solNeighborComparator.equals(_solution, *current) && neighborhood.cont(_solution)) { + //next neighbor + neighborhood.next(_solution, (*current)); + //eval + eval(_solution, (*current)); + } + } + else { + //if _solution hasn't neighbor, + isAccept=false; + } + }; /** * continue if there is a neighbor and it is remainds some steps to do @@ -134,7 +134,7 @@ public: * @return true there is some steps to do */ virtual bool isContinue(EOT & _solution) { - return (step < nbStep) && isAccept ; + return (step < nbStep) && isAccept ; }; /** @@ -142,10 +142,10 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - //move the solution - (*current).move(_solution); - //update its fitness - _solution.fitness((*current).fitness()); + //move the solution + (*current).move(_solution); + //update its fitness + _solution.fitness((*current).fitness()); }; /** @@ -154,9 +154,9 @@ public: * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { - if(neighborhood.hasNeighbor(_solution)) - isAccept = solNeighborComparator.equals(_solution, (*current)) ; - return isAccept; + if (neighborhood.hasNeighbor(_solution)) + isAccept = solNeighborComparator.equals(_solution, (*current)) ; + return isAccept; }; private: diff --git a/trunk/paradiseo-mo/src/explorer/moRandomWalkExplorer.h b/trunk/paradiseo-mo/src/explorer/moRandomWalkExplorer.h index 3e975366b..d8c16fc84 100644 --- a/trunk/paradiseo-mo/src/explorer/moRandomWalkExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moRandomWalkExplorer.h @@ -52,69 +52,69 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _nbStep maximum number of step to do - */ + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @param _nbStep maximum number of step to do + */ moRandomWalkExplorer(Neighborhood& _neighborhood, moEval& _eval, unsigned _nbStep) : moNeighborhoodExplorer(_neighborhood, _eval), nbStep(_nbStep) { - isAccept = false; - current=new Neighbor(); - // number of step done - step = 0; - if(!neighborhood.isRandom()){ - std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl; - } + isAccept = false; + current=new Neighbor(); + // number of step done + step = 0; + if (!neighborhood.isRandom()) { + std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl; + } } - /** - * Destructor - */ - ~moRandomWalkExplorer(){ - delete current; + /** + * Destructor + */ + ~moRandomWalkExplorer() { + delete current; } - /** - * initialization of the number of step to be done - */ - virtual void initParam(EOT & solution){ - step = 0; - isAccept = true; + /** + * initialization of the number of step to be done + */ + virtual void initParam(EOT & solution) { + step = 0; + isAccept = true; }; - /** - * increase the number of step - */ - virtual void updateParam(EOT & solution){ - step++; + /** + * increase the number of step + */ + virtual void updateParam(EOT & solution) { + step++; }; - /** - * terminate: NOTHING TO DO - */ - virtual void terminate(EOT & solution){}; + /** + * terminate: NOTHING TO DO + */ + virtual void terminate(EOT & solution) {}; /** * Explore the neighborhood with only one random solution * @param _solution */ - virtual void operator()(EOT & _solution){ + virtual void operator()(EOT & _solution) { - //Test if _solution has a Neighbor - if(neighborhood.hasNeighbor(_solution)){ - //init the first neighbor - neighborhood.init(_solution, (*current)); + //Test if _solution has a Neighbor + if (neighborhood.hasNeighbor(_solution)) { + //init the first neighbor + neighborhood.init(_solution, (*current)); - //eval the _solution moved with the neighbor and stock the result in the neighbor - eval(_solution, (*current)); + //eval the _solution moved with the neighbor and stock the result in the neighbor + eval(_solution, (*current)); - isAccept = true; - } - else{ - //if _solution hasn't neighbor, - isAccept=false; - } + isAccept = true; + } + else { + //if _solution hasn't neighbor, + isAccept=false; + } }; /** @@ -123,7 +123,7 @@ public: * @return true there is some steps to do */ virtual bool isContinue(EOT & _solution) { - return (step < nbStep) && isAccept ; + return (step < nbStep) && isAccept ; }; /** @@ -131,10 +131,10 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - //move the solution - (*current).move(_solution); - //update its fitness - _solution.fitness((*current).fitness()); + //move the solution + (*current).move(_solution); + //update its fitness + _solution.fitness((*current).fitness()); }; /** @@ -143,9 +143,9 @@ public: * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { - if(neighborhood.hasNeighbor(_solution)) - isAccept = true ; - return isAccept; + if (neighborhood.hasNeighbor(_solution)) + isAccept = true ; + return isAccept; }; private: diff --git a/trunk/paradiseo-mo/src/explorer/moSimpleHCexplorer.h b/trunk/paradiseo-mo/src/explorer/moSimpleHCexplorer.h index 6c92136b2..386b7041d 100644 --- a/trunk/paradiseo-mo/src/explorer/moSimpleHCexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moSimpleHCexplorer.h @@ -52,77 +52,77 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _neighborComparator a neighbor comparator - * @param _solNeighborComparator solution vs neighbor comparator - */ - moSimpleHCexplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) { - isAccept = false; - current=new Neighbor(); - best=new Neighbor(); + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @param _neighborComparator a neighbor comparator + * @param _solNeighborComparator solution vs neighbor comparator + */ + moSimpleHCexplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) { + isAccept = false; + current=new Neighbor(); + best=new Neighbor(); } - /** - * Destructor - */ - ~moSimpleHCexplorer(){ - delete current; - delete best; + /** + * Destructor + */ + ~moSimpleHCexplorer() { + delete current; + delete best; } - /** - * initParam: NOTHING TO DO - */ - virtual void initParam(EOT & solution){}; + /** + * initParam: NOTHING TO DO + */ + virtual void initParam(EOT & solution) {}; - /** - * updateParam: NOTHING TO DO - */ - virtual void updateParam(EOT & solution){}; + /** + * updateParam: NOTHING TO DO + */ + virtual void updateParam(EOT & solution) {}; - /** - * terminate: NOTHING TO DO - */ - virtual void terminate(EOT & solution){}; + /** + * terminate: NOTHING TO DO + */ + virtual void terminate(EOT & solution) {}; /** * Explore the neighborhood of a solution * @param _solution */ - virtual void operator()(EOT & _solution){ + virtual void operator()(EOT & _solution) { - //est qu'on peut initializer - //Test if _solution has a Neighbor - if(neighborhood.hasNeighbor(_solution)){ - //init the first neighbor - neighborhood.init(_solution, (*current)); + //est qu'on peut initializer + //Test if _solution has a Neighbor + if (neighborhood.hasNeighbor(_solution)) { + //init the first neighbor + neighborhood.init(_solution, (*current)); - //eval the _solution moved with the neighbor and stock the result in the neighbor - eval(_solution, (*current)); + //eval the _solution moved with the neighbor and stock the result in the neighbor + eval(_solution, (*current)); - //initialize the best neighbor - (*best) = (*current); + //initialize the best neighbor + (*best) = (*current); - //test all others neighbors - while (neighborhood.cont(_solution)) { - //next neighbor - neighborhood.next(_solution, (*current)); - //eval - eval(_solution, (*current)); - //if we found a better neighbor, update the best - if (neighborComparator((*best), (*current))) { - (*best) = (*current); - } - } + //test all others neighbors + while (neighborhood.cont(_solution)) { + //next neighbor + neighborhood.next(_solution, (*current)); + //eval + eval(_solution, (*current)); + //if we found a better neighbor, update the best + if (neighborComparator((*best), (*current))) { + (*best) = (*current); + } + } - } - else{ - //if _solution hasn't neighbor, - isAccept=false; - } + } + else { + //if _solution hasn't neighbor, + isAccept=false; + } }; /** @@ -131,7 +131,7 @@ public: * @return true if an ameliorated neighbor was be found */ virtual bool isContinue(EOT & _solution) { - return isAccept ; + return isAccept ; }; /** @@ -139,10 +139,10 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - //move the solution - (*best).move(_solution); - //update its fitness - _solution.fitness((*best).fitness()); + //move the solution + (*best).move(_solution); + //update its fitness + _solution.fitness((*best).fitness()); }; /** @@ -151,10 +151,10 @@ public: * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { - if(neighborhood.hasNeighbor(_solution)){ - isAccept = solNeighborComparator(_solution, (*best)) ; - } - return isAccept; + if (neighborhood.hasNeighbor(_solution)) { + isAccept = solNeighborComparator(_solution, (*best)) ; + } + return isAccept; }; /** @@ -162,7 +162,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moSimpleHCexplorer"; + return "moSimpleHCexplorer"; } private: diff --git a/trunk/paradiseo-mo/src/explorer/moSimpleHCneutralExplorer.h b/trunk/paradiseo-mo/src/explorer/moSimpleHCneutralExplorer.h index 6df1b3959..ca3729e16 100644 --- a/trunk/paradiseo-mo/src/explorer/moSimpleHCneutralExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moSimpleHCneutralExplorer.h @@ -54,91 +54,91 @@ public: using moNeighborhoodExplorer::neighborhood; using moNeighborhoodExplorer::eval; - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _neighborComparator a neighbor comparator - * @param _solNeighborComparator solution vs neighbor comparator - */ + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @param _neighborComparator a neighbor comparator + * @param _solNeighborComparator solution vs neighbor comparator + */ moSimpleHCneutralExplorer(Neighborhood& _neighborhood, - moEval& _eval, - moNeighborComparator& _neighborComparator, - moSolNeighborComparator& _solNeighborComparator) : - moNeighborhoodExplorer(_neighborhood, _eval), - neighborComparator(_neighborComparator), - solNeighborComparator(_solNeighborComparator) { - isAccept = false; - current=new Neighbor(); + moEval& _eval, + moNeighborComparator& _neighborComparator, + moSolNeighborComparator& _solNeighborComparator) : + moNeighborhoodExplorer(_neighborhood, _eval), + neighborComparator(_neighborComparator), + solNeighborComparator(_solNeighborComparator) { + isAccept = false; + current=new Neighbor(); } - /** - * Destructor - */ - ~moSimpleHCneutralExplorer(){ - delete current; + /** + * Destructor + */ + ~moSimpleHCneutralExplorer() { + delete current; } - /** - * empty the vector of best solutions - */ - virtual void initParam(EOT & solution){ - // delete all the best solutions - bestVector.clear(); + /** + * empty the vector of best solutions + */ + virtual void initParam(EOT & solution) { + // delete all the best solutions + bestVector.clear(); }; - /** - * empty the vector of best solutions - */ - virtual void updateParam(EOT & solution){ - // delete all the best solutions - bestVector.clear(); + /** + * empty the vector of best solutions + */ + virtual void updateParam(EOT & solution) { + // delete all the best solutions + bestVector.clear(); }; - /** - * terminate: NOTHING TO DO - */ - virtual void terminate(EOT & solution){}; + /** + * terminate: NOTHING TO DO + */ + virtual void terminate(EOT & solution) {}; /** * Explore the neighborhood of a solution * @param _solution */ - virtual void operator()(EOT & _solution){ + virtual void operator()(EOT & _solution) { - //Test if _solution has a Neighbor - if(neighborhood.hasNeighbor(_solution)){ - //init the first neighbor - neighborhood.init(_solution, (*current)); + //Test if _solution has a Neighbor + if (neighborhood.hasNeighbor(_solution)) { + //init the first neighbor + neighborhood.init(_solution, (*current)); - //eval the _solution moved with the neighbor and stock the result in the neighbor - eval(_solution, (*current)); + //eval the _solution moved with the neighbor and stock the result in the neighbor + eval(_solution, (*current)); - //initialize the best neighbor - bestVector.push_back(*current); + //initialize the best neighbor + bestVector.push_back(*current); - //test all others neighbors - while (neighborhood.cont(_solution)) { - //next neighbor - neighborhood.next(_solution, (*current)); - - //eval - eval(_solution, (*current)); - - //if we found a better neighbor, update the best - if (neighborComparator(bestVector[0], (*current))) { - bestVector.clear(); - bestVector.push_back(*current); - } - else if (neighborComparator.equals((*current), bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution - bestVector.push_back(*current); - } - } - else { - //if _solution hasn't neighbor, - isAccept=false; - } - }; + //test all others neighbors + while (neighborhood.cont(_solution)) { + //next neighbor + neighborhood.next(_solution, (*current)); + + //eval + eval(_solution, (*current)); + + //if we found a better neighbor, update the best + if (neighborComparator(bestVector[0], (*current))) { + bestVector.clear(); + bestVector.push_back(*current); + } + else if (neighborComparator.equals((*current), bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution + bestVector.push_back(*current); + } + } + else { + //if _solution hasn't neighbor, + isAccept=false; + } + }; /** * continue if a move is accepted @@ -146,7 +146,7 @@ public: * @return true if an ameliorated neighbor was be found */ virtual bool isContinue(EOT & _solution) { - return isAccept ; + return isAccept ; }; /** @@ -154,14 +154,14 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - // choose randomly one of the best solutions - unsigned int i = rng.random(bestVector.size()); + // choose randomly one of the best solutions + unsigned int i = rng.random(bestVector.size()); - //move the solution - bestVector[i].move(_solution); + //move the solution + bestVector[i].move(_solution); - //update its fitness - _solution.fitness(bestVector[i].fitness()); + //update its fitness + _solution.fitness(bestVector[i].fitness()); }; /** @@ -170,9 +170,9 @@ public: * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { - if(neighborhood.hasNeighbor(_solution)) - isAccept = solNeighborComparator(_solution, bestVector[0]) ; - return isAccept; + if (neighborhood.hasNeighbor(_solution)) + isAccept = solNeighborComparator(_solution, bestVector[0]) ; + return isAccept; }; protected: diff --git a/trunk/paradiseo-mo/src/explorer/moTSExplorer.h b/trunk/paradiseo-mo/src/explorer/moTSExplorer.h index 173ac90f3..cd35625ac 100644 --- a/trunk/paradiseo-mo/src/explorer/moTSExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moTSExplorer.h @@ -54,81 +54,81 @@ public: typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::Neighbor Neighbor ; - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _neighborComparator a neighbor comparator - * @param _solNeighborComparator a comparator between a solution and a neighbor - * @param _tabuList the tabu list - * @param _intensification the intensification box - * @param _diversification the diversification box - * @param _aspiration the aspiration criteria - */ + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @param _neighborComparator a neighbor comparator + * @param _solNeighborComparator a comparator between a solution and a neighbor + * @param _tabuList the tabu list + * @param _intensification the intensification box + * @param _diversification the diversification box + * @param _aspiration the aspiration criteria + */ moTSExplorer(Neighborhood& _neighborhood, - moEval& _eval, - moNeighborComparator& _neighborComparator, - moSolNeighborComparator& _solNeighborComparator, - moTabuList & _tabuList, - moIntensification & _intensification, - moDiversification & _diversification, - moAspiration & _aspiration - ) : - moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), - tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration) + moEval& _eval, + moNeighborComparator& _neighborComparator, + moSolNeighborComparator& _solNeighborComparator, + moTabuList & _tabuList, + moIntensification & _intensification, + moDiversification & _diversification, + moAspiration & _aspiration + ) : + moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), + tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration) { - isAccept = false; - current=new Neighbor(); - best=new Neighbor(); + isAccept = false; + current=new Neighbor(); + best=new Neighbor(); } - /** - * Destructor - */ - ~moTSExplorer(){ - delete current; - delete best; + /** + * Destructor + */ + ~moTSExplorer() { + delete current; + delete best; } - /** - * init tabu list, intensification box, diversification box and aspiration criteria - * @param _solution - */ + /** + * init tabu list, intensification box, diversification box and aspiration criteria + * @param _solution + */ virtual void initParam(EOT& _solution) { - tabuList.init(_solution); - intensification.init(_solution); - diversification.init(_solution); - aspiration.init(_solution); - bestSoFar=_solution; + tabuList.init(_solution); + intensification.init(_solution); + diversification.init(_solution); + aspiration.init(_solution); + bestSoFar=_solution; }; - /** - * update params of tabu list, intensification box, diversification box and aspiration criteria - * @param _solution - */ + /** + * update params of tabu list, intensification box, diversification box and aspiration criteria + * @param _solution + */ virtual void updateParam(EOT& _solution) { - if ((*this).moveApplied()){ - tabuList.add(_solution, *best); - intensification.add(_solution, *best); - diversification.add(_solution, *best); - if(_solution.fitness() > bestSoFar.fitness()) - bestSoFar = _solution; - } - tabuList.update(_solution, *best); - intensification.update(_solution, *best); - diversification.update(_solution, *best); - aspiration.update(_solution, *best); + if ((*this).moveApplied()) { + tabuList.add(_solution, *best); + intensification.add(_solution, *best); + diversification.add(_solution, *best); + if (_solution.fitness() > bestSoFar.fitness()) + bestSoFar = _solution; + } + tabuList.update(_solution, *best); + intensification.update(_solution, *best); + diversification.update(_solution, *best); + aspiration.update(_solution, *best); }; - /** - * terminate : _solution becomes the best so far - */ - virtual void terminate(EOT & _solution){ - _solution= bestSoFar; + /** + * terminate : _solution becomes the best so far + */ + virtual void terminate(EOT & _solution) { + _solution= bestSoFar; }; @@ -138,56 +138,56 @@ public: */ virtual void operator()(EOT & _solution) { - bool found=false; - intensification(_solution); - diversification(_solution); - if(neighborhood.hasNeighbor(_solution)) - { - //init the current neighbor - neighborhood.init(_solution, *current); - //eval the current neighbor - eval(_solution, *current); + bool found=false; + intensification(_solution); + diversification(_solution); + if (neighborhood.hasNeighbor(_solution)) + { + //init the current neighbor + neighborhood.init(_solution, *current); + //eval the current neighbor + eval(_solution, *current); - //Find the first non-tabu element - if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ){ - // set best - (*best)= (*current); - found=true; - } - while(neighborhood.cont(_solution) && !found){ - //next neighbor - neighborhood.next(_solution, (*current)); - //eval - eval(_solution, (*current)); + //Find the first non-tabu element + if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ) { + // set best + (*best)= (*current); + found=true; + } + while (neighborhood.cont(_solution) && !found) { + //next neighbor + neighborhood.next(_solution, (*current)); + //eval + eval(_solution, (*current)); - if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ){ - // set best - (*best)=(*current); - found=true; - } - } - //Explore the neighborhood - if(found){ - isAccept=true; - while(neighborhood.cont(_solution)){ - //next neighbor - neighborhood.next(_solution, (*current)); - //eval - eval(_solution, (*current)); - //check if the current is better than the best and is not tabu or if it is aspirat (by the aspiration criteria of course) - if ( (!tabuList.check(_solution, *current) || aspiration(_solution, (*current))) && neighborComparator((*best),(*current))){ - // set best - (*best)=(*current); - } - } - } - else{ - isAccept=false; - } - } - else{ - isAccept=false; - } + if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ) { + // set best + (*best)=(*current); + found=true; + } + } + //Explore the neighborhood + if (found) { + isAccept=true; + while (neighborhood.cont(_solution)) { + //next neighbor + neighborhood.next(_solution, (*current)); + //eval + eval(_solution, (*current)); + //check if the current is better than the best and is not tabu or if it is aspirat (by the aspiration criteria of course) + if ( (!tabuList.check(_solution, *current) || aspiration(_solution, (*current))) && neighborComparator((*best),(*current))) { + // set best + (*best)=(*current); + } + } + } + else { + isAccept=false; + } + } + else { + isAccept=false; + } }; @@ -196,8 +196,8 @@ public: * @param _solution the solution * @return true */ - virtual bool isContinue(EOT & _solution){ - return true; + virtual bool isContinue(EOT & _solution) { + return true; }; @@ -206,10 +206,10 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - //move the solution - best->move(_solution); - //update its fitness - _solution.fitness(best->fitness()); + //move the solution + best->move(_solution); + //update its fitness + _solution.fitness(best->fitness()); }; @@ -218,8 +218,8 @@ public: * @param _solution the solution * @return true if the best neighbor ameliorate the fitness */ - virtual bool accept(EOT & _solution){ - return isAccept; + virtual bool accept(EOT & _solution) { + return isAccept; }; @@ -236,11 +236,11 @@ protected: // Tabu components moTabuList & tabuList; moIntensification & intensification; - moDiversification & diversification; - moAspiration & aspiration; + moDiversification & diversification; + moAspiration & aspiration; - //Current and best neighbor - Neighbor* best; + //Current and best neighbor + Neighbor* best; Neighbor* current; //Best so far Solution diff --git a/trunk/paradiseo-mo/src/memory/moAspiration.h b/trunk/paradiseo-mo/src/memory/moAspiration.h index f8746a1d8..26c5a77e2 100644 --- a/trunk/paradiseo-mo/src/memory/moAspiration.h +++ b/trunk/paradiseo-mo/src/memory/moAspiration.h @@ -10,10 +10,10 @@ template< class Neighbor > class moAspiration : public eoBF { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - virtual void init(EOT & _sol) = 0; - virtual void update(EOT & _sol, Neighbor & _neighbor) = 0; + virtual void init(EOT & _sol) = 0; + virtual void update(EOT & _sol, Neighbor & _neighbor) = 0; }; #endif diff --git a/trunk/paradiseo-mo/src/memory/moBestImprAspiration.h b/trunk/paradiseo-mo/src/memory/moBestImprAspiration.h index 6e0d1dc7a..4fe5fb9d0 100644 --- a/trunk/paradiseo-mo/src/memory/moBestImprAspiration.h +++ b/trunk/paradiseo-mo/src/memory/moBestImprAspiration.h @@ -11,47 +11,47 @@ class moBestImprAspiration : public moAspiration { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * init the best solution - * @param _sol the best solution found - */ - void init(EOT & _sol){ - bestFoundSoFar = _sol; - } + /** + * init the best solution + * @param _sol the best solution found + */ + void init(EOT & _sol) { + bestFoundSoFar = _sol; + } - /** - * update the "bestFoundSoFar" if a best solution is found - * @param _sol a solution - * @param _neighbor a neighbor - */ - void update(EOT & _sol, Neighbor & _neighbor){ - if (bestFoundSoFar.fitness() < _sol.fitness()) - bestFoundSoFar = _sol; - } + /** + * update the "bestFoundSoFar" if a best solution is found + * @param _sol a solution + * @param _neighbor a neighbor + */ + void update(EOT & _sol, Neighbor & _neighbor) { + if (bestFoundSoFar.fitness() < _sol.fitness()) + bestFoundSoFar = _sol; + } - /** - * Test the tabu feature of the neighbor: - * test if the neighbor's fitness is better than the "bestFoundSoFar" fitness - * @param _sol a solution - * @param _neighbor a neighbor - * @return true if _neighbor fitness is better than the "bestFoundSoFar" - */ - bool operator()(EOT & _sol, Neighbor & _neighbor){ - return (bestFoundSoFar.fitness() < _neighbor.fitness()); - } + /** + * Test the tabu feature of the neighbor: + * test if the neighbor's fitness is better than the "bestFoundSoFar" fitness + * @param _sol a solution + * @param _neighbor a neighbor + * @return true if _neighbor fitness is better than the "bestFoundSoFar" + */ + bool operator()(EOT & _sol, Neighbor & _neighbor) { + return (bestFoundSoFar.fitness() < _neighbor.fitness()); + } - /** - * Getter - * @return a reference on the best found so far solution - */ - EOT& getBest(){ - return bestFoundSoFar; - } + /** + * Getter + * @return a reference on the best found so far solution + */ + EOT& getBest() { + return bestFoundSoFar; + } private: - EOT bestFoundSoFar; + EOT bestFoundSoFar; }; #endif diff --git a/trunk/paradiseo-mo/src/memory/moDiversification.h b/trunk/paradiseo-mo/src/memory/moDiversification.h index 91cb5b3de..5dffc2a41 100644 --- a/trunk/paradiseo-mo/src/memory/moDiversification.h +++ b/trunk/paradiseo-mo/src/memory/moDiversification.h @@ -9,6 +9,6 @@ */ template< class Neighbor > class moDiversification : public moMemory, public eoUF -{}; + {}; #endif diff --git a/trunk/paradiseo-mo/src/memory/moDummyDiversification.h b/trunk/paradiseo-mo/src/memory/moDummyDiversification.h index 9f0e14376..f66d8193e 100644 --- a/trunk/paradiseo-mo/src/memory/moDummyDiversification.h +++ b/trunk/paradiseo-mo/src/memory/moDummyDiversification.h @@ -10,34 +10,34 @@ template< class Neighbor > class moDummyDiversification : public moDiversification { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * Init : NOTHIING TO DO - */ - void init(EOT & _sol) {} + /** + * Init : NOTHIING TO DO + */ + void init(EOT & _sol) {} - /** - * Add : NOTHIING TO DO - */ - void add(EOT & _sol, Neighbor & _neighbor) {} + /** + * Add : NOTHIING TO DO + */ + void add(EOT & _sol, Neighbor & _neighbor) {} - /** - * Update : NOTHIING TO DO - */ - void update(EOT & _sol, Neighbor & _neighbor) {} + /** + * Update : NOTHIING TO DO + */ + void update(EOT & _sol, Neighbor & _neighbor) {} - /** - * ClearMemory : NOTHIING TO DO - */ - void clearMemory() {} + /** + * ClearMemory : NOTHIING TO DO + */ + void clearMemory() {} - /** - * @return always false - */ - bool operator()(EOT &){ - return false; - } + /** + * @return always false + */ + bool operator()(EOT &) { + return false; + } }; #endif diff --git a/trunk/paradiseo-mo/src/memory/moDummyIntensification.h b/trunk/paradiseo-mo/src/memory/moDummyIntensification.h index 7cc124871..76a16dca5 100644 --- a/trunk/paradiseo-mo/src/memory/moDummyIntensification.h +++ b/trunk/paradiseo-mo/src/memory/moDummyIntensification.h @@ -10,34 +10,34 @@ template< class Neighbor > class moDummyIntensification : public moIntensification { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * Init : NOTHIING TO DO - */ - void init(EOT & _sol) {} + /** + * Init : NOTHIING TO DO + */ + void init(EOT & _sol) {} - /** - * Add : NOTHIING TO DO - */ - void add(EOT & _sol, Neighbor & _neighbor) {} + /** + * Add : NOTHIING TO DO + */ + void add(EOT & _sol, Neighbor & _neighbor) {} - /** - * Update : NOTHIING TO DO - */ - void update(EOT & _sol, Neighbor & _neighbor) {} + /** + * Update : NOTHIING TO DO + */ + void update(EOT & _sol, Neighbor & _neighbor) {} - /** - * ClearMemory : NOTHIING TO DO - */ - void clearMemory() {} + /** + * ClearMemory : NOTHIING TO DO + */ + void clearMemory() {} - /** - * @return always false - */ - bool operator()(EOT &){ - return false; - } + /** + * @return always false + */ + bool operator()(EOT &) { + return false; + } }; #endif diff --git a/trunk/paradiseo-mo/src/memory/moIntensification.h b/trunk/paradiseo-mo/src/memory/moIntensification.h index 65b9bb1ad..c1c21274f 100644 --- a/trunk/paradiseo-mo/src/memory/moIntensification.h +++ b/trunk/paradiseo-mo/src/memory/moIntensification.h @@ -9,6 +9,6 @@ */ template< class Neighbor > class moIntensification : public moMemory, public eoUF -{}; + {}; #endif diff --git a/trunk/paradiseo-mo/src/memory/moMemory.h b/trunk/paradiseo-mo/src/memory/moMemory.h index a1284a094..a76351328 100644 --- a/trunk/paradiseo-mo/src/memory/moMemory.h +++ b/trunk/paradiseo-mo/src/memory/moMemory.h @@ -8,32 +8,32 @@ template< class Neighbor > class moMemory //: public eoObject { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * Init the memory - * @param _sol the current solution - */ - virtual void init(EOT & _sol) = 0; + /** + * Init the memory + * @param _sol the current solution + */ + virtual void init(EOT & _sol) = 0; - /** - * Add data in the memory - * @param _sol the current solution - * @param _neighbor the current neighbor - */ - virtual void add(EOT & _sol, Neighbor & _neighbor) = 0; + /** + * Add data in the memory + * @param _sol the current solution + * @param _neighbor the current neighbor + */ + virtual void add(EOT & _sol, Neighbor & _neighbor) = 0; - /** - * update the memory - * @param _sol the current solution - * @param _neighbor the current neighbor - */ - virtual void update(EOT & _sol, Neighbor & _neighbor) = 0; + /** + * update the memory + * @param _sol the current solution + * @param _neighbor the current neighbor + */ + virtual void update(EOT & _sol, Neighbor & _neighbor) = 0; - /** - * clear the memory - */ - virtual void clearMemory() = 0; + /** + * clear the memory + */ + virtual void clearMemory() = 0; }; diff --git a/trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h b/trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h index 17628f7a8..aa79c8255 100644 --- a/trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h +++ b/trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h @@ -12,91 +12,91 @@ template class moSolVectorTabuList : public moTabuList { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * Constructor - * @param _maxSize maximum size of the tabu list - * @param _howlong how many iteration a move is tabu - */ - moSolVectorTabuList(unsigned int _maxSize, unsigned int _howlong) : maxSize(_maxSize), howlong(_howlong){ - tabuList.reserve(_maxSize); - tabuList.resize(0); - } + /** + * Constructor + * @param _maxSize maximum size of the tabu list + * @param _howlong how many iteration a move is tabu + */ + moSolVectorTabuList(unsigned int _maxSize, unsigned int _howlong) : maxSize(_maxSize), howlong(_howlong) { + tabuList.reserve(_maxSize); + tabuList.resize(0); + } - /** - * init the tabuList by clearing the memory - * @param _sol the current solution - */ - virtual void init(EOT & _sol){ - clearMemory(); - } + /** + * init the tabuList by clearing the memory + * @param _sol the current solution + */ + virtual void init(EOT & _sol) { + clearMemory(); + } - /** - * add a new solution in the tabuList - * @param _sol the current solution - * @param _neighbor the current neighbor (unused) - */ - virtual void add(EOT & _sol, Neighbor & _neighbor){ + /** + * add a new solution in the tabuList + * @param _sol the current solution + * @param _neighbor the current neighbor (unused) + */ + virtual void add(EOT & _sol, Neighbor & _neighbor) { - if(tabuList.size() < maxSize){ - std::pair tmp; - tmp.first=_sol; - tmp.second=howlong; - tabuList.push_back(tmp); - } - else{ - tabuList[index%maxSize].first = _sol; - tabuList[index%maxSize].second = howlong; - index++; - } - } + if (tabuList.size() < maxSize) { + std::pair tmp; + tmp.first=_sol; + tmp.second=howlong; + tabuList.push_back(tmp); + } + else { + tabuList[index%maxSize].first = _sol; + tabuList[index%maxSize].second = howlong; + index++; + } + } - /** - * update the tabulist: NOTHING TO DO - * @param _sol the current solution - * @param _neighbor the current neighbor (unused) - */ - virtual void update(EOT & _sol, Neighbor & _neighbor){ - for(unsigned int i=0; i 0 && tabuList[i].second > 0 && tabuList[i].first == tmp) || (howlong==0 && tabuList[i].first==tmp)) - return true; - } - return false; - } + /** + * check if the solution is tabu + * @param _sol the current solution + * @param _neighbor the current neighbor (unused) + * @return true if tabuList contains _sol + */ + virtual bool check(EOT & _sol, Neighbor & _neighbor) { + EOT tmp=_sol; + _neighbor.move(tmp); + for (unsigned int i=0; i 0 && tabuList[i].second > 0 && tabuList[i].first == tmp) || (howlong==0 && tabuList[i].first==tmp)) + return true; + } + return false; + } - /** - * clearMemory: remove all solution of the tabuList - */ - virtual void clearMemory(){ - tabuList.resize(0); - index = 0; - } + /** + * clearMemory: remove all solution of the tabuList + */ + virtual void clearMemory() { + tabuList.resize(0); + index = 0; + } private: - //tabu list - std::vector< std::pair > tabuList; - //maximum size of the tabu list - unsigned int maxSize; - //how many iteration a move is tabu - unsigned int howlong; - //index on the tabulist - unsigned long index; + //tabu list + std::vector< std::pair > tabuList; + //maximum size of the tabu list + unsigned int maxSize; + //how many iteration a move is tabu + unsigned int howlong; + //index on the tabulist + unsigned long index; }; diff --git a/trunk/paradiseo-mo/src/memory/moTabuList.h b/trunk/paradiseo-mo/src/memory/moTabuList.h index 96131286e..e6dc409bd 100644 --- a/trunk/paradiseo-mo/src/memory/moTabuList.h +++ b/trunk/paradiseo-mo/src/memory/moTabuList.h @@ -10,15 +10,15 @@ template< class Neighbor > class moTabuList : public moMemory { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * Check if a neighbor is tabu or not - * @param _sol the current solution - * @param _neighbor the neighbor - * @return true if the neighbor is tabu - */ - virtual bool check(EOT & _sol, Neighbor & _neighbor) = 0; + /** + * Check if a neighbor is tabu or not + * @param _sol the current solution + * @param _neighbor the neighbor + * @return true if the neighbor is tabu + */ + virtual bool check(EOT & _sol, Neighbor & _neighbor) = 0; }; #endif diff --git a/trunk/paradiseo-mo/src/newmo b/trunk/paradiseo-mo/src/mo similarity index 100% rename from trunk/paradiseo-mo/src/newmo rename to trunk/paradiseo-mo/src/mo diff --git a/trunk/paradiseo-mo/src/newmo.h b/trunk/paradiseo-mo/src/mo.h similarity index 100% rename from trunk/paradiseo-mo/src/newmo.h rename to trunk/paradiseo-mo/src/mo.h diff --git a/trunk/paradiseo-mo/src/neighborhood/moBackableNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moBackableNeighbor.h index ac4324c77..efeb0acae 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moBackableNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moBackableNeighbor.h @@ -45,10 +45,10 @@ class moBackableNeighbor : virtual public moNeighbor { public: - /** - * the move back function - * @param _solution the solution to moveBack - */ + /** + * the move back function + * @param _solution the solution to moveBack + */ virtual void moveBack(EOT & _solution)=0; }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moBitNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moBitNeighbor.h index 3c4ccd35f..9ae964c09 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moBitNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moBitNeighbor.h @@ -56,7 +56,7 @@ public: * @param _solution the solution to move */ virtual void move(EOT & _solution) { - _solution[key] = !_solution[key]; + _solution[key] = !_solution[key]; } /** @@ -64,7 +64,7 @@ public: * @param _solution the solution to move back */ virtual void moveBack(EOT & _solution) { - _solution[key] = !_solution[key]; + _solution[key] = !_solution[key]; } /** @@ -72,39 +72,39 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moBitNeighbor"; + return "moBitNeighbor"; + } + + /** + * Read object.\ \ + * Calls base class, just in case that one had something to do. + * The read and print methods should be compatible and have the same format. + * In principle, format is "plain": they just print a number + * @param _is a std::istream. + * @throw runtime_std::exception If a valid object can't be read. + */ + virtual void readFrom(std::istream& _is) { + std::string fitness_str; + int pos = _is.tellg(); + _is >> fitness_str; + if (fitness_str == "INVALID") { + throw std::runtime_error("invalid fitness"); + } + else { + Fitness repFit ; + _is.seekg(pos); // rewind + _is >> repFit; + _is >> key; + fitness(repFit); + } } - - /** - * Read object.\ \ - * Calls base class, just in case that one had something to do. - * The read and print methods should be compatible and have the same format. - * In principle, format is "plain": they just print a number - * @param _is a std::istream. - * @throw runtime_std::exception If a valid object can't be read. - */ - virtual void readFrom(std::istream& _is) { - std::string fitness_str; - int pos = _is.tellg(); - _is >> fitness_str; - if (fitness_str == "INVALID"){ - throw std::runtime_error("invalid fitness"); - } - else{ - Fitness repFit ; - _is.seekg(pos); // rewind - _is >> repFit; - _is >> key; - fitness(repFit); - } - } /** * Write object. Called printOn since it prints the object _on_ a stream. * @param _os A std::ostream. */ virtual void printOn(std::ostream& _os) const { - _os << fitness() << ' ' << key << std::endl; + _os << fitness() << ' ' << key << std::endl; } }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moIndexNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moIndexNeighbor.h index c02747d2a..ef922b089 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moIndexNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moIndexNeighbor.h @@ -50,22 +50,22 @@ public: /** * Default Constructor */ - moIndexNeighbor() : moNeighbor(), key(0){} + moIndexNeighbor() : moNeighbor(), key(0) {} /** * Copy Constructor */ moIndexNeighbor(const moIndexNeighbor& _n) : moNeighbor(_n) { - this->key = _n.key ; + this->key = _n.key ; } /** * Assignment operator */ virtual moIndexNeighbor & operator=(const moIndexNeighbor & _source) { - moNeighbor::operator=(_source); - this->key = _source.key ; - return *this ; + moNeighbor::operator=(_source); + this->key = _source.key ; + return *this ; } /** @@ -73,23 +73,23 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moIndexNeighbor"; + return "moIndexNeighbor"; } /** * Getter * @return index of the IndexNeighbor */ - unsigned int index(){ - return key; + unsigned int index() { + return key; } /** * Setter * @param _key index of the IndexNeighbor */ - void index(unsigned int _key){ - key=_key; + void index(unsigned int _key) { + key=_key; } protected: diff --git a/trunk/paradiseo-mo/src/neighborhood/moIndexNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moIndexNeighborhood.h index 12c8b4246..d6129f92f 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moIndexNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moIndexNeighborhood.h @@ -44,23 +44,23 @@ template< class Neighbor > class moIndexNeighborhood : virtual public moNeighborhood { public: - /** - * Define type of a solution corresponding to Neighbor - */ + /** + * Define type of a solution corresponding to Neighbor + */ typedef typename Neighbor::EOT EOT; /** * Constructor * @param _neighborhoodSize the size of the neighborhood */ - moIndexNeighborhood(unsigned int _neighborhoodSize):neighborhoodSize(_neighborhoodSize){} + moIndexNeighborhood(unsigned int _neighborhoodSize):neighborhoodSize(_neighborhoodSize) {} /** * Return the class id. * @return the class name as a std::string */ virtual std::string className() const { - return "moIndexNeighborhood"; + return "moIndexNeighborhood"; } protected: diff --git a/trunk/paradiseo-mo/src/neighborhood/moNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moNeighbor.h index 38531bcf7..4114ff6ca 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moNeighbor.h @@ -47,30 +47,30 @@ template< class EOType , class Fitness > class moNeighbor : public eoObject, public eoPersistent { public: - typedef EOType EOT; + typedef EOType EOT; /** * Default Constructor */ - moNeighbor(){} + moNeighbor() {} /** * Copy Constructor * @param _neighbor to copy */ moNeighbor(const moNeighbor& _neighbor) { - repFitness = _neighbor.fitness(); + repFitness = _neighbor.fitness(); } - + /** * Assignment operator * @param _neighbor the neighbor to assign * @return a neighbor equal to the other */ virtual moNeighbor& operator=(const moNeighbor& _neighbor) { - repFitness = _neighbor.fitness(); - return (*this); + repFitness = _neighbor.fitness(); + return (*this); } - + /** * Move a solution * @param _solution the related solution @@ -82,32 +82,34 @@ public: * @return fitness of the neighbor */ const Fitness fitness() const { - return repFitness; + return repFitness; } - + /** * Get fitness as reference, useful when fitness is set in a multi-stage way, e.g., MOFitness gets performance information, is subsequently ranked * @return fitness as reference of the neighbor */ Fitness& fitnessReference() { - return repFitness; + return repFitness; } /** * Set fitness. At the same time, validates it. * @param _fitness new fitness value. */ - void fitness(const Fitness& _fitness){ - repFitness = _fitness; - } - + void fitness(const Fitness& _fitness) { + repFitness = _fitness; + } + /** * Return the class id. * @return the class name as a std::string */ - virtual std::string className() const { return "moNeighbor"; } - + virtual std::string className() const { + return "moNeighbor"; + } + /** * Read object. * Calls base class, just in case that one had something to do. @@ -116,7 +118,7 @@ public: * @param _is a std::istream. */ virtual void readFrom(std::istream& _is) { - _is >> repFitness; + _is >> repFitness; } /** @@ -124,9 +126,9 @@ public: * @param _os A std::ostream. */ virtual void printOn(std::ostream& _os) const { - _os << repFitness << std::endl; + _os << repFitness << std::endl; } - + protected: // minimal information on the neighbor : fitness Fitness repFitness ; diff --git a/trunk/paradiseo-mo/src/neighborhood/moNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moNeighborhood.h index bb3ca6d8f..2dd880aaa 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moNeighborhood.h @@ -44,21 +44,21 @@ template< class Neighbor > class moNeighborhood : public eoObject { public: - /** - * Define type of a solution corresponding to Neighbor - */ + /** + * Define type of a solution corresponding to Neighbor + */ typedef typename Neighbor::EOT EOT; /** * Default Constructor */ - moNeighborhood(){} + moNeighborhood() {} /** * @return if the neighborhood is random */ - virtual bool isRandom(){ - return false; + virtual bool isRandom() { + return false; } /** @@ -94,7 +94,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moNeighborhood"; + return "moNeighborhood"; } }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moOrderNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moOrderNeighborhood.h index fa3f7ef0d..b8a7245b8 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moOrderNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moOrderNeighborhood.h @@ -45,21 +45,21 @@ class moOrderNeighborhood : public moIndexNeighborhood { public: - /** - * Define type of a solution corresponding to Neighbor - */ + /** + * Define type of a solution corresponding to Neighbor + */ typedef N Neighbor; typedef typename Neighbor::EOT EOT; - using moIndexNeighborhood::neighborhoodSize; + using moIndexNeighborhood::neighborhoodSize; /** * Constructor * @param _neighborhoodSize the size of the neighborhood */ - moOrderNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood(_neighborhoodSize), currentIndex(0){} + moOrderNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood(_neighborhoodSize), currentIndex(0) {} /** * Test if it exist a neighbor @@ -67,7 +67,7 @@ public: * @return true if the neighborhood was not empty */ virtual bool hasNeighbor(EOT& _solution) { - return neighborhoodSize > 0; + return neighborhoodSize > 0; } /** @@ -76,8 +76,8 @@ public: * @param _neighbor the first neighbor */ virtual void init(EOT & _solution, Neighbor & _neighbor) { - currentIndex = 0 ; - _neighbor.index(currentIndex) ; + currentIndex = 0 ; + _neighbor.index(currentIndex) ; } /** @@ -86,8 +86,8 @@ public: * @param _neighbor the next neighbor */ virtual void next(EOT & _solution, Neighbor & _neighbor) { - currentIndex++ ; - _neighbor.index(currentIndex); + currentIndex++ ; + _neighbor.index(currentIndex); } /** @@ -98,15 +98,15 @@ public: * @return true if there is again a neighbor to explore */ virtual bool cont(EOT & _solution) { - return (currentIndex < neighborhoodSize - 1) ; + return (currentIndex < neighborhoodSize - 1) ; } /** * Getter * @return the position in the Neighborhood */ - unsigned int position(){ - return currentIndex; + unsigned int position() { + return currentIndex; } /** @@ -114,7 +114,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moOrderNeighborhood"; + return "moOrderNeighborhood"; } private: diff --git a/trunk/paradiseo-mo/src/neighborhood/moRndNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moRndNeighborhood.h index 2192bec57..8a80adb4a 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moRndNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moRndNeighborhood.h @@ -33,13 +33,13 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include template< class Neighbor > -class moRndNeighborhood : virtual public moNeighborhood{ +class moRndNeighborhood : virtual public moNeighborhood { public: - bool isRandom(){ - return true; - } + bool isRandom() { + return true; + } }; #endif diff --git a/trunk/paradiseo-mo/src/neighborhood/moRndWithReplNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moRndWithReplNeighborhood.h index 773138696..bad901816 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moRndWithReplNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moRndWithReplNeighborhood.h @@ -47,20 +47,20 @@ class moRndWithReplNeighborhood : public moIndexNeighborhood, public moRndNei { public: - /** - * Define type of a solution corresponding to Neighbor - */ + /** + * Define type of a solution corresponding to Neighbor + */ typedef N Neighbor; typedef typename Neighbor::EOT EOT; - using moIndexNeighborhood::neighborhoodSize; + using moIndexNeighborhood::neighborhoodSize; /** * Constructor * @param _neighborhoodSize the size of the neighborhood */ - moRndWithReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood(_neighborhoodSize){} + moRndWithReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood(_neighborhoodSize) {} /** * Test if it exist a neighbor @@ -68,7 +68,7 @@ public: * @return true if the neighborhood was not empty */ virtual bool hasNeighbor(EOT& _solution) { - return neighborhoodSize > 0; + return neighborhoodSize > 0; } /** @@ -77,7 +77,7 @@ public: * @param _neighbor the first neighbor */ virtual void init(EOT & _solution, Neighbor & _neighbor) { - _neighbor.index(rng.random(neighborhoodSize)); + _neighbor.index(rng.random(neighborhoodSize)); } /** @@ -86,7 +86,7 @@ public: * @param _neighbor the next neighbor */ virtual void next(EOT & _solution, Neighbor & _neighbor) { - _neighbor.index(rng.random(neighborhoodSize)); + _neighbor.index(rng.random(neighborhoodSize)); } /** @@ -95,7 +95,7 @@ public: * @return true if there is again a neighbor to explore */ virtual bool cont(EOT & _solution) { - return neighborhoodSize > 0; + return neighborhoodSize > 0; } /** @@ -103,7 +103,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moRndWithReplNeighborhood"; + return "moRndWithReplNeighborhood"; } }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moRndWithoutReplNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moRndWithoutReplNeighborhood.h index 3766deafb..89b7586ac 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moRndWithoutReplNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moRndWithoutReplNeighborhood.h @@ -47,22 +47,22 @@ class moRndWithoutReplNeighborhood : public moIndexNeighborhood, public moRnd { public: - /** - * Define type of a solution corresponding to Neighbor - */ + /** + * Define type of a solution corresponding to Neighbor + */ typedef N Neighbor; typedef typename Neighbor::EOT EOT; - using moIndexNeighborhood::neighborhoodSize; + using moIndexNeighborhood::neighborhoodSize; /** * Constructor * @param _neighborhoodSize the size of the neighborhood */ - moRndWithoutReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood(_neighborhoodSize), maxIndex(0){ - for(unsigned int i=0; i < neighborhoodSize; i++) - indexVector.push_back(i); + moRndWithoutReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood(_neighborhoodSize), maxIndex(0) { + for (unsigned int i=0; i < neighborhoodSize; i++) + indexVector.push_back(i); } /** @@ -71,7 +71,7 @@ public: * @return true if the neighborhood was not empty */ virtual bool hasNeighbor(EOT& _solution) { - return neighborhoodSize > 0; + return neighborhoodSize > 0; } /** @@ -80,14 +80,14 @@ public: * @param _neighbor the first neighbor */ virtual void init(EOT & _solution, Neighbor & _neighbor) { - unsigned int i, tmp; - maxIndex = neighborhoodSize ; - i = rng.random(maxIndex); - _neighbor.index(indexVector[i]); - tmp=indexVector[i]; - indexVector[i]=indexVector[maxIndex-1]; - indexVector[maxIndex-1]=tmp; - maxIndex--; + unsigned int i, tmp; + maxIndex = neighborhoodSize ; + i = rng.random(maxIndex); + _neighbor.index(indexVector[i]); + tmp=indexVector[i]; + indexVector[i]=indexVector[maxIndex-1]; + indexVector[maxIndex-1]=tmp; + maxIndex--; } /** @@ -96,31 +96,31 @@ public: * @param _neighbor the next neighbor */ virtual void next(EOT & _solution, Neighbor & _neighbor) { - unsigned int i, tmp; - i = rng.random(maxIndex); - _neighbor.index(indexVector[i]); - tmp=indexVector[i]; - indexVector[i]=indexVector[maxIndex-1]; - indexVector[maxIndex-1]=tmp; - maxIndex--; + unsigned int i, tmp; + i = rng.random(maxIndex); + _neighbor.index(indexVector[i]); + tmp=indexVector[i]; + indexVector[i]=indexVector[maxIndex-1]; + indexVector[maxIndex-1]=tmp; + maxIndex--; } /** * test if all neighbors are explore or not,if false, there is no neighbor left to explore - * maxIndex is number of neighbors + * maxIndex is number of neighbors * @param _solution the solution to explore * @return true if there is again a neighbor to explore */ virtual bool cont(EOT & _solution) { - return (maxIndex > 0) ; + return (maxIndex > 0) ; } /** * Getter * @return the position in the Neighborhood */ - unsigned int position(){ - return indexVector[maxIndex]; + unsigned int position() { + return indexVector[maxIndex]; } /** @@ -128,7 +128,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moRndWithoutReplNeighborhood"; + return "moRndWithoutReplNeighborhood"; } private: diff --git a/trunk/paradiseo-mo/src/old/moIncrEvalWrapper.h b/trunk/paradiseo-mo/src/old/moIncrEvalWrapper.h index d951804d5..5d4b2b86b 100644 --- a/trunk/paradiseo-mo/src/old/moIncrEvalWrapper.h +++ b/trunk/paradiseo-mo/src/old/moIncrEvalWrapper.h @@ -12,22 +12,22 @@ template class moIncrEvalWrapper : public moEval { public: - using moEval::EOT EOT; - using moEval::Fitness Fitness; + using moEval::EOT EOT; + using moEval::Fitness Fitness; - moIncrEvalWrapper(moIncrEval& _incr):incr(_incr){} + moIncrEvalWrapper(moIncrEval& _incr):incr(_incr) {} - /* - * make the evaluation of the current neighbor and update the information on this neighbor - * the evaluation could be incremental - */ - virtual void eval(MoveNeighbor& _neighbor,EOT & _solution){ - _neighbor.fitness(incrEval(*(_neighbor.getMove()), _solution)); - } + /* + * make the evaluation of the current neighbor and update the information on this neighbor + * the evaluation could be incremental + */ + virtual void eval(MoveNeighbor& _neighbor,EOT & _solution) { + _neighbor.fitness(incrEval(*(_neighbor.getMove()), _solution)); + } private: - /** the full evaluation object */ - moIncrEval & incrEval; + /** the full evaluation object */ + moIncrEval & incrEval; }; diff --git a/trunk/paradiseo-mo/src/old/moMove.h b/trunk/paradiseo-mo/src/old/moMove.h index ecf878783..2c56aa21a 100644 --- a/trunk/paradiseo-mo/src/old/moMove.h +++ b/trunk/paradiseo-mo/src/old/moMove.h @@ -2,20 +2,20 @@ Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008 (C) OPAC Team, LIFL, 2002-2008 - + Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr) - + This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". - + As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. - + In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, @@ -28,10 +28,10 @@ same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms. - + ParadisEO WebSite : http://paradiseo.gforge.inria.fr Contact: paradiseo-help@lists.gforge.inria.fr - + */ #ifndef _moMove_h @@ -48,10 +48,10 @@ template < class EOT > class moMove:public eoUF < EOT &, void > { - public: - - // Alias for the type - typedef EOT EOType; +public: + + // Alias for the type + typedef EOT EOType; }; #endif diff --git a/trunk/paradiseo-mo/src/old/moMoveIncrEval.h b/trunk/paradiseo-mo/src/old/moMoveIncrEval.h index e4a911eb7..d28fa8e06 100644 --- a/trunk/paradiseo-mo/src/old/moMoveIncrEval.h +++ b/trunk/paradiseo-mo/src/old/moMoveIncrEval.h @@ -47,6 +47,6 @@ */ template < class M, class Objective = typename M::EOType::Fitness> class moMoveIncrEval:public eoBF < const M &, const typename M::EOType &, Objective > -{}; + {}; #endif diff --git a/trunk/paradiseo-mo/src/old/moMoveInit.h b/trunk/paradiseo-mo/src/old/moMoveInit.h index dae026c72..8b59424af 100644 --- a/trunk/paradiseo-mo/src/old/moMoveInit.h +++ b/trunk/paradiseo-mo/src/old/moMoveInit.h @@ -2,20 +2,20 @@ Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008 (C) OPAC Team, LIFL, 2002-2008 - + Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr) - + This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". - + As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. - + In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, @@ -28,7 +28,7 @@ same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms. - + ParadisEO WebSite : http://paradiseo.gforge.inria.fr Contact: paradiseo-help@lists.gforge.inria.fr */ @@ -45,6 +45,6 @@ */ template < class M > class moMoveInit:public eoBF < M &, const typename M::EOType &, void > -{}; + {}; #endif diff --git a/trunk/paradiseo-mo/src/old/moMoveNeighbor.h b/trunk/paradiseo-mo/src/old/moMoveNeighbor.h index ce655e609..7550be693 100644 --- a/trunk/paradiseo-mo/src/old/moMoveNeighbor.h +++ b/trunk/paradiseo-mo/src/old/moMoveNeighbor.h @@ -12,58 +12,60 @@ contener of the neighbor informations */ template< class M , class Fitness > - class moMoveNeighbor : public moNeighbor +class moMoveNeighbor : public moNeighbor { public: - - typedef typename M::EOType EOT; + + typedef typename M::EOType EOT; // empty constructor - moMoveNeighbor() { - move=new M(); - }; + moMoveNeighbor() { + move=new M(); + }; - ~moMoveNeighbor() { - delete move; - }; + ~moMoveNeighbor() { + delete move; + }; + + // copy constructeur + moMoveNeighbor(const moMoveNeighbor & _n) { + moNeighbor::operator=(_n); + (*move) = *(_n.getMove()); + } - // copy constructeur - moMoveNeighbor(const moMoveNeighbor & _n) { - moNeighbor::operator=(_n); - (*move) = *(_n.getMove()); - } - // assignment operator virtual moMoveNeighbor & operator=(const moMoveNeighbor & _n) { - moNeighbor ::operator=(_n); - (*move) = *(_n.getMove()); - return *this ; + moNeighbor ::operator=(_n); + (*move) = *(_n.getMove()); + return *this ; } - + /* * move the solution */ - virtual void move(EOT & _solution){ - (*move)(_solution); + virtual void move(EOT & _solution) { + (*move)(_solution); } /** Return the class id. * @return the class name as a std::string */ - virtual std::string className() const { return "moMoveNeighbor"; } - - void setMove(M* _move){ - move=_move; + virtual std::string className() const { + return "moMoveNeighbor"; } - M* getMove(){ - return move; + void setMove(M* _move) { + move=_move; } - + M* getMove() { + return move; + } + + private: M* move; - + }; #endif diff --git a/trunk/paradiseo-mo/src/old/moMoveNeighborhood.h b/trunk/paradiseo-mo/src/old/moMoveNeighborhood.h index b66b925a2..aede5fc44 100644 --- a/trunk/paradiseo-mo/src/old/moMoveNeighborhood.h +++ b/trunk/paradiseo-mo/src/old/moMoveNeighborhood.h @@ -8,47 +8,49 @@ #include template< class M, class Fitness > - class moMoveNeighborhood : public moNeighborhood > +class moMoveNeighborhood : public moNeighborhood > { public: - typedef moMoveNeighbor Neighbor; - typedef typename M::EOType EOT; + typedef moMoveNeighbor Neighbor; + typedef typename M::EOType EOT; - moMoveNeighborhood(moMoveInit& i, moNextMove& n):_init(i), _next(n), isContinue(true) {} + moMoveNeighborhood(moMoveInit& i, moNextMove& n):_init(i), _next(n), isContinue(true) {} - virtual bool hasNeighbor(EOT & solution){ - return true; - } + virtual bool hasNeighbor(EOT & solution) { + return true; + } /* initialisation of the neighborhood */ - virtual void init(EOT & solution, Neighbor & current){ - _init(*(current._move), solution); - isContinue=true; - } + virtual void init(EOT & solution, Neighbor & current) { + _init(*(current._move), solution); + isContinue=true; + } /* Give the next neighbor */ - virtual void next(EOT & solution, Neighbor & current){ - isContinue=_next(*(current._move), solution); - } + virtual void next(EOT & solution, Neighbor & current) { + isContinue=_next(*(current._move), solution); + } - /* - if false, there is no neighbor left to explore - */ - virtual bool cont(EOT & solution){ - return isContinue; - } + /* + if false, there is no neighbor left to explore + */ + virtual bool cont(EOT & solution) { + return isContinue; + } /** Return the class id. * @return the class name as a std::string */ - virtual std::string className() const { return "moMoveNeighborhood"; } + virtual std::string className() const { + return "moMoveNeighborhood"; + } - private: +private: moMoveInit& _init; moNextMove& _next; bool isContinue; diff --git a/trunk/paradiseo-mo/src/old/moNextMove.h b/trunk/paradiseo-mo/src/old/moNextMove.h index c40268f2f..10fda225d 100644 --- a/trunk/paradiseo-mo/src/old/moNextMove.h +++ b/trunk/paradiseo-mo/src/old/moNextMove.h @@ -2,20 +2,20 @@ Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008 (C) OPAC Team, LIFL, 2002-2008 - + Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr) - + This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". - + As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. - + In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, @@ -28,7 +28,7 @@ same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms. - + ParadisEO WebSite : http://paradiseo.gforge.inria.fr Contact: paradiseo-help@lists.gforge.inria.fr */ @@ -43,8 +43,8 @@ * Useful for the explorer (for moTS or moHC). * Does nothing... An object that herits from this class needs to be designed for being used. */ -template < class M > +template < class M > class moNextMove:public eoBF < M &, const typename M::EOType &, bool > -{}; + {}; #endif diff --git a/trunk/paradiseo-mo/test/moTestClass.h b/trunk/paradiseo-mo/test/moTestClass.h index 7350d7628..9324f3ac4 100644 --- a/trunk/paradiseo-mo/test/moTestClass.h +++ b/trunk/paradiseo-mo/test/moTestClass.h @@ -54,151 +54,151 @@ typedef eoBit bitVector; typedef moBitNeighbor bitNeighbor ; -class moDummyRndNeighborhood: public moOrderNeighborhood/*, public moRndNeighborhood*/{ +class moDummyRndNeighborhood: public moOrderNeighborhood/*, public moRndNeighborhood*/ { public: - moDummyRndNeighborhood(unsigned int a): moOrderNeighborhood(a){} + moDummyRndNeighborhood(unsigned int a): moOrderNeighborhood(a) {} }; typedef moDummyRndNeighborhood bitNeighborhood ; typedef EO Solution; -class moDummyNeighbor : public moNeighbor{ +class moDummyNeighbor : public moNeighbor { public: - virtual void move(Solution & _solution){} + virtual void move(Solution & _solution) {} }; -class moDummyBackableNeighbor : public moBackableNeighbor{ +class moDummyBackableNeighbor : public moBackableNeighbor { public: - virtual void move(Solution & _solution){} - virtual void moveBack(Solution & _solution){} + virtual void move(Solution & _solution) {} + virtual void moveBack(Solution & _solution) {} }; -class moDummyNeighborhood : public moNeighborhood{ +class moDummyNeighborhood : public moNeighborhood { public: - typedef moDummyNeighbor Neighbor; + typedef moDummyNeighbor Neighbor; - moDummyNeighborhood():i(0),j(0){} + moDummyNeighborhood():i(0),j(0) {} - virtual bool hasNeighbor(EOT & _solution){ - bool res; - if(i%3==0) - res=false; - else - res=true; - i++; - return res; + virtual bool hasNeighbor(EOT & _solution) { + bool res; + if (i%3==0) + res=false; + else + res=true; + i++; + return res; } - virtual void init(EOT & _solution, Neighbor & _current){} - virtual void next(EOT & _solution, Neighbor & _current){} - virtual bool cont(EOT & _solution){ - j++; - return (j%10!=0); + virtual void init(EOT & _solution, Neighbor & _current) {} + virtual void next(EOT & _solution, Neighbor & _current) {} + virtual bool cont(EOT & _solution) { + j++; + return (j%10!=0); } private: int i,j; }; -class moDummyEval: public eoEvalFunc{ +class moDummyEval: public eoEvalFunc { public: - void operator()(Solution& _sol){ - if(_sol.invalid()) - _sol.fitness(100); - else - _sol.fitness(_sol.fitness()+50); - } + void operator()(Solution& _sol) { + if (_sol.invalid()) + _sol.fitness(100); + else + _sol.fitness(_sol.fitness()+50); + } }; class evalOneMax : public moEval< bitNeighbor > { private: - unsigned size; + unsigned size; public: - evalOneMax(unsigned _size) : size(_size) {}; + evalOneMax(unsigned _size) : size(_size) {}; - ~evalOneMax(void) {} ; + ~evalOneMax(void) {} ; - void operator() (bitVector& _sol, bitNeighbor& _n) { - unsigned int fit = _sol.fitness(); - if(_sol[_n.index()]) - fit--; - else - fit++; - _n.fitness(fit); - } + void operator() (bitVector& _sol, bitNeighbor& _n) { + unsigned int fit = _sol.fitness(); + if (_sol[_n.index()]) + fit--; + else + fit++; + _n.fitness(fit); + } }; class dummyEvalOneMax : public moEval< bitNeighbor > { private: - unsigned size; + unsigned size; public: - dummyEvalOneMax(unsigned _size) : size(_size) {}; + dummyEvalOneMax(unsigned _size) : size(_size) {}; - ~dummyEvalOneMax(void) {} ; + ~dummyEvalOneMax(void) {} ; - void operator() (bitVector& _sol, bitNeighbor& _n) { - unsigned int fit = _sol.fitness(); - _n.fitness(fit); - } + void operator() (bitVector& _sol, bitNeighbor& _n) { + unsigned int fit = _sol.fitness(); + _n.fitness(fit); + } }; class monitor1 : public eoMonitor { public: - monitor1(unsigned int& _a): a(_a){} + monitor1(unsigned int& _a): a(_a) {} - eoMonitor& operator()(){ - a++; - return *this; - } + eoMonitor& operator()() { + a++; + return *this; + } - void lastCall(){ - a++; - } + void lastCall() { + a++; + } private: - unsigned int& a; + unsigned int& a; }; class monitor2 : public eoMonitor { public: - monitor2(unsigned int& _a): a(_a){} + monitor2(unsigned int& _a): a(_a) {} - eoMonitor& operator()(){ - a++; - return *this; - } + eoMonitor& operator()() { + a++; + return *this; + } - void lastCall(){ - a++; - } + void lastCall() { + a++; + } private: - unsigned int& a; + unsigned int& a; }; class updater1: public eoUpdater { public: - updater1(unsigned int& _a): a(_a){} + updater1(unsigned int& _a): a(_a) {} - void operator()(){ - a++; - } + void operator()() { + a++; + } - void lastCall(){ - a++; - } + void lastCall() { + a++; + } private: - unsigned int& a; + unsigned int& a; }; #endif diff --git a/trunk/paradiseo-mo/test/t-moBestImprAspiration.cpp b/trunk/paradiseo-mo/test/t-moBestImprAspiration.cpp index a7910ba80..cd2de284d 100644 --- a/trunk/paradiseo-mo/test/t-moBestImprAspiration.cpp +++ b/trunk/paradiseo-mo/test/t-moBestImprAspiration.cpp @@ -33,46 +33,46 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moBestImprAspiration] => START" << std::endl; + std::cout << "[t-moBestImprAspiration] => START" << std::endl; - moBestImprAspiration test; - eoBit sol1(4); - eoBit sol2(4); - eoBit sol3(4); - eoBit sol4(4); - bitNeighbor n1; - bitNeighbor n2; - bitNeighbor n3; - bitNeighbor n4; + moBestImprAspiration test; + eoBit sol1(4); + eoBit sol2(4); + eoBit sol3(4); + eoBit sol4(4); + bitNeighbor n1; + bitNeighbor n2; + bitNeighbor n3; + bitNeighbor n4; - sol3[0]=true; - sol4[3]=true; + sol3[0]=true; + sol4[3]=true; - sol1.fitness(4); - sol2.fitness(5); - sol3.fitness(3); - sol4.fitness(3); - n1.fitness(4); - n2.fitness(5); - n3.fitness(3); - n4.fitness(3); + sol1.fitness(4); + sol2.fitness(5); + sol3.fitness(3); + sol4.fitness(3); + n1.fitness(4); + n2.fitness(5); + n3.fitness(3); + n4.fitness(3); - //verification qu'on update bien le best so far quand il faut - test.init(sol1); - assert(test.getBest()==sol1); - assert(!test(sol2,n2)); - assert(test(sol3,n3)); - test.update(sol3,n3); - assert(test.getBest()==sol3); - assert(!test(sol4,n4)); - test.update(sol4,n4); - assert(test.getBest()==sol3); + //verification qu'on update bien le best so far quand il faut + test.init(sol1); + assert(test.getBest()==sol1); + assert(!test(sol2,n2)); + assert(test(sol3,n3)); + test.update(sol3,n3); + assert(test.getBest()==sol3); + assert(!test(sol4,n4)); + test.update(sol4,n4); + assert(test.getBest()==sol3); - std::cout << "[t-moBestImprAspiration] => OK" << std::endl; + std::cout << "[t-moBestImprAspiration] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moBitNeighbor.cpp b/trunk/paradiseo-mo/test/t-moBitNeighbor.cpp index ee3bd1e68..a5f3d3689 100644 --- a/trunk/paradiseo-mo/test/t-moBitNeighbor.cpp +++ b/trunk/paradiseo-mo/test/t-moBitNeighbor.cpp @@ -37,49 +37,49 @@ #include #include -int main(){ +int main() { - std::cout << "[t-moBitNeighbor] => START" << std::endl; + std::cout << "[t-moBitNeighbor] => START" << std::endl; - //init sol - eoBit sol; - sol.push_back(true); - sol.push_back(false); - sol.push_back(true); + //init sol + eoBit sol; + sol.push_back(true); + sol.push_back(false); + sol.push_back(true); - //verif du constructeur vide - moBitNeighbor test1; - assert(test1.index()==0); + //verif du constructeur vide + moBitNeighbor test1; + assert(test1.index()==0); - //verif du setter d'index et du constructeur de copy - test1.index(6); - test1.fitness(2); - moBitNeighbor test2(test1); - assert(test2.index()==6); - assert(test2.fitness()==2); + //verif du setter d'index et du constructeur de copy + test1.index(6); + test1.fitness(2); + moBitNeighbor test2(test1); + assert(test2.index()==6); + assert(test2.fitness()==2); - //verif du getter - assert(test1.index()==6); + //verif du getter + assert(test1.index()==6); - //verif de l'operateur= - test1.fitness(8); - test1.index(2); - test2=test1; - assert(test2.fitness()==8); - assert(test2.index()==2); + //verif de l'operateur= + test1.fitness(8); + test1.index(2); + test2=test1; + assert(test2.fitness()==8); + assert(test2.index()==2); - //verif de move - test2.move(sol); - assert(!sol[2]); + //verif de move + test2.move(sol); + assert(!sol[2]); - //verif de moveBack - test2.moveBack(sol); - assert(sol[2]); + //verif de moveBack + test2.moveBack(sol); + assert(sol[2]); - test1.printOn(std::cout); - test2.printOn(std::cout); + test1.printOn(std::cout); + test2.printOn(std::cout); - assert(test1.className()=="moBitNeighbor"); - std::cout << "[t-moBitNeighbor] => OK" << std::endl; - return EXIT_SUCCESS; + assert(test1.className()=="moBitNeighbor"); + std::cout << "[t-moBitNeighbor] => OK" << std::endl; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moCheckpoint.cpp b/trunk/paradiseo-mo/test/t-moCheckpoint.cpp index fb9b788e7..4bfe440cc 100644 --- a/trunk/paradiseo-mo/test/t-moCheckpoint.cpp +++ b/trunk/paradiseo-mo/test/t-moCheckpoint.cpp @@ -36,87 +36,87 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moCheckpoint] => START" << std::endl; + std::cout << "[t-moCheckpoint] => START" << std::endl; - unsigned int a=2; - unsigned int b=15; - unsigned int c= 10; - unsigned int d= 47; + unsigned int a=2; + unsigned int b=15; + unsigned int c= 10; + unsigned int d= 47; - eoBit s(3); - s[0]=true; - s[1]=true; - s[2]=false; + eoBit s(3); + s[0]=true; + s[1]=true; + s[2]=false; - s.fitness(17); + s.fitness(17); - //verification que toutes les operateurs sont bien apellés - moSolutionStat< eoBit< eoMinimizingFitness > > stat; - updater1 up1(a); - updater1 up2(b); - monitor1 mon1(c); - monitor2 mon2(d); - moTrueContinuator< bitNeighborhood > cont; + //verification que toutes les operateurs sont bien apellés + moSolutionStat< eoBit< eoMinimizingFitness > > stat; + updater1 up1(a); + updater1 up2(b); + monitor1 mon1(c); + monitor2 mon2(d); + moTrueContinuator< bitNeighborhood > cont; - moCheckpoint< bitNeighborhood> test1(cont); - moCheckpoint< bitNeighborhood> test2(cont, 3); + moCheckpoint< bitNeighborhood> test1(cont); + moCheckpoint< bitNeighborhood> test2(cont, 3); - test1.add(up1); - test1.add(up2); - test1.add(mon1); - test1.add(mon2); - test1.add(stat); + test1.add(up1); + test1.add(up2); + test1.add(mon1); + test1.add(mon2); + test1.add(stat); - test2.add(up1); - test2.add(up2); - test2.add(mon1); - test2.add(mon2); - test2.add(stat); + test2.add(up1); + test2.add(up2); + test2.add(mon1); + test2.add(mon2); + test2.add(stat); - test1.init(s); - test1(s); - assert(a==3 && b==16 && c==11 && d==48); - assert(stat.value()[0]); - assert(stat.value()[1]); - assert(!stat.value()[2]); - assert(stat.value().fitness()==17); + test1.init(s); + test1(s); + assert(a==3 && b==16 && c==11 && d==48); + assert(stat.value()[0]); + assert(stat.value()[1]); + assert(!stat.value()[2]); + assert(stat.value().fitness()==17); - test1(s); - assert(a==4 && b==17 && c==12 && d==49); - assert(stat.value()[0]); - assert(stat.value()[1]); - assert(!stat.value()[2]); - assert(stat.value().fitness()==17); + test1(s); + assert(a==4 && b==17 && c==12 && d==49); + assert(stat.value()[0]); + assert(stat.value()[1]); + assert(!stat.value()[2]); + assert(stat.value().fitness()==17); - s.fitness(4); + s.fitness(4); - test2.init(s); - test2(s); - assert(a==5 && b==18 && c==13 && d==50); - assert(stat.value()[0]); - assert(stat.value()[1]); - assert(!stat.value()[2]); - assert(stat.value().fitness()==4); + test2.init(s); + test2(s); + assert(a==5 && b==18 && c==13 && d==50); + assert(stat.value()[0]); + assert(stat.value()[1]); + assert(!stat.value()[2]); + assert(stat.value().fitness()==4); - s.fitness(6); - test2(s); - assert(stat.value().fitness()==4); - test2(s); - assert(stat.value().fitness()==4); - test2(s); - assert(stat.value().fitness()==6); + s.fitness(6); + test2(s); + assert(stat.value().fitness()==4); + test2(s); + assert(stat.value().fitness()==4); + test2(s); + assert(stat.value().fitness()==6); - test1.lastCall(s); - assert(a==9 && b==22 && c==17 && d==54); - test2.lastCall(s); - assert(a==10 && b==23 && c==18 && d==55); + test1.lastCall(s); + assert(a==9 && b==22 && c==17 && d==54); + test2.lastCall(s); + assert(a==10 && b==23 && c==18 && d==55); - assert(test1.className()=="moCheckpoint"); - std::cout << "[t-moCheckpoint] => OK" << std::endl; + assert(test1.className()=="moCheckpoint"); + std::cout << "[t-moCheckpoint] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moCounterMonitorSaver.cpp b/trunk/paradiseo-mo/test/t-moCounterMonitorSaver.cpp index 7ea014147..2672be7f3 100644 --- a/trunk/paradiseo-mo/test/t-moCounterMonitorSaver.cpp +++ b/trunk/paradiseo-mo/test/t-moCounterMonitorSaver.cpp @@ -35,37 +35,37 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include -int main(){ +int main() { - std::cout << "[t-moCounterMonitorSaver] => START" << std::endl; + std::cout << "[t-moCounterMonitorSaver] => START" << std::endl; - unsigned int a=1; - unsigned int b=10; + unsigned int a=1; + unsigned int b=10; - monitor1 mon1(a); - monitor2 mon2(b); + monitor1 mon1(a); + monitor2 mon2(b); - moCounterMonitorSaver test(3, mon1); - test.add(mon2); + moCounterMonitorSaver test(3, mon1); + test.add(mon2); - //on verifie qu'on apelle les moniteurs seulement tout les 3 itération + //on verifie qu'on apelle les moniteurs seulement tout les 3 itération - test(); - assert(a==2 && b==11); - test(); - assert(a==2 && b==11); - test(); - assert(a==2 && b==11); - test(); - assert(a==3 && b==12); + test(); + assert(a==2 && b==11); + test(); + assert(a==2 && b==11); + test(); + assert(a==2 && b==11); + test(); + assert(a==3 && b==12); - //test du lastCall - test.lastCall(); - assert(a==4 && b==13); + //test du lastCall + test.lastCall(); + assert(a==4 && b==13); - assert(test.className()=="moCounterMonitorSaver"); - std::cout << "[t-moCounterMonitorSaver] => OK" << std::endl; + assert(test.className()=="moCounterMonitorSaver"); + std::cout << "[t-moCounterMonitorSaver] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moDistanceStat.cpp b/trunk/paradiseo-mo/test/t-moDistanceStat.cpp index 8a8434817..5fd98b550 100644 --- a/trunk/paradiseo-mo/test/t-moDistanceStat.cpp +++ b/trunk/paradiseo-mo/test/t-moDistanceStat.cpp @@ -35,39 +35,39 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moDistanceStat] => START" << std::endl; + std::cout << "[t-moDistanceStat] => START" << std::endl; - eoBit sol1; - eoBit sol2; - eoBit sol3; - sol1.push_back(true); - sol1.push_back(false); - sol1.push_back(true); + eoBit sol1; + eoBit sol2; + eoBit sol3; + sol1.push_back(true); + sol1.push_back(false); + sol1.push_back(true); - sol2.push_back(true); - sol2.push_back(true); - sol2.push_back(false); + sol2.push_back(true); + sol2.push_back(true); + sol2.push_back(false); - sol3.push_back(true); - sol3.push_back(true); - sol3.push_back(true); + sol3.push_back(true); + sol3.push_back(true); + sol3.push_back(true); - //verification de la stat avec une distance de Hamming + //verification de la stat avec une distance de Hamming - eoHammingDistance< eoBit > dist; + eoHammingDistance< eoBit > dist; - moDistanceStat< eoBit > test(dist, sol1); + moDistanceStat< eoBit > test(dist, sol1); - test(sol2); - assert(test.value()==2); - test(sol3); - assert(test.value()==1); + test(sol2); + assert(test.value()==2); + test(sol3); + assert(test.value()==1); - assert(test.className()=="moDistanceStat"); - std::cout << "[t-moDistanceStat] => OK" << std::endl; + assert(test.className()=="moDistanceStat"); + std::cout << "[t-moDistanceStat] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moDummyMemory.cpp b/trunk/paradiseo-mo/test/t-moDummyMemory.cpp index 5d965da43..4dcda2bc1 100644 --- a/trunk/paradiseo-mo/test/t-moDummyMemory.cpp +++ b/trunk/paradiseo-mo/test/t-moDummyMemory.cpp @@ -35,29 +35,29 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moDummyMemory] => START" << std::endl; + std::cout << "[t-moDummyMemory] => START" << std::endl; - eoBit sol(4); - bitNeighbor n; - moDummyDiversification test1; - test1.init(sol); - test1.add(sol, n); - test1.update(sol, n); - test1.clearMemory(); - assert(!test1(sol)); + eoBit sol(4); + bitNeighbor n; + moDummyDiversification test1; + test1.init(sol); + test1.add(sol, n); + test1.update(sol, n); + test1.clearMemory(); + assert(!test1(sol)); - moDummyIntensification test2; - test2.init(sol); - test2.add(sol, n); - test2.update(sol, n); - test2.clearMemory(); - assert(!test2(sol)); + moDummyIntensification test2; + test2.init(sol); + test2.add(sol, n); + test2.update(sol, n); + test2.clearMemory(); + assert(!test2(sol)); - std::cout << "[t-moDummyMemory] => OK" << std::endl; + std::cout << "[t-moDummyMemory] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moFirstImprExplorer.cpp b/trunk/paradiseo-mo/test/t-moFirstImprExplorer.cpp index 6506ec753..1d4601d2f 100644 --- a/trunk/paradiseo-mo/test/t-moFirstImprExplorer.cpp +++ b/trunk/paradiseo-mo/test/t-moFirstImprExplorer.cpp @@ -36,58 +36,58 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moFirstImprExplorer] => START" << std::endl; + std::cout << "[t-moFirstImprExplorer] => START" << std::endl; - //Instanciation - eoBit sol(4, true); - sol.fitness(4); - bitNeighborhood nh(4); - evalOneMax eval(4); - moNeighborComparator ncomp; - moSolNeighborComparator sncomp; + //Instanciation + eoBit sol(4, true); + sol.fitness(4); + bitNeighborhood nh(4); + evalOneMax eval(4); + moNeighborComparator ncomp; + moSolNeighborComparator sncomp; - moFirstImprExplorer test(nh, eval, ncomp, sncomp); + moFirstImprExplorer test(nh, eval, ncomp, sncomp); - //on verifie qu'on améliore peut continuer à explorer tant qu'on améliore la solution + //on verifie qu'on améliore peut continuer à explorer tant qu'on améliore la solution - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==3); - assert(!sol[0]); - assert(test.isContinue(sol)); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==3); + assert(!sol[0]); + assert(test.isContinue(sol)); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==2); - assert(!sol[1]); - assert(test.isContinue(sol)); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==2); + assert(!sol[1]); + assert(test.isContinue(sol)); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==1); - assert(!sol[2]); - assert(test.isContinue(sol)); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==1); + assert(!sol[2]); + assert(test.isContinue(sol)); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==0); - assert(!sol[3]); - assert(test.isContinue(sol)); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==0); + assert(!sol[3]); + assert(test.isContinue(sol)); - test(sol); - assert(!test.accept(sol)); - assert(sol.fitness()==0); - assert(!test.isContinue(sol)); + test(sol); + assert(!test.accept(sol)); + assert(sol.fitness()==0); + assert(!test.isContinue(sol)); - std::cout << "[t-moFirstImprExplorer] => OK" << std::endl; + std::cout << "[t-moFirstImprExplorer] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moFitnessStat.cpp b/trunk/paradiseo-mo/test/t-moFitnessStat.cpp index 34d221508..dc0c47102 100644 --- a/trunk/paradiseo-mo/test/t-moFitnessStat.cpp +++ b/trunk/paradiseo-mo/test/t-moFitnessStat.cpp @@ -34,24 +34,24 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moFitnessStat] => START" << std::endl; + std::cout << "[t-moFitnessStat] => START" << std::endl; - eoBit sol; + eoBit sol; - moFitnessStat< eoBit > test; - sol.fitness(3); - test(sol); - assert(test.value()==3); + moFitnessStat< eoBit > test; + sol.fitness(3); + test(sol); + assert(test.value()==3); - sol.fitness(12); - test(sol); - assert(test.value()==12); + sol.fitness(12); + test(sol); + assert(test.value()==12); - assert(test.className()=="moFitnessStat"); - std::cout << "[t-moFitnessStat] => OK" << std::endl; + assert(test.className()=="moFitnessStat"); + std::cout << "[t-moFitnessStat] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moFullEvalByCopy.cpp b/trunk/paradiseo-mo/test/t-moFullEvalByCopy.cpp index c2865a751..c7d7c838b 100644 --- a/trunk/paradiseo-mo/test/t-moFullEvalByCopy.cpp +++ b/trunk/paradiseo-mo/test/t-moFullEvalByCopy.cpp @@ -38,26 +38,26 @@ #include #include -int main(){ +int main() { - //Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval + //Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval - std::cout << "[t-moFullEvalByCopy] => START" << std::endl; + std::cout << "[t-moFullEvalByCopy] => START" << std::endl; - Solution sol; - moDummyNeighbor neighbor; - moDummyEval eval; + Solution sol; + moDummyNeighbor neighbor; + moDummyEval eval; - //verif constructor - moFullEvalByCopy test(eval); + //verif constructor + moFullEvalByCopy test(eval); - sol.fitness(3); + sol.fitness(3); - //verif operator() - test(sol,neighbor); - assert(sol.fitness()==3); + //verif operator() + test(sol,neighbor); + assert(sol.fitness()==3); - std::cout << "[t-moFullEvalByCopy] => OK" << std::endl; + std::cout << "[t-moFullEvalByCopy] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moFullEvalByModif.cpp b/trunk/paradiseo-mo/test/t-moFullEvalByModif.cpp index 0c71df098..741b831d9 100644 --- a/trunk/paradiseo-mo/test/t-moFullEvalByModif.cpp +++ b/trunk/paradiseo-mo/test/t-moFullEvalByModif.cpp @@ -38,26 +38,26 @@ #include #include -int main(){ +int main() { - //Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval + //Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval - std::cout << "[t-moFullEvalByModif] => START" << std::endl; + std::cout << "[t-moFullEvalByModif] => START" << std::endl; - Solution sol; - moDummyBackableNeighbor neighbor; - moDummyEval eval; + Solution sol; + moDummyBackableNeighbor neighbor; + moDummyEval eval; - //verif constructor - moFullEvalByModif test(eval); + //verif constructor + moFullEvalByModif test(eval); - sol.fitness(3); + sol.fitness(3); - //verif operator() - test(sol,neighbor); - assert(sol.fitness()==3); + //verif operator() + test(sol,neighbor); + assert(sol.fitness()==3); - std::cout << "[t-moFullEvalByModif] => OK" << std::endl; + std::cout << "[t-moFullEvalByModif] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moHCneutralExplorer.cpp b/trunk/paradiseo-mo/test/t-moHCneutralExplorer.cpp index cc7f65a6a..e95e79c81 100644 --- a/trunk/paradiseo-mo/test/t-moHCneutralExplorer.cpp +++ b/trunk/paradiseo-mo/test/t-moHCneutralExplorer.cpp @@ -36,57 +36,57 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moHCneutralExplorer] => START" << std::endl; + std::cout << "[t-moHCneutralExplorer] => START" << std::endl; - //Instanciation - eoBit sol(4, true); - sol.fitness(4); - bitNeighborhood nh(4); - evalOneMax eval(4); - moNeighborComparator ncomp; - moSolNeighborComparator sncomp; + //Instanciation + eoBit sol(4, true); + sol.fitness(4); + bitNeighborhood nh(4); + evalOneMax eval(4); + moNeighborComparator ncomp; + moSolNeighborComparator sncomp; - moHCneutralExplorer test(nh, eval, ncomp, sncomp,3); + moHCneutralExplorer test(nh, eval, ncomp, sncomp,3); - //on verifie qu'on ameliore bien la solution et que l'exploration dure 3 itérations + //on verifie qu'on ameliore bien la solution et que l'exploration dure 3 itérations - test.initParam(sol); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==3); - test.updateParam(sol); - assert(test.isContinue(sol)); + test.initParam(sol); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==3); + test.updateParam(sol); + assert(test.isContinue(sol)); - //les affichages permettent de voir qu'on prend pas toujours les mm voisins(lancer plusieurs fois l'exe) - std::cout << sol << std::endl; + //les affichages permettent de voir qu'on prend pas toujours les mm voisins(lancer plusieurs fois l'exe) + std::cout << sol << std::endl; - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==2); - test.updateParam(sol); - assert(test.isContinue(sol)); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==2); + test.updateParam(sol); + assert(test.isContinue(sol)); - std::cout << sol << std::endl; + std::cout << sol << std::endl; - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==1); - test.updateParam(sol); - assert(!test.isContinue(sol)); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==1); + test.updateParam(sol); + assert(!test.isContinue(sol)); - std::cout << sol << std::endl; + std::cout << sol << std::endl; - std::cout << "[t-moHCneutralExplorer] => OK" << std::endl; + std::cout << "[t-moHCneutralExplorer] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moMetropolisHastingExplorer.cpp b/trunk/paradiseo-mo/test/t-moMetropolisHastingExplorer.cpp index 8ddd4f8ef..730db2b6b 100644 --- a/trunk/paradiseo-mo/test/t-moMetropolisHastingExplorer.cpp +++ b/trunk/paradiseo-mo/test/t-moMetropolisHastingExplorer.cpp @@ -34,64 +34,64 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl; + std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl; - //Instanciation - eoBit sol(4, true); - sol.fitness(4); - bitNeighborhood nh(4); - evalOneMax eval(4); - moNeighborComparator ncomp; - moSolNeighborComparator sncomp; + //Instanciation + eoBit sol(4, true); + sol.fitness(4); + bitNeighborhood nh(4); + evalOneMax eval(4); + moNeighborComparator ncomp; + moSolNeighborComparator sncomp; - moMetropolisHastingExplorer test(nh, eval, ncomp, sncomp, 3); + moMetropolisHastingExplorer test(nh, eval, ncomp, sncomp, 3); - //test de l'acceptation d'un voisin améliorant - test.initParam(sol); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==3); - test.updateParam(sol); - assert(test.isContinue(sol)); + //test de l'acceptation d'un voisin améliorant + test.initParam(sol); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==3); + test.updateParam(sol); + assert(test.isContinue(sol)); - unsigned int oui=0, non=0; + unsigned int oui=0, non=0; - //test de l'acceptation d'un voisin non améliorant - for(unsigned int i=0; i<1000; i++){ - test(sol); - if(test.accept(sol)) - oui++; - else - non++; - } - std::cout << "Attention test en fonction d'une proba \"p\" uniforme dans [0,1] , oui si p < 3/4, non sinon -> resultat sur 1000 essai" << std::endl; - std::cout << "oui: " << oui << std::endl; - std::cout << "non: " << non << std::endl; + //test de l'acceptation d'un voisin non améliorant + for (unsigned int i=0; i<1000; i++) { + test(sol); + if (test.accept(sol)) + oui++; + else + non++; + } + std::cout << "Attention test en fonction d'une proba \"p\" uniforme dans [0,1] , oui si p < 3/4, non sinon -> resultat sur 1000 essai" << std::endl; + std::cout << "oui: " << oui << std::endl; + std::cout << "non: " << non << std::endl; - assert(oui > 700 && oui < 800); //verification grossiere + assert(oui > 700 && oui < 800); //verification grossiere - //test du critere d'arret - test.updateParam(sol); - assert(test.isContinue(sol)); - test.updateParam(sol); - assert(!test.isContinue(sol)); + //test du critere d'arret + test.updateParam(sol); + assert(test.isContinue(sol)); + test.updateParam(sol); + assert(!test.isContinue(sol)); - //test de l'acceptation d'un voisin - sol[0]=false; - sol[1]=false; - sol[2]=false; - sol[3]=false; - sol.fitness(0); + //test de l'acceptation d'un voisin + sol[0]=false; + sol[1]=false; + sol[2]=false; + sol[3]=false; + sol.fitness(0); - test.initParam(sol); - test(sol); - assert(!test.accept(sol)); + test.initParam(sol); + test(sol); + assert(!test.accept(sol)); - std::cout << "[t-moMetropolisHastingExplorer] => OK" << std::endl; + std::cout << "[t-moMetropolisHastingExplorer] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moNeighbor.cpp b/trunk/paradiseo-mo/test/t-moNeighbor.cpp index d703f8ce4..6fbff336d 100644 --- a/trunk/paradiseo-mo/test/t-moNeighbor.cpp +++ b/trunk/paradiseo-mo/test/t-moNeighbor.cpp @@ -37,28 +37,28 @@ #include #include -int main(){ +int main() { - std::cout << "[t-moNeighbor] => START" << std::endl; + std::cout << "[t-moNeighbor] => START" << std::endl; - //test constructor - moDummyNeighbor test1, test2; + //test constructor + moDummyNeighbor test1, test2; - test1.fitness(3); - //test operateur d'affectation - test2=test1; - assert(test1.fitness()==test2.fitness()); + test1.fitness(3); + //test operateur d'affectation + test2=test1; + assert(test1.fitness()==test2.fitness()); - //test operateur de copy - moDummyNeighbor test3(test1); - assert(test1.fitness()==test3.fitness()); + //test operateur de copy + moDummyNeighbor test3(test1); + assert(test1.fitness()==test3.fitness()); - test1.printOn(std::cout); - test2.printOn(std::cout); - test3.printOn(std::cout); + test1.printOn(std::cout); + test2.printOn(std::cout); + test3.printOn(std::cout); - assert(test1.className()=="moNeighbor"); - std::cout << "[t-moNeighbor] => OK" << std::endl; + assert(test1.className()=="moNeighbor"); + std::cout << "[t-moNeighbor] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moNeighborComparator.cpp b/trunk/paradiseo-mo/test/t-moNeighborComparator.cpp index 2f305e597..681d13e25 100644 --- a/trunk/paradiseo-mo/test/t-moNeighborComparator.cpp +++ b/trunk/paradiseo-mo/test/t-moNeighborComparator.cpp @@ -40,29 +40,29 @@ #include #include -int main(){ +int main() { - std::cout << "[t-moNeighborComparator] => START" << std::endl; + std::cout << "[t-moNeighborComparator] => START" << std::endl; - moBitNeighbor neighbor1; - moBitNeighbor neighbor2; + moBitNeighbor neighbor1; + moBitNeighbor neighbor2; - moNeighborComparator< moBitNeighbor > test; + moNeighborComparator< moBitNeighbor > test; - neighbor1.fitness(3); - neighbor2.fitness(2); - //test with a minimizing fitness neighbor2 must be better than neighbor1 and reversly - assert(test(neighbor1, neighbor2)); - assert(!test(neighbor2, neighbor1)); + neighbor1.fitness(3); + neighbor2.fitness(2); + //test with a minimizing fitness neighbor2 must be better than neighbor1 and reversly + assert(test(neighbor1, neighbor2)); + assert(!test(neighbor2, neighbor1)); - //test equals - assert(!test.equals(neighbor1,neighbor2)); + //test equals + assert(!test.equals(neighbor1,neighbor2)); - neighbor2.fitness(3); - assert(test.equals(neighbor1,neighbor2)); + neighbor2.fitness(3); + assert(test.equals(neighbor1,neighbor2)); - assert(test.className()=="moNeighborComparator"); - std::cout << "[t-moNeighborComparator] => OK" << std::endl; - return EXIT_SUCCESS; + assert(test.className()=="moNeighborComparator"); + std::cout << "[t-moNeighborComparator] => OK" << std::endl; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moNeighborhoodStat.cpp b/trunk/paradiseo-mo/test/t-moNeighborhoodStat.cpp index 1d15665ae..b18262a14 100644 --- a/trunk/paradiseo-mo/test/t-moNeighborhoodStat.cpp +++ b/trunk/paradiseo-mo/test/t-moNeighborhoodStat.cpp @@ -46,107 +46,107 @@ Contact: paradiseo-help@lists.gforge.inria.fr /* * Tests all classes depending of moNeighborhoodStat.h */ -int main(){ +int main() { - //test de moNeighborhoodStat.h - std::cout << "[t-moNeighborhoodStat] => START" << std::endl; + //test de moNeighborhoodStat.h + std::cout << "[t-moNeighborhoodStat] => START" << std::endl; - moNeighborComparator neighborComp; - moSolNeighborComparator solNeighborComp; - evalOneMax eval(10); + moNeighborComparator neighborComp; + moSolNeighborComparator solNeighborComp; + evalOneMax eval(10); - bitNeighborhood n(10); + bitNeighborhood n(10); - bitVector sol; + bitVector sol; - sol.push_back(true); - sol.push_back(false); - sol.push_back(true); - sol.push_back(true); - sol.push_back(false); - sol.push_back(true); - sol.push_back(false); - sol.push_back(true); - sol.push_back(true); - sol.push_back(true); + sol.push_back(true); + sol.push_back(false); + sol.push_back(true); + sol.push_back(true); + sol.push_back(false); + sol.push_back(true); + sol.push_back(false); + sol.push_back(true); + sol.push_back(true); + sol.push_back(true); - sol.fitness(7); + sol.fitness(7); - moNeighborhoodStat test(n, eval, neighborComp, solNeighborComp); + moNeighborhoodStat test(n, eval, neighborComp, solNeighborComp); - test(sol); + test(sol); - assert(test.getMin()==8); - assert(test.getMax()==6); - assert(test.getMean()==6.6); - double sd=test.getSD(); - assert(test.getSD()>0.966 && test.getSD()<0.967); - assert(test.getSize()==10); - assert(test.getNbSup()==7); - assert(test.getNbInf()==3); - assert(test.getNbEqual()==0); + assert(test.getMin()==8); + assert(test.getMax()==6); + assert(test.getMean()==6.6); + double sd=test.getSD(); + assert(sd>0.966 && sd<0.967); + assert(test.getSize()==10); + assert(test.getNbSup()==7); + assert(test.getNbInf()==3); + assert(test.getNbEqual()==0); - assert(test.className()=="moNeighborhoodStat"); - std::cout << "[t-moNeighborhoodStat] => OK" << std::endl; + assert(test.className()=="moNeighborhoodStat"); + std::cout << "[t-moNeighborhoodStat] => OK" << std::endl; - //test of moMaxNeighborStat.h - std::cout << "[t-moMaxNeighborStat] => START" << std::endl; - moMaxNeighborStat test2(test); - test2(sol); - assert(test2.value()==6); - assert(test2.className()=="moMaxNeighborStat"); - std::cout << "[t-moMaxNeighborStat] => OK" << std::endl; + //test of moMaxNeighborStat.h + std::cout << "[t-moMaxNeighborStat] => START" << std::endl; + moMaxNeighborStat test2(test); + test2(sol); + assert(test2.value()==6); + assert(test2.className()=="moMaxNeighborStat"); + std::cout << "[t-moMaxNeighborStat] => OK" << std::endl; - //test of moMinNeighborStat.h - std::cout << "[t-moMinNeighborStat] => START" << std::endl; - moMinNeighborStat test3(test); - test3(sol); - assert(test3.value()==8); - assert(test3.className()=="moMinNeighborStat"); - std::cout << "[t-moMinNeighborStat] => OK" << std::endl; + //test of moMinNeighborStat.h + std::cout << "[t-moMinNeighborStat] => START" << std::endl; + moMinNeighborStat test3(test); + test3(sol); + assert(test3.value()==8); + assert(test3.className()=="moMinNeighborStat"); + std::cout << "[t-moMinNeighborStat] => OK" << std::endl; - //test of moNbInfNeighborStat.h - std::cout << "[t-moNbInfNeighborStat] => START" << std::endl; - moNbInfNeighborStat test4(test); - test4(sol); - assert(test4.value()==3); - assert(test4.className()=="moNbInfNeighborStat"); - std::cout << "[t-moNbInfNeighborStat] => OK" << std::endl; + //test of moNbInfNeighborStat.h + std::cout << "[t-moNbInfNeighborStat] => START" << std::endl; + moNbInfNeighborStat test4(test); + test4(sol); + assert(test4.value()==3); + assert(test4.className()=="moNbInfNeighborStat"); + std::cout << "[t-moNbInfNeighborStat] => OK" << std::endl; - //test of moNbSupNeighborStat.h - std::cout << "[t-moNbSupNeighborStat] => START" << std::endl; - moNbSupNeighborStat test5(test); - test5(sol); - assert(test5.value()==7); - assert(test5.className()=="moNbSupNeighborStat"); - std::cout << "[t-moNbSupNeighborStat] => OK" << std::endl; + //test of moNbSupNeighborStat.h + std::cout << "[t-moNbSupNeighborStat] => START" << std::endl; + moNbSupNeighborStat test5(test); + test5(sol); + assert(test5.value()==7); + assert(test5.className()=="moNbSupNeighborStat"); + std::cout << "[t-moNbSupNeighborStat] => OK" << std::endl; - //test of moNeutralDegreeNeighborStat.h - std::cout << "[t-moNeutralDegreeNeighborStat] => START" << std::endl; - moNeutralDegreeNeighborStat test6(test); - test6(sol); - assert(test6.value()==0); - assert(test6.className()=="moNeutralDegreeNeighborStat"); - std::cout << "[t-moNeutralDegreeNeighborStat] => OK" << std::endl; + //test of moNeutralDegreeNeighborStat.h + std::cout << "[t-moNeutralDegreeNeighborStat] => START" << std::endl; + moNeutralDegreeNeighborStat test6(test); + test6(sol); + assert(test6.value()==0); + assert(test6.className()=="moNeutralDegreeNeighborStat"); + std::cout << "[t-moNeutralDegreeNeighborStat] => OK" << std::endl; - //test of moSecondMomentNeighborStat.h - std::cout << "[t-moSecondMomentNeighborStat] => START" << std::endl; - moSecondMomentNeighborStat test7(test); - test7(sol); - assert(test7.value().first==6.6); - assert(test7.value().second > 0.966 && test7.value().second < 0.967); - assert(test7.className()=="moSecondMomentNeighborStat"); - std::cout << "[t-moSecondMomentNeighborStat] => OK" << std::endl; + //test of moSecondMomentNeighborStat.h + std::cout << "[t-moSecondMomentNeighborStat] => START" << std::endl; + moSecondMomentNeighborStat test7(test); + test7(sol); + assert(test7.value().first==6.6); + assert(test7.value().second > 0.966 && test7.value().second < 0.967); + assert(test7.className()=="moSecondMomentNeighborStat"); + std::cout << "[t-moSecondMomentNeighborStat] => OK" << std::endl; - //test of moSizeNeighborStat.h - std::cout << "[t-moSizeNeighborStat] => START" << std::endl; - moSizeNeighborStat test8(test); - test8(sol); - assert(test8.value()==10); - assert(test8.className()=="moSizeNeighborStat"); - std::cout << "[t-moSizeNeighborStat] => OK" << std::endl; + //test of moSizeNeighborStat.h + std::cout << "[t-moSizeNeighborStat] => START" << std::endl; + moSizeNeighborStat test8(test); + test8(sol); + assert(test8.value()==10); + assert(test8.className()=="moSizeNeighborStat"); + std::cout << "[t-moSizeNeighborStat] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moOrderNeighborhood.cpp b/trunk/paradiseo-mo/test/t-moOrderNeighborhood.cpp index 1b07436dd..43f948a04 100644 --- a/trunk/paradiseo-mo/test/t-moOrderNeighborhood.cpp +++ b/trunk/paradiseo-mo/test/t-moOrderNeighborhood.cpp @@ -39,42 +39,42 @@ #include #include -int main(){ +int main() { - std::cout << "[t-moOrderNeighborhood] => START" << std::endl; + std::cout << "[t-moOrderNeighborhood] => START" << std::endl; - //init sol - eoBit sol; - sol.push_back(true); - sol.push_back(false); - sol.push_back(true); + //init sol + eoBit sol; + sol.push_back(true); + sol.push_back(false); + sol.push_back(true); - moBitNeighbor neighbor; + moBitNeighbor neighbor; - //verif du constructeur vide - moOrderNeighborhood > test(3); - assert(test.position()==0); + //verif du constructeur vide + moOrderNeighborhood > test(3); + assert(test.position()==0); - //verif du hasneighbor - assert(test.hasNeighbor(sol)); + //verif du hasneighbor + assert(test.hasNeighbor(sol)); - //verif de init - test.init(sol, neighbor); - assert(neighbor.index()==0); - assert(test.position()==0); + //verif de init + test.init(sol, neighbor); + assert(neighbor.index()==0); + assert(test.position()==0); - //verif du next - test.next(sol, neighbor); - assert(neighbor.index()==1); - assert(test.position()==1); + //verif du next + test.next(sol, neighbor); + assert(neighbor.index()==1); + assert(test.position()==1); - //verif du cont - assert(test.cont(sol)); - test.next(sol, neighbor); - assert(!test.cont(sol)); + //verif du cont + assert(test.cont(sol)); + test.next(sol, neighbor); + assert(!test.cont(sol)); - assert(test.className()=="moOrderNeighborhood"); + assert(test.className()=="moOrderNeighborhood"); - std::cout << "[t-moOrderNeighborhood] => OK" << std::endl; - return EXIT_SUCCESS; + std::cout << "[t-moOrderNeighborhood] => OK" << std::endl; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moRandomNeutralWalkExplorer.cpp b/trunk/paradiseo-mo/test/t-moRandomNeutralWalkExplorer.cpp index 483525b1e..c8af982de 100644 --- a/trunk/paradiseo-mo/test/t-moRandomNeutralWalkExplorer.cpp +++ b/trunk/paradiseo-mo/test/t-moRandomNeutralWalkExplorer.cpp @@ -34,55 +34,55 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moRandomNeutralWalkExplorer] => START" << std::endl; + std::cout << "[t-moRandomNeutralWalkExplorer] => START" << std::endl; - eoBit sol(4, true); - sol.fitness(4); - bitNeighborhood nh(4); - evalOneMax eval(4); - dummyEvalOneMax eval2(4); - moSolNeighborComparator sncomp; + eoBit sol(4, true); + sol.fitness(4); + bitNeighborhood nh(4); + evalOneMax eval(4); + dummyEvalOneMax eval2(4); + moSolNeighborComparator sncomp; - //test avec la fonction d'eval classique - //on verifie qu'on ne trouve pas de voisin de mm fitness - moRandomNeutralWalkExplorer test(nh, eval, sncomp, 3); + //test avec la fonction d'eval classique + //on verifie qu'on ne trouve pas de voisin de mm fitness + moRandomNeutralWalkExplorer test(nh, eval, sncomp, 3); - test.initParam(sol); - test(sol); - assert(!test.accept(sol)); - assert(!test.isContinue(sol)); + test.initParam(sol); + test(sol); + assert(!test.accept(sol)); + assert(!test.isContinue(sol)); - //test avec une fonction d'eval bidon qui renvoie toujours la mm fitness - //on peut donc verifier qu'on s'arette au bout des 3 itérations. - moRandomNeutralWalkExplorer test2(nh, eval2, sncomp, 3); + //test avec une fonction d'eval bidon qui renvoie toujours la mm fitness + //on peut donc verifier qu'on s'arette au bout des 3 itérations. + moRandomNeutralWalkExplorer test2(nh, eval2, sncomp, 3); - sol.fitness(2); - test2.initParam(sol); - test2(sol); - assert(test2.accept(sol)); - test2.move(sol); - assert(sol.fitness()==2); - test2.updateParam(sol); - assert(test2.isContinue(sol)); + sol.fitness(2); + test2.initParam(sol); + test2(sol); + assert(test2.accept(sol)); + test2.move(sol); + assert(sol.fitness()==2); + test2.updateParam(sol); + assert(test2.isContinue(sol)); - test2(sol); - assert(test2.accept(sol)); - test2.move(sol); - assert(sol.fitness()==2); - test2.updateParam(sol); - assert(test2.isContinue(sol)); + test2(sol); + assert(test2.accept(sol)); + test2.move(sol); + assert(sol.fitness()==2); + test2.updateParam(sol); + assert(test2.isContinue(sol)); - test2(sol); - assert(test2.accept(sol)); - test2.move(sol); - assert(sol.fitness()==2); - test2.updateParam(sol); - assert(!test2.isContinue(sol)); + test2(sol); + assert(test2.accept(sol)); + test2.move(sol); + assert(sol.fitness()==2); + test2.updateParam(sol); + assert(!test2.isContinue(sol)); - std::cout << "[t-moRandomNeutralWalkExplorer] => OK" << std::endl; + std::cout << "[t-moRandomNeutralWalkExplorer] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moRandomWalkExplorer.cpp b/trunk/paradiseo-mo/test/t-moRandomWalkExplorer.cpp index 460988d2b..880e4ebd1 100644 --- a/trunk/paradiseo-mo/test/t-moRandomWalkExplorer.cpp +++ b/trunk/paradiseo-mo/test/t-moRandomWalkExplorer.cpp @@ -34,46 +34,46 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moRandomWalkExplorer] => START" << std::endl; + std::cout << "[t-moRandomWalkExplorer] => START" << std::endl; - eoBit sol(4, true); - sol.fitness(4); - bitNeighborhood nh(4); - evalOneMax eval(4); + eoBit sol(4, true); + sol.fitness(4); + bitNeighborhood nh(4); + evalOneMax eval(4); - //test avec un neighbordhood ordonné - //Du coup on verifie juste qu'on a bien une evolution de la solution et qu'on fait 3 pas avant d'arreter l'exploration - moRandomWalkExplorer test(nh, eval, 3); + //test avec un neighbordhood ordonné + //Du coup on verifie juste qu'on a bien une evolution de la solution et qu'on fait 3 pas avant d'arreter l'exploration + moRandomWalkExplorer test(nh, eval, 3); - test.initParam(sol); + test.initParam(sol); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==3); - test.updateParam(sol); - assert(test.isContinue(sol)); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==3); + test.updateParam(sol); + assert(test.isContinue(sol)); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==4); - test.updateParam(sol); - assert(test.isContinue(sol)); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==4); + test.updateParam(sol); + assert(test.isContinue(sol)); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==3); - assert(!sol[0]); - test.updateParam(sol); - assert(!test.isContinue(sol)); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==3); + assert(!sol[0]); + test.updateParam(sol); + assert(!test.isContinue(sol)); - std::cout << "[t-moRandomWalkExplorer] => OK" << std::endl; + std::cout << "[t-moRandomWalkExplorer] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moRndWithReplNeighborhood.cpp b/trunk/paradiseo-mo/test/t-moRndWithReplNeighborhood.cpp index 110b4e824..4e8d0b874 100644 --- a/trunk/paradiseo-mo/test/t-moRndWithReplNeighborhood.cpp +++ b/trunk/paradiseo-mo/test/t-moRndWithReplNeighborhood.cpp @@ -35,41 +35,41 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moRndWithReplNeighborhood] => START" << std::endl; + std::cout << "[t-moRndWithReplNeighborhood] => START" << std::endl; - unsigned int a, b; - eoBit sol; - moBitNeighbor n; + unsigned int a, b; + eoBit sol; + moBitNeighbor n; - moRndWithReplNeighborhood< moBitNeighbor > test(3); - moRndWithReplNeighborhood< moBitNeighbor > test2(0); + moRndWithReplNeighborhood< moBitNeighbor > test(3); + moRndWithReplNeighborhood< moBitNeighbor > test2(0); - assert(test.hasNeighbor(sol)); - assert(!test2.hasNeighbor(sol)); + assert(test.hasNeighbor(sol)); + assert(!test2.hasNeighbor(sol)); - test.init(sol,n); + test.init(sol,n); - //on s'assure qu'on a bien toujours bien l'index 0, 1 ou 2 qui est renvoyé - for(unsigned int i=0; i<100; i++){ + //on s'assure qu'on a bien toujours bien l'index 0, 1 ou 2 qui est renvoyé + for (unsigned int i=0; i<100; i++) { - a=n.index(); - test.next(sol,n); - b=n.index(); + a=n.index(); + test.next(sol,n); + b=n.index(); - assert(a==0 || a==1 || a==2); - assert(b==0 || b==1 || b==2); - assert(test.cont(sol)); - assert(!test2.cont(sol)); - assert(test.cont(sol)); + assert(a==0 || a==1 || a==2); + assert(b==0 || b==1 || b==2); + assert(test.cont(sol)); + assert(!test2.cont(sol)); + assert(test.cont(sol)); - } + } - assert(test.className()=="moRndWithReplNeighborhood"); + assert(test.className()=="moRndWithReplNeighborhood"); - std::cout << "[t-moRndWithReplNeighborhood] => OK" << std::endl; + std::cout << "[t-moRndWithReplNeighborhood] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moRndWithoutReplNeighborhood.cpp b/trunk/paradiseo-mo/test/t-moRndWithoutReplNeighborhood.cpp index c8ed7e426..cce451053 100644 --- a/trunk/paradiseo-mo/test/t-moRndWithoutReplNeighborhood.cpp +++ b/trunk/paradiseo-mo/test/t-moRndWithoutReplNeighborhood.cpp @@ -35,42 +35,42 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moRndWithoutReplNeighborhood] => START" << std::endl; + std::cout << "[t-moRndWithoutReplNeighborhood] => START" << std::endl; - unsigned int a, b, c; - eoBit sol; - moBitNeighbor n; + unsigned int a, b, c; + eoBit sol; + moBitNeighbor n; - //instanciation - moRndWithoutReplNeighborhood< moBitNeighbor > test(3); - moRndWithoutReplNeighborhood< moBitNeighbor > test2(0); + //instanciation + moRndWithoutReplNeighborhood< moBitNeighbor > test(3); + moRndWithoutReplNeighborhood< moBitNeighbor > test2(0); - //on verifie que test a bien des voisins et que test2 n'en a pas - assert(test.hasNeighbor(sol)); - assert(!test2.hasNeighbor(sol)); + //on verifie que test a bien des voisins et que test2 n'en a pas + assert(test.hasNeighbor(sol)); + assert(!test2.hasNeighbor(sol)); - //on recupere successivement les index - test.init(sol, n); - assert(test.cont(sol)); - a=test.position(); - test.next(sol, n); - assert(test.cont(sol)); - b=test.position(); - test.next(sol,n); - assert(!test.cont(sol)); - c=test.position(); + //on recupere successivement les index + test.init(sol, n); + assert(test.cont(sol)); + a=test.position(); + test.next(sol, n); + assert(test.cont(sol)); + b=test.position(); + test.next(sol,n); + assert(!test.cont(sol)); + c=test.position(); - //on s'assure qu'on a bien 0, 1 et 2 (dans un ordre aléatoire) - assert(a==0 || b==0 || c==0); - assert(a==1 || b==1 || c==1); - assert(a==2 || b==2 || c==2); + //on s'assure qu'on a bien 0, 1 et 2 (dans un ordre aléatoire) + assert(a==0 || b==0 || c==0); + assert(a==1 || b==1 || c==1); + assert(a==2 || b==2 || c==2); - assert(test.className()=="moRndWithoutReplNeighborhood"); + assert(test.className()=="moRndWithoutReplNeighborhood"); - std::cout << "[t-moRndWithoutReplNeighborhood] => OK" << std::endl; + std::cout << "[t-moRndWithoutReplNeighborhood] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moSimpleHCexplorer.cpp b/trunk/paradiseo-mo/test/t-moSimpleHCexplorer.cpp index 90c7a66fe..3fdeed63f 100644 --- a/trunk/paradiseo-mo/test/t-moSimpleHCexplorer.cpp +++ b/trunk/paradiseo-mo/test/t-moSimpleHCexplorer.cpp @@ -41,52 +41,52 @@ #include #include -int main(){ +int main() { - //Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval + //Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval - std::cout << "[t-moSimpleHCexplorer] => START" << std::endl; + std::cout << "[t-moSimpleHCexplorer] => START" << std::endl; - Solution sol; - moDummyNeighbor neighbor; - moDummyEval eval; - moDummyNeighborhood nh; - moFullEvalByCopy fulleval(eval); - moNeighborComparator comp; - moSolNeighborComparator solNeighborComp; + Solution sol; + moDummyNeighbor neighbor; + moDummyEval eval; + moDummyNeighborhood nh; + moFullEvalByCopy fulleval(eval); + moNeighborComparator comp; + moSolNeighborComparator solNeighborComp; - //verif constructor - moSimpleHCexplorer test(nh, fulleval, comp, solNeighborComp); + //verif constructor + moSimpleHCexplorer test(nh, fulleval, comp, solNeighborComp); - //verif operator() et accept: le neigorhood est construit pour qu'on tombe dans les 3 cas suivants: - //hasNeighbor() retourne faux a l'entrée de l'operator() donc on doit pas continuer - sol.fitness(3); - test(sol); - test.accept(sol); - assert(!test.isContinue(sol)); + //verif operator() et accept: le neigorhood est construit pour qu'on tombe dans les 3 cas suivants: + //hasNeighbor() retourne faux a l'entrée de l'operator() donc on doit pas continuer + sol.fitness(3); + test(sol); + test.accept(sol); + assert(!test.isContinue(sol)); - //hasNeighbor() retourne faux a l'entrée de accept() donc on doit pas continuer - test(sol); - test.accept(sol); - assert(!test.isContinue(sol)); + //hasNeighbor() retourne faux a l'entrée de accept() donc on doit pas continuer + test(sol); + test.accept(sol); + assert(!test.isContinue(sol)); - //hasNeighbor() retourne vrai et on ameliore la fitness donc on doit continuer - test(sol); - test.accept(sol); - assert(test.isContinue(sol)); + //hasNeighbor() retourne vrai et on ameliore la fitness donc on doit continuer + test(sol); + test.accept(sol); + assert(test.isContinue(sol)); - //verif de move -> on affecte la fitness du best d'avant - test.move(sol); + //verif de move -> on affecte la fitness du best d'avant + test.move(sol); - //hasNeighbor() retourne vrai et on ameliore pas la fitness donc on doit pas continuer - test(sol); - test(sol); - test.accept(sol); - assert(!test.isContinue(sol)); + //hasNeighbor() retourne vrai et on ameliore pas la fitness donc on doit pas continuer + test(sol); + test(sol); + test.accept(sol); + assert(!test.isContinue(sol)); - assert(test.className()=="moSimpleHCexplorer"); + assert(test.className()=="moSimpleHCexplorer"); - std::cout << "[t-moSimpleHCexplorer] => OK" << std::endl; + std::cout << "[t-moSimpleHCexplorer] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moSimpleHCneutralExplorer.cpp b/trunk/paradiseo-mo/test/t-moSimpleHCneutralExplorer.cpp index 7d32c5a0d..5ee7737fc 100644 --- a/trunk/paradiseo-mo/test/t-moSimpleHCneutralExplorer.cpp +++ b/trunk/paradiseo-mo/test/t-moSimpleHCneutralExplorer.cpp @@ -36,66 +36,66 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moSimpleHCneutralExplorer] => START" << std::endl; + std::cout << "[t-moSimpleHCneutralExplorer] => START" << std::endl; - //instanciation - eoBit sol(4, true); - sol.fitness(4); - bitNeighborhood nh(4); - evalOneMax eval(4); - moNeighborComparator ncomp; - moSolNeighborComparator sncomp; + //instanciation + eoBit sol(4, true); + sol.fitness(4); + bitNeighborhood nh(4); + evalOneMax eval(4); + moNeighborComparator ncomp; + moSolNeighborComparator sncomp; - moSimpleHCneutralExplorer test(nh, eval, ncomp, sncomp); + moSimpleHCneutralExplorer test(nh, eval, ncomp, sncomp); - //test qu'on ameliore bien a chaque itération - test.initParam(sol); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==3); - assert(test.isContinue(sol)); - test.updateParam(sol); + //test qu'on ameliore bien a chaque itération + test.initParam(sol); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==3); + assert(test.isContinue(sol)); + test.updateParam(sol); - //les affichages permettent de voir qu'on choisit pas toujours les mm voisins améliorant (lancer plusieurs fois l'exe) - std::cout << sol << std::endl; + //les affichages permettent de voir qu'on choisit pas toujours les mm voisins améliorant (lancer plusieurs fois l'exe) + std::cout << sol << std::endl; - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==2); - assert(test.isContinue(sol)); - test.updateParam(sol); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==2); + assert(test.isContinue(sol)); + test.updateParam(sol); - std::cout << sol << std::endl; + std::cout << sol << std::endl; - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==1); - assert(test.isContinue(sol)); - test.updateParam(sol); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==1); + assert(test.isContinue(sol)); + test.updateParam(sol); - std::cout << sol << std::endl; + std::cout << sol << std::endl; - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==0); - assert(test.isContinue(sol)); - test.updateParam(sol); + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==0); + assert(test.isContinue(sol)); + test.updateParam(sol); - test(sol); - assert(!test.accept(sol)); - assert(sol.fitness()==0); - assert(!test.isContinue(sol)); - test.updateParam(sol); + test(sol); + assert(!test.accept(sol)); + assert(sol.fitness()==0); + assert(!test.isContinue(sol)); + test.updateParam(sol); - std::cout << "[t-moSimpleHCneutralExplorer] => OK" << std::endl; + std::cout << "[t-moSimpleHCneutralExplorer] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moSolNeighborComparator.cpp b/trunk/paradiseo-mo/test/t-moSolNeighborComparator.cpp index f3b735b99..2b5df96f0 100644 --- a/trunk/paradiseo-mo/test/t-moSolNeighborComparator.cpp +++ b/trunk/paradiseo-mo/test/t-moSolNeighborComparator.cpp @@ -40,33 +40,33 @@ #include #include -int main(){ +int main() { - std::cout << "[t-moSolNeighborComparator] => START" << std::endl; + std::cout << "[t-moSolNeighborComparator] => START" << std::endl; - moBitNeighbor neighbor; - eoBit sol; + moBitNeighbor neighbor; + eoBit sol; - moSolNeighborComparator< moBitNeighbor > test; + moSolNeighborComparator< moBitNeighbor > test; - neighbor.fitness(3); - sol.fitness(2); - //test with a minimizing fitness, neighbor must not be better than sol - assert(!test(sol, neighbor)); + neighbor.fitness(3); + sol.fitness(2); + //test with a minimizing fitness, neighbor must not be better than sol + assert(!test(sol, neighbor)); - //reversly - neighbor.fitness(2); - sol.fitness(3); - assert(test(sol, neighbor)); + //reversly + neighbor.fitness(2); + sol.fitness(3); + assert(test(sol, neighbor)); - //test equals - assert(!test.equals(sol, neighbor)); + //test equals + assert(!test.equals(sol, neighbor)); - neighbor.fitness(3); - assert(test.equals(sol, neighbor)); + neighbor.fitness(3); + assert(test.equals(sol, neighbor)); - assert(test.className()=="moSolNeighborComparator"); + assert(test.className()=="moSolNeighborComparator"); - std::cout << "[t-moSolNeighborComparator] => OK" << std::endl; - return EXIT_SUCCESS; + std::cout << "[t-moSolNeighborComparator] => OK" << std::endl; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moSolVectorTabuList.cpp b/trunk/paradiseo-mo/test/t-moSolVectorTabuList.cpp index 7f792b40a..cf883d369 100644 --- a/trunk/paradiseo-mo/test/t-moSolVectorTabuList.cpp +++ b/trunk/paradiseo-mo/test/t-moSolVectorTabuList.cpp @@ -34,121 +34,121 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moSolVectorTabuList] => START" << std::endl; + std::cout << "[t-moSolVectorTabuList] => START" << std::endl; - //test without countdown - moSolVectorTabuList test(2,0); - bitNeighbor n1; - bitNeighbor n2; - bitNeighbor n3; - bitNeighbor n4; - n1.index(0); - n2.index(1); - n3.index(2); - n4.index(3); + //test without countdown + moSolVectorTabuList test(2,0); + bitNeighbor n1; + bitNeighbor n2; + bitNeighbor n3; + bitNeighbor n4; + n1.index(0); + n2.index(1); + n3.index(2); + n4.index(3); - eoBit sol1(4, true); - eoBit sol2(4, true); - eoBit sol3(4, true); - eoBit sol4(4, true); + eoBit sol1(4, true); + eoBit sol2(4, true); + eoBit sol3(4, true); + eoBit sol4(4, true); - sol2[0]=false; - sol3[1]=false; - sol4[0]=false; - sol4[1]=false; + sol2[0]=false; + sol3[1]=false; + sol4[0]=false; + sol4[1]=false; - //init - test.init(sol1); + //init + test.init(sol1); - //ajout d'une sol tabu - test.add(sol1,n1); + //ajout d'une sol tabu + test.add(sol1,n1); - //verification des voisins de chaques sol - assert(test.check(sol2,n1)); - assert(!test.check(sol2,n2)); - assert(!test.check(sol2,n3)); - assert(!test.check(sol2,n4)); + //verification des voisins de chaques sol + assert(test.check(sol2,n1)); + assert(!test.check(sol2,n2)); + assert(!test.check(sol2,n3)); + assert(!test.check(sol2,n4)); - assert(!test.check(sol3,n1)); - assert(test.check(sol3,n2)); - assert(!test.check(sol3,n3)); - assert(!test.check(sol3,n4)); + assert(!test.check(sol3,n1)); + assert(test.check(sol3,n2)); + assert(!test.check(sol3,n3)); + assert(!test.check(sol3,n4)); - assert(!test.check(sol4,n1)); - assert(!test.check(sol4,n2)); - assert(!test.check(sol4,n3)); - assert(!test.check(sol4,n4)); + assert(!test.check(sol4,n1)); + assert(!test.check(sol4,n2)); + assert(!test.check(sol4,n3)); + assert(!test.check(sol4,n4)); - test.init(sol1); - assert(!test.check(sol2,n1)); - assert(!test.check(sol3,n2)); + test.init(sol1); + assert(!test.check(sol2,n1)); + assert(!test.check(sol3,n2)); - test.update(sol1,n1); + test.update(sol1,n1); - test.add(sol1,n1); - test.add(sol2,n1); - assert(test.check(sol2,n1)); - test.add(sol4,n1); - assert(!test.check(sol2,n1)); - assert(test.check(sol2,n2)); + test.add(sol1,n1); + test.add(sol2,n1); + assert(test.check(sol2,n1)); + test.add(sol4,n1); + assert(!test.check(sol2,n1)); + assert(test.check(sol2,n2)); - //test with a countdown at 3 - moSolVectorTabuList test2(2,2); - test2.init(sol1); - test2.add(sol1,n1); - assert(test2.check(sol2,n1)); - assert(!test2.check(sol2,n2)); - assert(!test2.check(sol2,n3)); - assert(!test2.check(sol2,n4)); + //test with a countdown at 3 + moSolVectorTabuList test2(2,2); + test2.init(sol1); + test2.add(sol1,n1); + assert(test2.check(sol2,n1)); + assert(!test2.check(sol2,n2)); + assert(!test2.check(sol2,n3)); + assert(!test2.check(sol2,n4)); - assert(!test2.check(sol3,n1)); - assert(test2.check(sol3,n2)); - assert(!test2.check(sol3,n3)); - assert(!test2.check(sol3,n4)); + assert(!test2.check(sol3,n1)); + assert(test2.check(sol3,n2)); + assert(!test2.check(sol3,n3)); + assert(!test2.check(sol3,n4)); - assert(!test2.check(sol4,n1)); - assert(!test2.check(sol4,n2)); - assert(!test2.check(sol4,n3)); - assert(!test2.check(sol4,n4)); + assert(!test2.check(sol4,n1)); + assert(!test2.check(sol4,n2)); + assert(!test2.check(sol4,n3)); + assert(!test2.check(sol4,n4)); - //coutdown sol1 -> 1 - test2.update(sol1,n1); - assert(test2.check(sol2,n1)); - assert(!test2.check(sol2,n2)); - assert(!test2.check(sol2,n3)); - assert(!test2.check(sol2,n4)); + //coutdown sol1 -> 1 + test2.update(sol1,n1); + assert(test2.check(sol2,n1)); + assert(!test2.check(sol2,n2)); + assert(!test2.check(sol2,n3)); + assert(!test2.check(sol2,n4)); - assert(!test2.check(sol3,n1)); - assert(test2.check(sol3,n2)); - assert(!test2.check(sol3,n3)); - assert(!test2.check(sol3,n4)); + assert(!test2.check(sol3,n1)); + assert(test2.check(sol3,n2)); + assert(!test2.check(sol3,n3)); + assert(!test2.check(sol3,n4)); - assert(!test2.check(sol4,n1)); - assert(!test2.check(sol4,n2)); - assert(!test2.check(sol4,n3)); - assert(!test2.check(sol4,n4)); + assert(!test2.check(sol4,n1)); + assert(!test2.check(sol4,n2)); + assert(!test2.check(sol4,n3)); + assert(!test2.check(sol4,n4)); - //coutdown sol1 -> 0 : sol1 is no longer tabu - test2.update(sol1,n1); - assert(!test2.check(sol2,n1)); - assert(!test2.check(sol2,n2)); - assert(!test2.check(sol2,n3)); - assert(!test2.check(sol2,n4)); + //coutdown sol1 -> 0 : sol1 is no longer tabu + test2.update(sol1,n1); + assert(!test2.check(sol2,n1)); + assert(!test2.check(sol2,n2)); + assert(!test2.check(sol2,n3)); + assert(!test2.check(sol2,n4)); - assert(!test2.check(sol3,n1)); - assert(!test2.check(sol3,n2)); - assert(!test2.check(sol3,n3)); - assert(!test2.check(sol3,n4)); + assert(!test2.check(sol3,n1)); + assert(!test2.check(sol3,n2)); + assert(!test2.check(sol3,n3)); + assert(!test2.check(sol3,n4)); - assert(!test2.check(sol4,n1)); - assert(!test2.check(sol4,n2)); - assert(!test2.check(sol4,n3)); - assert(!test2.check(sol4,n4)); + assert(!test2.check(sol4,n1)); + assert(!test2.check(sol4,n2)); + assert(!test2.check(sol4,n3)); + assert(!test2.check(sol4,n4)); - std::cout << "[t-moSolVectorTabuList] => OK" << std::endl; + std::cout << "[t-moSolVectorTabuList] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moSolutionStat.cpp b/trunk/paradiseo-mo/test/t-moSolutionStat.cpp index c17c67fe2..2ebe777da 100644 --- a/trunk/paradiseo-mo/test/t-moSolutionStat.cpp +++ b/trunk/paradiseo-mo/test/t-moSolutionStat.cpp @@ -34,31 +34,31 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moSolutionStat] => START" << std::endl; + std::cout << "[t-moSolutionStat] => START" << std::endl; - eoBit s(3); - s[0]=true; - s[1]=true; - s[2]=false; + eoBit s(3); + s[0]=true; + s[1]=true; + s[2]=false; - s.fitness(17); + s.fitness(17); - moSolutionStat< eoBit > test; + moSolutionStat< eoBit > test; - test(s); - //on verifie que la solution est bien enregistré + test(s); + //on verifie que la solution est bien enregistré - assert(test.value()[0]); - assert(test.value()[1]); - assert(!test.value()[2]); - assert(test.value().fitness()==17); + assert(test.value()[0]); + assert(test.value()[1]); + assert(!test.value()[2]); + assert(test.value().fitness()==17); - assert(test.className()=="moSolutionStat"); + assert(test.className()=="moSolutionStat"); - std::cout << "[t-moSolutionStat] => OK" << std::endl; + std::cout << "[t-moSolutionStat] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moTSExplorer.cpp b/trunk/paradiseo-mo/test/t-moTSExplorer.cpp index ba72bdbd1..a591fc22e 100644 --- a/trunk/paradiseo-mo/test/t-moTSExplorer.cpp +++ b/trunk/paradiseo-mo/test/t-moTSExplorer.cpp @@ -38,128 +38,128 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -int main(){ +int main() { - std::cout << "[t-moTSExplorer] => START" << std::endl; + std::cout << "[t-moTSExplorer] => START" << std::endl; - //instansiation - eoBit sol(4, true); - sol.fitness(4); - bitNeighborhood nh(4); - bitNeighborhood emptyNH(0); - evalOneMax eval(4); - moNeighborComparator ncomp; - moSolNeighborComparator sncomp; - moDummyIntensification intens; - moDummyDiversification diver; - moSolVectorTabuList tabuList(4,0); - moBestImprAspiration aspir; + //instansiation + eoBit sol(4, true); + sol.fitness(4); + bitNeighborhood nh(4); + bitNeighborhood emptyNH(0); + evalOneMax eval(4); + moNeighborComparator ncomp; + moSolNeighborComparator sncomp; + moDummyIntensification intens; + moDummyDiversification diver; + moSolVectorTabuList tabuList(4,0); + moBestImprAspiration aspir; - moTSExplorer test(nh, eval, ncomp, sncomp, tabuList, intens, diver, aspir); - moTSExplorer test2(emptyNH, eval, ncomp, sncomp, tabuList, intens, diver, aspir); + moTSExplorer test(nh, eval, ncomp, sncomp, tabuList, intens, diver, aspir); + moTSExplorer test2(emptyNH, eval, ncomp, sncomp, tabuList, intens, diver, aspir); - //test d'un voisinage vide - test2.initParam(sol); - test2(sol); - assert(!test2.accept(sol)); + //test d'un voisinage vide + test2.initParam(sol); + test2(sol); + assert(!test2.accept(sol)); - //test le comportement classique de la taboo - test.initParam(sol); - assert(aspir.getBest()==sol); + //test le comportement classique de la taboo + test.initParam(sol); + assert(aspir.getBest()==sol); - test(sol); - test.updateParam(sol); - assert(aspir.getBest()==sol); + test(sol); + test.updateParam(sol); + assert(aspir.getBest()==sol); - //on ameliore et on stock une sol tabou 0111 - test(sol); - test.move(sol); - test.moveApplied(true); - test.updateParam(sol); - assert(aspir.getBest()==sol); + //on ameliore et on stock une sol tabou 0111 + test(sol); + test.move(sol); + test.moveApplied(true); + test.updateParam(sol); + assert(aspir.getBest()==sol); - //on ameliore et on stock une autre sol tabou 0011 - test(sol); - test.move(sol); - test.moveApplied(true); - test.updateParam(sol); - assert(aspir.getBest()==sol); + //on ameliore et on stock une autre sol tabou 0011 + test(sol); + test.move(sol); + test.moveApplied(true); + test.updateParam(sol); + assert(aspir.getBest()==sol); - //pareil on stock 0001 met pdt la recherche on se rend compte que 0111 est tabou - test(sol); - test.move(sol); - test.moveApplied(true); - test.updateParam(sol); - assert(aspir.getBest()==sol); + //pareil on stock 0001 met pdt la recherche on se rend compte que 0111 est tabou + test(sol); + test.move(sol); + test.moveApplied(true); + test.updateParam(sol); + assert(aspir.getBest()==sol); - //on modifie la sol en 1001(fitness 2) pour que la 1er sol exploré(0001) soit tabou - //De plus on change la solution mais elle est pas meilleure que la best so Far - sol[0]=true; - std::cout << sol << std::endl; - sol.fitness(2); - test(sol); - test.move(sol); - test.moveApplied(true); - test.updateParam(sol); - assert( sol[0] && !sol[1] && !sol[2] && !sol[3]); - sol[0]=false; - sol[3]=true; - assert(aspir.getBest()==sol); + //on modifie la sol en 1001(fitness 2) pour que la 1er sol exploré(0001) soit tabou + //De plus on change la solution mais elle est pas meilleure que la best so Far + sol[0]=true; + std::cout << sol << std::endl; + sol.fitness(2); + test(sol); + test.move(sol); + test.moveApplied(true); + test.updateParam(sol); + assert( sol[0] && !sol[1] && !sol[2] && !sol[3]); + sol[0]=false; + sol[3]=true; + assert(aspir.getBest()==sol); - //test du isContinue - assert(test.isContinue(sol)); + //test du isContinue + assert(test.isContinue(sol)); - //test du terminate - test.initParam(sol); - sol[0]=true; - sol[1]=true; - sol[2]=true; - sol[3]=true; - sol.fitness(4); - test(sol); - test.move(sol); - test.moveApplied(true); - test.updateParam(sol); - assert( !sol[0] && sol[1] && sol[2] && sol[3]); - test.terminate(sol); - assert( !sol[0] && !sol[1] && !sol[2] && sol[3]); + //test du terminate + test.initParam(sol); + sol[0]=true; + sol[1]=true; + sol[2]=true; + sol[3]=true; + sol.fitness(4); + test(sol); + test.move(sol); + test.moveApplied(true); + test.updateParam(sol); + assert( !sol[0] && sol[1] && sol[2] && sol[3]); + test.terminate(sol); + assert( !sol[0] && !sol[1] && !sol[2] && sol[3]); - //test pour avoir que des mouvement taboo - eoBit sol2(2, true); - sol2.fitness(2); - bitNeighborhood nh2(2); - evalOneMax eval2(2); + //test pour avoir que des mouvement taboo + eoBit sol2(2, true); + sol2.fitness(2); + bitNeighborhood nh2(2); + evalOneMax eval2(2); - moTSExplorer test3(nh2, eval2, ncomp, sncomp, tabuList, intens, diver, aspir); + moTSExplorer test3(nh2, eval2, ncomp, sncomp, tabuList, intens, diver, aspir); - test3.initParam(sol2); - test3(sol2); - test3.move(sol2); - test3.moveApplied(true); - test3.updateParam(sol2); + test3.initParam(sol2); + test3(sol2); + test3.move(sol2); + test3.moveApplied(true); + test3.updateParam(sol2); - test3(sol2); - test3.move(sol2); - test3.moveApplied(true); - test3.updateParam(sol2); + test3(sol2); + test3.move(sol2); + test3.moveApplied(true); + test3.updateParam(sol2); - test3(sol2); - test3.move(sol2); - test3.moveApplied(true); - test3.updateParam(sol2); + test3(sol2); + test3.move(sol2); + test3.moveApplied(true); + test3.updateParam(sol2); - test3(sol2); - test3.move(sol2); - test3.moveApplied(true); - test3.updateParam(sol2); + test3(sol2); + test3.move(sol2); + test3.moveApplied(true); + test3.updateParam(sol2); - //on a rempli la liste tabu pour que tout les voisins soit tabu - test3(sol2); - assert(!test3.accept(sol2)); + //on a rempli la liste tabu pour que tout les voisins soit tabu + test3(sol2); + assert(!test3.accept(sol2)); - std::cout << "[t-moTSExplorer] => OK" << std::endl; + std::cout << "[t-moTSExplorer] => OK" << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/test/t-moTrueContinuator.cpp b/trunk/paradiseo-mo/test/t-moTrueContinuator.cpp index c3ae5746d..eb717abbb 100644 --- a/trunk/paradiseo-mo/test/t-moTrueContinuator.cpp +++ b/trunk/paradiseo-mo/test/t-moTrueContinuator.cpp @@ -39,15 +39,15 @@ #include -int main(){ +int main() { - std::cout << "[t-moTrueContinuator] => START" << std::endl; + std::cout << "[t-moTrueContinuator] => START" << std::endl; - moTrueContinuator test; - Solution s; + moTrueContinuator test; + Solution s; - assert(test(s)); + assert(test(s)); - std::cout << "[t-moTrueContinuator] => OK" << std::endl; - return EXIT_SUCCESS; + std::cout << "[t-moTrueContinuator] => OK" << std::endl; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testFirstImpr.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testFirstImpr.cpp index af728719b..5ce85ceb6 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/testFirstImpr.cpp +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testFirstImpr.cpp @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- /** testFirstImpr.cpp * - * SV - 12/01/10 + * SV - 12/01/10 * */ //----------------------------------------------------------------------------- @@ -38,148 +38,148 @@ using namespace std; // REPRESENTATION //----------------------------------------------------------------------------- -typedef eoBit Indi; +typedef eoBit Indi; typedef moBitNeighbor Neighbor ; // incremental evaluation typedef moRndWithoutReplNeighborhood Neighborhood ; void main_function(int argc, char **argv) { - /* ========================================================= - * - * Parameters - * - * ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ - // First define a parser from the command-line arguments - eoParser parser(argc, argv); + // First define a parser from the command-line arguments + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // description of genotype - eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); - parser.processParam( vecSizeParam, "Representation" ); - unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()){ - parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != ""){ - ofstream os(statusParam.value().c_str()); - os << parser;// and you can use that file as parameter file - } + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } - /* ========================================================= - * - * Random seed - * - * ========================================================= */ + /* ========================================================= + * + * Random seed + * + * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ - FuncOneMax eval(vecSize); + FuncOneMax eval(vecSize); - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ - moFullEvalByModif fulleval(eval); + moFullEvalByModif fulleval(eval); - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); + //An eval by copy can be used instead of the eval by modif + //moFullEvalByCopy fulleval(eval); - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ + /* ========================================================= + * + * Comparator of neighbors + * + * ========================================================= */ - moNeighborComparator comparator; - moSolNeighborComparator solComparator; + moNeighborComparator comparator; + moSolNeighborComparator solComparator; - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ - Neighborhood neighborhood(vecSize); + Neighborhood neighborhood(vecSize); - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moFirstImprExplorer explorer(neighborhood, fulleval, comparator, solComparator); + /* ========================================================= + * + * a neighborhood explorer solution + * + * ========================================================= */ + + moFirstImprExplorer explorer(neighborhood, fulleval, comparator, solComparator); - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - moTrueContinuator continuator;//always continue + moTrueContinuator continuator;//always continue - moLocalSearch< moFirstImprExplorer > localSearch(explorer, continuator, eval); + moLocalSearch< moFirstImprExplorer > localSearch(explorer, continuator, eval); - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ - Indi solution; + Indi solution; - random(solution); + random(solution); - //Can be eval here, else it will be done at the beginning of the localSearch - //eval(solution); + //Can be eval here, else it will be done at the beginning of the localSearch + //eval(solution); - std::cout << "initial: " << solution << std::endl ; + std::cout << "initial: " << solution << std::endl ; - localSearch(solution); - - std::cout << "final: " << solution << std::endl ; + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; } @@ -187,11 +187,11 @@ void main_function(int argc, char **argv) int main(int argc, char **argv) { - try{ - main_function(argc, argv); - } - catch(exception& e){ - cout << "Exception: " << e.what() << '\n'; - } - return 1; + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testHCneutral.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testHCneutral.cpp index a14367f7b..037a8c698 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/testHCneutral.cpp +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testHCneutral.cpp @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- /** testHCneutral.cpp * - * SV - 24/01/10 + * SV - 24/01/10 * */ //----------------------------------------------------------------------------- @@ -38,152 +38,152 @@ using namespace std; // REPRESENTATION //----------------------------------------------------------------------------- -typedef eoBit Indi; +typedef eoBit Indi; typedef moBitNeighbor Neighbor ; // incremental evaluation typedef moOrderNeighborhood Neighborhood ; void main_function(int argc, char **argv) { - /* ========================================================= - * - * Parameters - * - * ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ - // First define a parser from the command-line arguments - eoParser parser(argc, argv); + // First define a parser from the command-line arguments + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // description of genotype - eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); - parser.processParam( vecSizeParam, "Representation" ); - unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); - eoValueParam stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); - parser.processParam( stepParam, "Representation" ); - unsigned nbStep = stepParam.value(); + eoValueParam stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); + parser.processParam( stepParam, "Representation" ); + unsigned nbStep = stepParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()){ - parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != ""){ - ofstream os(statusParam.value().c_str()); - os << parser;// and you can use that file as parameter file - } + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } - /* ========================================================= - * - * Random seed - * - * ========================================================= */ + /* ========================================================= + * + * Random seed + * + * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ - FuncOneMax eval(vecSize); + FuncOneMax eval(vecSize); - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ - moFullEvalByModif fulleval(eval); + moFullEvalByModif fulleval(eval); - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); + //An eval by copy can be used instead of the eval by modif + //moFullEvalByCopy fulleval(eval); - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ + /* ========================================================= + * + * Comparator of neighbors + * + * ========================================================= */ - moNeighborComparator comparator; - moSolNeighborComparator solComparator; + moNeighborComparator comparator; + moSolNeighborComparator solComparator; - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ - Neighborhood neighborhood(vecSize); + Neighborhood neighborhood(vecSize); - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moHCneutralExplorer explorer(neighborhood, fulleval, comparator, solComparator, nbStep); + /* ========================================================= + * + * a neighborhood explorer solution + * + * ========================================================= */ + + moHCneutralExplorer explorer(neighborhood, fulleval, comparator, solComparator, nbStep); - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - moTrueContinuator continuator;//always continue + moTrueContinuator continuator;//always continue - moLocalSearch< moHCneutralExplorer > localSearch(explorer, continuator, eval); + moLocalSearch< moHCneutralExplorer > localSearch(explorer, continuator, eval); - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ - Indi solution; + Indi solution; - random(solution); + random(solution); - //Can be eval here, else it will be done at the beginning of the localSearch - //eval(solution); + //Can be eval here, else it will be done at the beginning of the localSearch + //eval(solution); - std::cout << "initial: " << solution << std::endl ; + std::cout << "initial: " << solution << std::endl ; - localSearch(solution); - - std::cout << "final: " << solution << std::endl ; + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; } @@ -191,11 +191,11 @@ void main_function(int argc, char **argv) int main(int argc, char **argv) { - try{ - main_function(argc, argv); - } - catch(exception& e){ - cout << "Exception: " << e.what() << '\n'; - } - return 1; + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testMetropolisHasting.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testMetropolisHasting.cpp index c8518f20d..d647f60dc 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/testMetropolisHasting.cpp +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testMetropolisHasting.cpp @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- /** testMetropolisHasting.cpp * - * SV - 22/01/10 + * SV - 22/01/10 * */ //----------------------------------------------------------------------------- @@ -38,152 +38,152 @@ using namespace std; // REPRESENTATION //----------------------------------------------------------------------------- -typedef eoBit Indi; +typedef eoBit Indi; typedef moBitNeighbor Neighbor ; // incremental evaluation typedef moRndWithReplNeighborhood Neighborhood ; void main_function(int argc, char **argv) { - /* ========================================================= - * - * Parameters - * - * ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ - // First define a parser from the command-line arguments - eoParser parser(argc, argv); + // First define a parser from the command-line arguments + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // description of genotype - eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); - parser.processParam( vecSizeParam, "Representation" ); - unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); - eoValueParam stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); - parser.processParam( stepParam, "Representation" ); - unsigned nbStep = stepParam.value(); + eoValueParam stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); + parser.processParam( stepParam, "Representation" ); + unsigned nbStep = stepParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()){ - parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != ""){ - ofstream os(statusParam.value().c_str()); - os << parser;// and you can use that file as parameter file - } + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } - /* ========================================================= - * - * Random seed - * - * ========================================================= */ + /* ========================================================= + * + * Random seed + * + * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ - FuncOneMax eval(vecSize); + FuncOneMax eval(vecSize); - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ - moFullEvalByModif fulleval(eval); + moFullEvalByModif fulleval(eval); - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); + //An eval by copy can be used instead of the eval by modif + //moFullEvalByCopy fulleval(eval); - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ + /* ========================================================= + * + * Comparator of neighbors + * + * ========================================================= */ - moNeighborComparator comparator; - moSolNeighborComparator solComparator; + moNeighborComparator comparator; + moSolNeighborComparator solComparator; - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ - Neighborhood neighborhood(vecSize); + Neighborhood neighborhood(vecSize); - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moMetropolisHastingExplorer explorer(neighborhood, fulleval, comparator, solComparator, nbStep); + /* ========================================================= + * + * a neighborhood explorer solution + * + * ========================================================= */ + + moMetropolisHastingExplorer explorer(neighborhood, fulleval, comparator, solComparator, nbStep); - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - moTrueContinuator continuator;//always continue + moTrueContinuator continuator;//always continue - moLocalSearch< moMetropolisHastingExplorer > localSearch(explorer, continuator, eval); + moLocalSearch< moMetropolisHastingExplorer > localSearch(explorer, continuator, eval); - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ - Indi solution; + Indi solution; - random(solution); + random(solution); - //Can be eval here, else it will be done at the beginning of the localSearch - //eval(solution); + //Can be eval here, else it will be done at the beginning of the localSearch + //eval(solution); - std::cout << "initial: " << solution << std::endl ; + std::cout << "initial: " << solution << std::endl ; - localSearch(solution); - - std::cout << "final: " << solution << std::endl ; + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; } @@ -191,11 +191,11 @@ void main_function(int argc, char **argv) int main(int argc, char **argv) { - try{ - main_function(argc, argv); - } - catch(exception& e){ - cout << "Exception: " << e.what() << '\n'; - } - return 1; + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testRandomNeutralWalk.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testRandomNeutralWalk.cpp index 2c1b77b90..7243d5afa 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/testRandomNeutralWalk.cpp +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testRandomNeutralWalk.cpp @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- /** testRandomNeutralWalk.cpp * - * SV - 22/02/10 + * SV - 22/02/10 * */ //----------------------------------------------------------------------------- @@ -52,215 +52,215 @@ using namespace std; // REPRESENTATION //----------------------------------------------------------------------------- -typedef eoBit Indi; +typedef eoBit Indi; typedef moBitNeighbor Neighbor ; // incremental evaluation typedef moRndWithoutReplNeighborhood Neighborhood ; void main_function(int argc, char **argv) { - /* ========================================================= - * - * Parameters - * - * ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ - // First define a parser from the command-line arguments - eoParser parser(argc, argv); + // First define a parser from the command-line arguments + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // description of genotype - eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); - parser.processParam( vecSizeParam, "Representation" ); - unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); - eoValueParam blockSizeParam(2, "blockSize", "Size of block in the royal road", 'k'); - parser.processParam( blockSizeParam, "Representation" ); - unsigned blockSize = blockSizeParam.value(); + eoValueParam blockSizeParam(2, "blockSize", "Size of block in the royal road", 'k'); + parser.processParam( blockSizeParam, "Representation" ); + unsigned blockSize = blockSizeParam.value(); - eoValueParam stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); - parser.processParam( stepParam, "Representation" ); - unsigned nbStep = stepParam.value(); + eoValueParam stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); + parser.processParam( stepParam, "Representation" ); + unsigned nbStep = stepParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()){ - parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != ""){ - ofstream os(statusParam.value().c_str()); - os << parser;// and you can use that file as parameter file - } + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } - /* ========================================================= - * - * Random seed - * - * ========================================================= */ + /* ========================================================= + * + * Random seed + * + * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ - FuncRoyalRoad eval(vecSize / blockSize, blockSize); + FuncRoyalRoad eval(vecSize / blockSize, blockSize); - /* ========================================================= - * - * Initilisazor of the solution - * - * ========================================================= */ + /* ========================================================= + * + * Initilisazor of the solution + * + * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); - /* ========================================================= - * - * Evaluation of a neighbor solution - * - * ========================================================= */ + /* ========================================================= + * + * Evaluation of a neighbor solution + * + * ========================================================= */ - moFullEvalByModif nhEval(eval); + moFullEvalByModif nhEval(eval); - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy nhEval(eval); + //An eval by copy can be used instead of the eval by modif + //moFullEvalByCopy nhEval(eval); - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ + /* ========================================================= + * + * Comparator of neighbors + * + * ========================================================= */ - moNeighborComparator comparator; - moSolNeighborComparator solComparator; + moNeighborComparator comparator; + moSolNeighborComparator solComparator; - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ - Neighborhood neighborhood(vecSize); + Neighborhood neighborhood(vecSize); - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moRandomNeutralWalkExplorer explorer(neighborhood, nhEval, solComparator, nbStep); + /* ========================================================= + * + * a neighborhood explorer solution + * + * ========================================================= */ + + moRandomNeutralWalkExplorer explorer(neighborhood, nhEval, solComparator, nbStep); - /* ========================================================= - * - * initial random solution - * - * ========================================================= */ + /* ========================================================= + * + * initial random solution + * + * ========================================================= */ - Indi solution; + Indi solution; - random(solution); + random(solution); - //Can be eval here, else it will be done at the beginning of the localSearch - eval(solution); + //Can be eval here, else it will be done at the beginning of the localSearch + eval(solution); - /* ========================================================= - * - * the continuator and the checkpoint - * - * ========================================================= */ + /* ========================================================= + * + * the continuator and the checkpoint + * + * ========================================================= */ - moTrueContinuator continuator;//always continue + moTrueContinuator continuator;//always continue - moCheckpoint checkpoint(continuator); + moCheckpoint checkpoint(continuator); - moFitnessStat fStat; + moFitnessStat fStat; - eoHammingDistance distance; - moDistanceStat distStat(distance, solution); // distance from the intial solution - - moOrderNeighborhood nh(vecSize); - moNeighborhoodStat< moOrderNeighborhood > neighborhoodStat(nh, nhEval, comparator, solComparator); - moMinNeighborStat< moOrderNeighborhood > minStat(neighborhoodStat); - moSecondMomentNeighborStat< moOrderNeighborhood > secondMomentStat(neighborhoodStat); - moMaxNeighborStat< moOrderNeighborhood > maxStat(neighborhoodStat); + eoHammingDistance distance; + moDistanceStat distStat(distance, solution); // distance from the intial solution - moNbSupNeighborStat< moOrderNeighborhood > nbSupStat(neighborhoodStat); - moNbInfNeighborStat< moOrderNeighborhood > nbInfStat(neighborhoodStat); - moNeutralDegreeNeighborStat< moOrderNeighborhood > ndStat(neighborhoodStat); - moSizeNeighborStat< moOrderNeighborhood > sizeStat(neighborhoodStat); + moOrderNeighborhood nh(vecSize); + moNeighborhoodStat< moOrderNeighborhood > neighborhoodStat(nh, nhEval, comparator, solComparator); + moMinNeighborStat< moOrderNeighborhood > minStat(neighborhoodStat); + moSecondMomentNeighborStat< moOrderNeighborhood > secondMomentStat(neighborhoodStat); + moMaxNeighborStat< moOrderNeighborhood > maxStat(neighborhoodStat); - eoValueParam genCounter(-1,"Gen"); - eoIncrementor increm(genCounter.value()); + moNbSupNeighborStat< moOrderNeighborhood > nbSupStat(neighborhoodStat); + moNbInfNeighborStat< moOrderNeighborhood > nbInfStat(neighborhoodStat); + moNeutralDegreeNeighborStat< moOrderNeighborhood > ndStat(neighborhoodStat); + moSizeNeighborStat< moOrderNeighborhood > sizeStat(neighborhoodStat); - checkpoint.add(fStat); - checkpoint.add(distStat); - checkpoint.add(neighborhoodStat); - checkpoint.add(minStat); - checkpoint.add(secondMomentStat); - checkpoint.add(maxStat); - checkpoint.add(nbInfStat); - checkpoint.add(ndStat); - checkpoint.add(nbSupStat); - checkpoint.add(sizeStat); - checkpoint.add(increm); + eoValueParam genCounter(-1,"Gen"); + eoIncrementor increm(genCounter.value()); - eoFileMonitor outputfile("out.dat", " "); - checkpoint.add(outputfile); + checkpoint.add(fStat); + checkpoint.add(distStat); + checkpoint.add(neighborhoodStat); + checkpoint.add(minStat); + checkpoint.add(secondMomentStat); + checkpoint.add(maxStat); + checkpoint.add(nbInfStat); + checkpoint.add(ndStat); + checkpoint.add(nbSupStat); + checkpoint.add(sizeStat); + checkpoint.add(increm); - outputfile.add(genCounter); - outputfile.add(fStat); - outputfile.add(distStat); - outputfile.add(minStat); - outputfile.add(secondMomentStat); - outputfile.add(maxStat); - outputfile.add(nbInfStat); - outputfile.add(ndStat); - outputfile.add(nbSupStat); - outputfile.add(sizeStat); + eoFileMonitor outputfile("out.dat", " "); + checkpoint.add(outputfile); - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ + outputfile.add(genCounter); + outputfile.add(fStat); + outputfile.add(distStat); + outputfile.add(minStat); + outputfile.add(secondMomentStat); + outputfile.add(maxStat); + outputfile.add(nbInfStat); + outputfile.add(ndStat); + outputfile.add(nbSupStat); + outputfile.add(sizeStat); - moLocalSearch< moRandomNeutralWalkExplorer > localSearch(explorer, checkpoint, eval); + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ + moLocalSearch< moRandomNeutralWalkExplorer > localSearch(explorer, checkpoint, eval); - std::cout << "initial: " << solution << std::endl ; + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ - localSearch(solution); - - std::cout << "final: " << solution << std::endl ; + std::cout << "initial: " << solution << std::endl ; + + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; } @@ -268,11 +268,11 @@ void main_function(int argc, char **argv) int main(int argc, char **argv) { - try{ - main_function(argc, argv); - } - catch(exception& e){ - cout << "Exception: " << e.what() << '\n'; - } - return 1; + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testRandomWalk.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testRandomWalk.cpp index 6edd068db..3496e4a15 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/testRandomWalk.cpp +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testRandomWalk.cpp @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- /** testRandomWalk.cpp * - * SV - 22/01/10 + * SV - 22/01/10 * */ //----------------------------------------------------------------------------- @@ -44,188 +44,188 @@ using namespace std; // REPRESENTATION //----------------------------------------------------------------------------- -typedef eoBit Indi; +typedef eoBit Indi; typedef moBitNeighbor Neighbor ; // incremental evaluation typedef moRndWithReplNeighborhood Neighborhood ; void main_function(int argc, char **argv) { - /* ========================================================= - * - * Parameters - * - * ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ - // First define a parser from the command-line arguments - eoParser parser(argc, argv); + // First define a parser from the command-line arguments + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // description of genotype - eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); - parser.processParam( vecSizeParam, "Representation" ); - unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); - eoValueParam stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); - parser.processParam( stepParam, "Representation" ); - unsigned nbStep = stepParam.value(); + eoValueParam stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); + parser.processParam( stepParam, "Representation" ); + unsigned nbStep = stepParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()){ - parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != ""){ - ofstream os(statusParam.value().c_str()); - os << parser;// and you can use that file as parameter file - } + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } - /* ========================================================= - * - * Random seed - * - * ========================================================= */ + /* ========================================================= + * + * Random seed + * + * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ - FuncOneMax eval(vecSize); + FuncOneMax eval(vecSize); - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ - moFullEvalByModif nhEval(eval); + moFullEvalByModif nhEval(eval); - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy nhEval(eval); + //An eval by copy can be used instead of the eval by modif + //moFullEvalByCopy nhEval(eval); - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ - Neighborhood neighborhood(vecSize); + Neighborhood neighborhood(vecSize); - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moRandomWalkExplorer explorer(neighborhood, nhEval, nbStep); + /* ========================================================= + * + * a neighborhood explorer solution + * + * ========================================================= */ + + moRandomWalkExplorer explorer(neighborhood, nhEval, nbStep); - /* ========================================================= - * - * the continuator and the checkpoint - * - * ========================================================= */ + /* ========================================================= + * + * the continuator and the checkpoint + * + * ========================================================= */ - moTrueContinuator continuator;//always continue + moTrueContinuator continuator;//always continue - moCheckpoint checkpoint(continuator); + moCheckpoint checkpoint(continuator); - moFitnessStat fStat; - eoHammingDistance distance; - Indi bestSolution(vecSize, true); - moDistanceStat distStat(distance, bestSolution); - // moSolutionStat solStat; - - checkpoint.add(fStat); - checkpoint.add(distStat); - // checkpoint.add(solStat); + moFitnessStat fStat; + eoHammingDistance distance; + Indi bestSolution(vecSize, true); + moDistanceStat distStat(distance, bestSolution); + // moSolutionStat solStat; - eoValueParam genCounter(-1,"Gen"); - eoIncrementor increm(genCounter.value()); - checkpoint.add(increm); + checkpoint.add(fStat); + checkpoint.add(distStat); + // checkpoint.add(solStat); - eoFileMonitor outputfile("out.dat", " "); - checkpoint.add(outputfile); + eoValueParam genCounter(-1,"Gen"); + eoIncrementor increm(genCounter.value()); + checkpoint.add(increm); - outputfile.add(genCounter); - outputfile.add(fStat); - outputfile.add(distStat); - // outputfile.add(solStat); + eoFileMonitor outputfile("out.dat", " "); + checkpoint.add(outputfile); - Indi solution; // current solution of the search process + outputfile.add(genCounter); + outputfile.add(fStat); + outputfile.add(distStat); + // outputfile.add(solStat); - /* - // to save the solution at each iteration - eoState outState; + Indi solution; // current solution of the search process - // Register the algorithm into the state (so it has something to save!! + /* + // to save the solution at each iteration + eoState outState; - outState.registerObject(solution); + // Register the algorithm into the state (so it has something to save!! - // 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); - */ + outState.registerObject(solution); - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ + // and feed the state to state savers + // save state every 10th iteration + eoCountedStateSaver stateSaver(10, outState, "iteration"); - moLocalSearch< moRandomWalkExplorer > localSearch(explorer, checkpoint, eval); + // Don't forget to add the two savers to the checkpoint + checkpoint.add(stateSaver); + */ - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - random(solution); + moLocalSearch< moRandomWalkExplorer > localSearch(explorer, checkpoint, eval); - //Can be eval here, else it will be done at the beginning of the localSearch - //eval(solution); + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ - std::cout << "initial: " << solution << std::endl ; + random(solution); - localSearch(solution); - - std::cout << "final: " << solution << std::endl ; + //Can be eval here, else it will be done at the beginning of the localSearch + //eval(solution); + + std::cout << "initial: " << solution << std::endl ; + + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; } @@ -233,11 +233,11 @@ void main_function(int argc, char **argv) int main(int argc, char **argv) { - try{ - main_function(argc, argv); - } - catch(exception& e){ - cout << "Exception: " << e.what() << '\n'; - } - return 1; + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHC.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHC.cpp index 53da20692..7d37a93fc 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHC.cpp +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHC.cpp @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- /** testSimpleHC.cpp * - * SV - 12/01/10 + * SV - 12/01/10 * */ //----------------------------------------------------------------------------- @@ -38,148 +38,148 @@ using namespace std; // REPRESENTATION //----------------------------------------------------------------------------- -typedef eoBit Indi; +typedef eoBit Indi; typedef moBitNeighbor Neighbor ; // incremental evaluation typedef moOrderNeighborhood Neighborhood ; void main_function(int argc, char **argv) { - /* ========================================================= - * - * Parameters - * - * ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ - // First define a parser from the command-line arguments - eoParser parser(argc, argv); + // First define a parser from the command-line arguments + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // description of genotype - eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); - parser.processParam( vecSizeParam, "Representation" ); - unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()){ - parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != ""){ - ofstream os(statusParam.value().c_str()); - os << parser;// and you can use that file as parameter file - } + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } - /* ========================================================= - * - * Random seed - * - * ========================================================= */ + /* ========================================================= + * + * Random seed + * + * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ - FuncOneMax eval(vecSize); + FuncOneMax eval(vecSize); - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ - moFullEvalByModif fulleval(eval); + moFullEvalByModif fulleval(eval); - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); + //An eval by copy can be used instead of the eval by modif + //moFullEvalByCopy fulleval(eval); - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ + /* ========================================================= + * + * Comparator of neighbors + * + * ========================================================= */ - moNeighborComparator comparator; - moSolNeighborComparator solComparator; + moNeighborComparator comparator; + moSolNeighborComparator solComparator; - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ - Neighborhood neighborhood(vecSize); + Neighborhood neighborhood(vecSize); - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moSimpleHCexplorer explorer(neighborhood, fulleval, comparator, solComparator); + /* ========================================================= + * + * a neighborhood explorer solution + * + * ========================================================= */ + + moSimpleHCexplorer explorer(neighborhood, fulleval, comparator, solComparator); - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - moTrueContinuator continuator;//always continue + moTrueContinuator continuator;//always continue - moLocalSearch< moSimpleHCexplorer > localSearch(explorer, continuator, eval); + moLocalSearch< moSimpleHCexplorer > localSearch(explorer, continuator, eval); - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ - Indi solution; + Indi solution; - random(solution); + random(solution); - //Can be eval here, else it will be done at the beginning of the localSearch - //eval(solution); + //Can be eval here, else it will be done at the beginning of the localSearch + //eval(solution); - std::cout << "initial: " << solution << std::endl ; + std::cout << "initial: " << solution << std::endl ; - localSearch(solution); - - std::cout << "final: " << solution << std::endl ; + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; } @@ -187,11 +187,11 @@ void main_function(int argc, char **argv) int main(int argc, char **argv) { - try{ - main_function(argc, argv); - } - catch(exception& e){ - cout << "Exception: " << e.what() << '\n'; - } - return 1; + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHCneutral.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHCneutral.cpp index e193c0ab2..8db916671 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHCneutral.cpp +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHCneutral.cpp @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- /** testSimpleHCneutral.cpp * - * SV - 24/01/10 + * SV - 24/01/10 * */ //----------------------------------------------------------------------------- @@ -38,148 +38,148 @@ using namespace std; // REPRESENTATION //----------------------------------------------------------------------------- -typedef eoBit Indi; +typedef eoBit Indi; typedef moBitNeighbor Neighbor ; // incremental evaluation typedef moOrderNeighborhood Neighborhood ; void main_function(int argc, char **argv) { - /* ========================================================= - * - * Parameters - * - * ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ - // First define a parser from the command-line arguments - eoParser parser(argc, argv); + // First define a parser from the command-line arguments + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // description of genotype - eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); - parser.processParam( vecSizeParam, "Representation" ); - unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()){ - parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != ""){ - ofstream os(statusParam.value().c_str()); - os << parser;// and you can use that file as parameter file - } + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } - /* ========================================================= - * - * Random seed - * - * ========================================================= */ + /* ========================================================= + * + * Random seed + * + * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ - FuncOneMax eval(vecSize); + FuncOneMax eval(vecSize); - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ - moFullEvalByModif fulleval(eval); + moFullEvalByModif fulleval(eval); - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); + //An eval by copy can be used instead of the eval by modif + //moFullEvalByCopy fulleval(eval); - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ + /* ========================================================= + * + * Comparator of neighbors + * + * ========================================================= */ - moNeighborComparator comparator; - moSolNeighborComparator solComparator; + moNeighborComparator comparator; + moSolNeighborComparator solComparator; - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ - Neighborhood neighborhood(vecSize); + Neighborhood neighborhood(vecSize); - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moSimpleHCneutralExplorer explorer(neighborhood, fulleval, comparator, solComparator); + /* ========================================================= + * + * a neighborhood explorer solution + * + * ========================================================= */ + + moSimpleHCneutralExplorer explorer(neighborhood, fulleval, comparator, solComparator); - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - moTrueContinuator continuator;//always continue + moTrueContinuator continuator;//always continue - moLocalSearch< moSimpleHCneutralExplorer > localSearch(explorer, continuator, eval); + moLocalSearch< moSimpleHCneutralExplorer > localSearch(explorer, continuator, eval); - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ - Indi solution; + Indi solution; - random(solution); + random(solution); - //Can be eval here, else it will be done at the beginning of the localSearch - //eval(solution); + //Can be eval here, else it will be done at the beginning of the localSearch + //eval(solution); - std::cout << "initial: " << solution << std::endl ; + std::cout << "initial: " << solution << std::endl ; - localSearch(solution); - - std::cout << "final: " << solution << std::endl ; + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; } @@ -187,11 +187,11 @@ void main_function(int argc, char **argv) int main(int argc, char **argv) { - try{ - main_function(argc, argv); - } - catch(exception& e){ - cout << "Exception: " << e.what() << '\n'; - } - return 1; + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleTS.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleTS.cpp index 6cdd51093..8f623e226 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleTS.cpp +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleTS.cpp @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- /** testSimpleHC.cpp * - * SV - 12/01/10 + * SV - 12/01/10 * */ //----------------------------------------------------------------------------- @@ -40,152 +40,152 @@ using namespace std; // REPRESENTATION //----------------------------------------------------------------------------- -typedef eoBit Indi; +typedef eoBit Indi; typedef moBitNeighbor Neighbor ; // incremental evaluation typedef moOrderNeighborhood Neighborhood ; void main_function(int argc, char **argv) { - /* ========================================================= - * - * Parameters - * - * ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ - // First define a parser from the command-line arguments - eoParser parser(argc, argv); + // First define a parser from the command-line arguments + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // description of genotype - eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); - parser.processParam( vecSizeParam, "Representation" ); - unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()){ - parser.printHelp(cout); - exit(1); - } - if (statusParam.value() != ""){ - ofstream os(statusParam.value().c_str()); - os << parser;// and you can use that file as parameter file - } + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { + parser.printHelp(cout); + exit(1); + } + if (statusParam.value() != "") { + ofstream os(statusParam.value().c_str()); + os << parser;// and you can use that file as parameter file + } - /* ========================================================= - * - * Random seed - * - * ========================================================= */ + /* ========================================================= + * + * Random seed + * + * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ - FuncOneMax fulleval(vecSize); + FuncOneMax fulleval(vecSize); - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ - moFullEvalByModif eval(fulleval); + moFullEvalByModif eval(fulleval); - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); + //An eval by copy can be used instead of the eval by modif + //moFullEvalByCopy fulleval(eval); - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ + /* ========================================================= + * + * Comparator of neighbors + * + * ========================================================= */ - moNeighborComparator comparator; - moSolNeighborComparator solComparator; + moNeighborComparator comparator; + moSolNeighborComparator solComparator; - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ - Neighborhood neighborhood(vecSize); + Neighborhood neighborhood(vecSize); - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moSolVectorTabuList tl(10,10); - moDummyIntensification inten; - moDummyDiversification div; - moBestImprAspiration asp; - moTSExplorer explorer(neighborhood, eval, comparator, solComparator, tl, inten, div, asp); + /* ========================================================= + * + * a neighborhood explorer solution + * + * ========================================================= */ + + moSolVectorTabuList tl(10,10); + moDummyIntensification inten; + moDummyDiversification div; + moBestImprAspiration asp; + moTSExplorer explorer(neighborhood, eval, comparator, solComparator, tl, inten, div, asp); - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - moTrueContinuator continuator;//always continue + moTrueContinuator continuator;//always continue - moLocalSearch< moTSExplorer > localSearch(explorer, continuator, fulleval); + moLocalSearch< moTSExplorer > localSearch(explorer, continuator, fulleval); - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ - Indi solution; + Indi solution; - random(solution); + random(solution); - //Can be eval here, else it will be done at the beginning of the localSearch - //eval(solution); + //Can be eval here, else it will be done at the beginning of the localSearch + //eval(solution); - std::cout << "initial: " << solution << std::endl ; + std::cout << "initial: " << solution << std::endl ; - localSearch(solution); - - std::cout << "final: " << solution << std::endl ; + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; } @@ -193,11 +193,11 @@ void main_function(int argc, char **argv) int main(int argc, char **argv) { - try{ - main_function(argc, argv); - } - catch(exception& e){ - cout << "Exception: " << e.what() << '\n'; - } - return 1; + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/application/testWithMove.cpp b/trunk/paradiseo-mo/tutorial/oneMax/application/testWithMove.cpp index 726f1fa05..9259d7b81 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/application/testWithMove.cpp +++ b/trunk/paradiseo-mo/tutorial/oneMax/application/testWithMove.cpp @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- /** testSimpleHC.cpp * - * SV - 12/01/10 + * SV - 12/01/10 * */ //----------------------------------------------------------------------------- @@ -51,7 +51,7 @@ using namespace std; // REPRESENTATION //----------------------------------------------------------------------------- // define your individuals -typedef eoBit Indi; +typedef eoBit Indi; //typedef OneMaxBitNeighbor Neighbor ; // incremental evaluation typedef moMoveNeighbor, unsigned> Neighbor ; // full evaluation typedef moMoveNeighborhood, unsigned> Neighborhood ; @@ -61,138 +61,138 @@ typedef moMoveNeighborhood, unsigned> Neighborhood ; void main_function(int argc, char **argv) { - /* ========================================================= - * - * Parameters - * - * ========================================================= */ + /* ========================================================= + * + * Parameters + * + * ========================================================= */ - // First define a parser from the command-line arguments - eoParser parser(argc, argv); + // First define a parser from the command-line arguments + eoParser parser(argc, argv); - // For each parameter, define Parameter, read it through the parser, - // and assign the value to the variable + // For each parameter, define Parameter, read it through the parser, + // and assign the value to the variable - eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); - parser.processParam( seedParam ); - unsigned seed = seedParam.value(); + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); - // description of genotype - eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); - parser.processParam( vecSizeParam, "Representation" ); - unsigned vecSize = vecSizeParam.value(); + // description of genotype + eoValueParam vecSizeParam(8, "vecSize", "Genotype size", 'V'); + parser.processParam( vecSizeParam, "Representation" ); + unsigned vecSize = vecSizeParam.value(); - string fileOut("out.dat"); - eoValueParam fileStatParam(fileOut.c_str(), "out", "A file to export results", 'o'); - parser.processParam( fileStatParam, "Persistence" ); - fileOut = fileStatParam.value(); + string fileOut("out.dat"); + eoValueParam fileStatParam(fileOut.c_str(), "out", "A file to export results", 'o'); + parser.processParam( fileStatParam, "Persistence" ); + fileOut = fileStatParam.value(); - // the name of the "status" file where all actual parameter values will be saved - string str_status = parser.ProgramName() + ".status"; // default value - eoValueParam statusParam(str_status.c_str(), "status", "Status file"); - parser.processParam( statusParam, "Persistence" ); + // the name of the "status" file where all actual parameter values will be saved + string str_status = parser.ProgramName() + ".status"; // default value + eoValueParam statusParam(str_status.c_str(), "status", "Status file"); + parser.processParam( statusParam, "Persistence" ); - // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED - // i.e. in case you need parameters somewhere else, postpone these - if (parser.userNeedsHelp()) + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (parser.userNeedsHelp()) { - parser.printHelp(cout); - exit(1); + parser.printHelp(cout); + exit(1); } - if (statusParam.value() != "") + if (statusParam.value() != "") { - ofstream os(statusParam.value().c_str()); - os << parser; // and you can use that file as parameter file + ofstream os(statusParam.value().c_str()); + os << parser; // and you can use that file as parameter file } - /* ========================================================= - * - * Random seed - * - * ========================================================= */ + /* ========================================================= + * + * Random seed + * + * ========================================================= */ - //reproducible random seed: if you don't change SEED above, - // you'll aways get the same result, NOT a random run - rng.reseed(seed); + //reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + rng.reseed(seed); - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ - FuncOneMax eval(vecSize); + FuncOneMax eval(vecSize); - OneMaxIncrEval incrEval; - Neighbor::setIncrEval(incrEval); + OneMaxIncrEval incrEval; + Neighbor::setIncrEval(incrEval); - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); - - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ - - // no need if incremental evaluation with OneMaxBitNeighbor - // Neighbor::setFullEvalFunc(eval); + // a Indi random initializer + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ - BitMove_init init; - BitMove_next next; - + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ - Neighborhood neighborhood(init, next); + // no need if incremental evaluation with OneMaxBitNeighbor + // Neighbor::setFullEvalFunc(eval); - /* ========================================================= - * - * a neighborhood explorator solution - * - * ========================================================= */ - - moSimpleHCexplorer explorer(neighborhood); + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ + BitMove_init init; + BitMove_next next; - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ - moTrueContinuator continuator; + Neighborhood neighborhood(init, next); - moLocalSearch< moSimpleHCexplorer > localSearch(explorer, continuator); + /* ========================================================= + * + * a neighborhood explorator solution + * + * ========================================================= */ - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ + moSimpleHCexplorer explorer(neighborhood); - Indi solution; + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ - random(solution); + moTrueContinuator continuator; - eval(solution); + moLocalSearch< moSimpleHCexplorer > localSearch(explorer, continuator); - std::cout << "initial: " << solution << std::endl ; + /* ========================================================= + * + * execute the local search from random sollution + * + * ========================================================= */ - localSearch(solution); - - std::cout << "final: " << solution << std::endl ; + Indi solution; + + random(solution); + + eval(solution); + + std::cout << "initial: " << solution << std::endl ; + + localSearch(solution); + + std::cout << "final: " << solution << std::endl ; } @@ -205,7 +205,7 @@ int main(int argc, char **argv) { main_function(argc, argv); } - catch(exception& e) + catch (exception& e) { cout << "Exception: " << e.what() << '\n'; } diff --git a/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove.h b/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove.h index 17415ebda..0a5b2638b 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove.h +++ b/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove.h @@ -13,21 +13,21 @@ class BitMove : public moMove { public : -typedef EOT EOType; - - unsigned bit; + typedef EOT EOType; - BitMove() { - bit = 0; - } + unsigned bit; - BitMove(unsigned _bit) : bit(_bit) { } + BitMove() { + bit = 0; + } + + BitMove(unsigned _bit) : bit(_bit) { } - void operator () (EOT & chrom) - { - chrom[bit] = !chrom[bit]; - }; + void operator () (EOT & chrom) + { + chrom[bit] = !chrom[bit]; + }; } ; diff --git a/trunk/paradiseo-mo/tutorial/oneMax/src/bitMoveIncrEval.h b/trunk/paradiseo-mo/tutorial/oneMax/src/bitMoveIncrEval.h index fce128de5..1aa460a4c 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/src/bitMoveIncrEval.h +++ b/trunk/paradiseo-mo/tutorial/oneMax/src/bitMoveIncrEval.h @@ -11,17 +11,17 @@ template class OneMaxIncrEval : public moMoveIncrEval < BitMove > { -public : - OneMaxIncrEval(){ }; +public : + OneMaxIncrEval() { }; - typename EOT::Fitness operator () (const BitMove & move, const EOT & chrom) { - if(chrom[move.bit]==0){ - return chrom.fitness()+1; -} - else{ - return chrom.fitness()-1; -} -}; + typename EOT::Fitness operator () (const BitMove & move, const EOT & chrom) { + if (chrom[move.bit]==0) { + return chrom.fitness()+1; + } + else { + return chrom.fitness()-1; + } + }; }; #endif diff --git a/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_init.h b/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_init.h index a6254dca7..4fca0995a 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_init.h +++ b/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_init.h @@ -9,13 +9,13 @@ template class BitMove_init : public moMoveInit < BitMove > { - + public : - - void operator () (BitMove & __move, const EOT & genome) { - __move.bit = 0 ; - }; - + + void operator () (BitMove & __move, const EOT & genome) { + __move.bit = 0 ; + }; + } ; #endif diff --git a/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_next.h b/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_next.h index 1950ad9f0..28017e65a 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_next.h +++ b/trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_next.h @@ -10,24 +10,24 @@ template class BitMove_next : public moNextMove < BitMove > { - + public: - BitMove_next() - { - }; + BitMove_next() + { + }; + + bool operator () (BitMove & __move, const EOT & genome) { + + if (__move.bit >= (genome.size() - 1)) { + return false ; + } + else { + __move.bit++; + return true ; + } + }; - bool operator () (BitMove & __move, const EOT & genome) { - - if (__move.bit >= (genome.size() - 1)){ - return false ; -} - else { - __move.bit++; - return true ; - } - }; - } ; #endif diff --git a/trunk/paradiseo-mo/tutorial/oneMax/src/funcOneMax.h b/trunk/paradiseo-mo/tutorial/oneMax/src/funcOneMax.h index b35057203..a79d623fc 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/src/funcOneMax.h +++ b/trunk/paradiseo-mo/tutorial/oneMax/src/funcOneMax.h @@ -12,22 +12,22 @@ template< class EOT > class FuncOneMax : public eoEvalFunc { private: - unsigned N; - + unsigned N; + public: - FuncOneMax(unsigned n) : N(n) {}; + FuncOneMax(unsigned n) : N(n) {}; - ~FuncOneMax(void) {} ; - - void operator() (EOT & genome) { - unsigned sum = 0; + ~FuncOneMax(void) {} ; - for (int i = 0; i < N; i++) - sum += genome[i]; + void operator() (EOT & genome) { + unsigned sum = 0; + + for (int i = 0; i < N; i++) + sum += genome[i]; + + genome.fitness(sum); + } - genome.fitness(sum); - } - }; #endif diff --git a/trunk/paradiseo-mo/tutorial/oneMax/src/funcRoyalRoad.h b/trunk/paradiseo-mo/tutorial/oneMax/src/funcRoyalRoad.h index d26e022a0..d0b2af486 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/src/funcRoyalRoad.h +++ b/trunk/paradiseo-mo/tutorial/oneMax/src/funcRoyalRoad.h @@ -8,33 +8,33 @@ template< class EOT > class FuncRoyalRoad : public eoEvalFunc { - // number of blocks - unsigned n; + // number of blocks + unsigned n; + + // size of a block + unsigned k; - // size of a block - unsigned k; - public: - FuncRoyalRoad(unsigned _n, unsigned _k) : n(_n), k(_k) {}; + FuncRoyalRoad(unsigned _n, unsigned _k) : n(_n), k(_k) {}; - ~FuncRoyalRoad(void) {} ; - - virtual void operator() (EOT & _solution) - { - unsigned sum = 0; - unsigned i, j; + ~FuncRoyalRoad(void) {} ; - for (i = 0; i < n; i++) { - j = 0; - while (_solution[i * n + j] && j < k) j++; + virtual void operator() (EOT & _solution) + { + unsigned sum = 0; + unsigned i, j; - if (j == k) - sum++; - } + for (i = 0; i < n; i++) { + j = 0; + while (_solution[i * n + j] && j < k) j++; + + if (j == k) + sum++; + } + + _solution.fitness(sum); + }; - _solution.fitness(sum); - }; - }; #endif diff --git a/trunk/paradiseo-mo/tutorial/oneMax/src/oneMaxBitNeighbor.h b/trunk/paradiseo-mo/tutorial/oneMax/src/oneMaxBitNeighbor.h index bfe93f767..3ab1328f8 100644 --- a/trunk/paradiseo-mo/tutorial/oneMax/src/oneMaxBitNeighbor.h +++ b/trunk/paradiseo-mo/tutorial/oneMax/src/oneMaxBitNeighbor.h @@ -19,10 +19,10 @@ public: * incremental evaluation of the solution for the oneMax problem */ virtual void eval(EOType & solution) { - if (solution[bit] == 0) - fitness(solution.fitness() + 1); - else - fitness(solution.fitness() - 1); + if (solution[bit] == 0) + fitness(solution.fitness() + 1); + else + fitness(solution.fitness() - 1); }; };