From 16374482e0752f6e53a2f18e4a0d8381f166cdba Mon Sep 17 00:00:00 2001 From: verel Date: Wed, 28 Apr 2010 16:10:49 +0000 Subject: [PATCH] Ajout du moNeutralHC.h, et update de la lesson 1 git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1757 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-mo/src/algo/moFirstImprHC.h | 10 + trunk/paradiseo-mo/src/algo/moNeutralHC.h | 103 +++++++++ trunk/paradiseo-mo/src/algo/moRandomBestHC.h | 10 + trunk/paradiseo-mo/src/algo/moSimpleHC.h | 10 + .../src/explorer/moNeutralHCexplorer.h | 3 - trunk/paradiseo-mo/src/mo.h | 1 + .../tutorial/Lesson1/CMakeLists.txt | 4 +- .../tutorial/Lesson1/lesson1_HCneutral.cpp | 201 ------------------ .../tutorial/Lesson1/lesson1_firstImpr.cpp | 197 ----------------- .../tutorial/Lesson1/lesson1_neutralHC.cpp | 200 +++++++++++++++++ .../tutorial/Lesson1/testFirstImpr.cpp | 197 ----------------- .../tutorial/Lesson1/testHCneutral.cpp | 201 ------------------ .../tutorial/Lesson1/testRandomBestHC.cpp | 197 ----------------- .../tutorial/Lesson1/testSimpleHC.cpp | 197 ----------------- 14 files changed, 336 insertions(+), 1195 deletions(-) create mode 100644 trunk/paradiseo-mo/src/algo/moNeutralHC.h delete mode 100644 trunk/paradiseo-mo/tutorial/Lesson1/lesson1_HCneutral.cpp delete mode 100644 trunk/paradiseo-mo/tutorial/Lesson1/lesson1_firstImpr.cpp create mode 100644 trunk/paradiseo-mo/tutorial/Lesson1/lesson1_neutralHC.cpp delete mode 100644 trunk/paradiseo-mo/tutorial/Lesson1/testFirstImpr.cpp delete mode 100644 trunk/paradiseo-mo/tutorial/Lesson1/testHCneutral.cpp delete mode 100644 trunk/paradiseo-mo/tutorial/Lesson1/testRandomBestHC.cpp delete mode 100644 trunk/paradiseo-mo/tutorial/Lesson1/testSimpleHC.cpp diff --git a/trunk/paradiseo-mo/src/algo/moFirstImprHC.h b/trunk/paradiseo-mo/src/algo/moFirstImprHC.h index 3380f9e6f..a4e51a5d3 100644 --- a/trunk/paradiseo-mo/src/algo/moFirstImprHC.h +++ b/trunk/paradiseo-mo/src/algo/moFirstImprHC.h @@ -36,6 +36,16 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include +/******************************************************** + * First improvement HC: + * Hill-Climber local search + * + * At each iteration, + * one of the random solution in the neighborhood is selected + * if the selected neighbor have higher fitness than the current solution + * then the solution is replaced by the selected neighbor + * the algorithm stops when there is no higher neighbor + ********************************************************/ template class moFirstImprHC: public moLocalSearch { diff --git a/trunk/paradiseo-mo/src/algo/moNeutralHC.h b/trunk/paradiseo-mo/src/algo/moNeutralHC.h new file mode 100644 index 000000000..924fc9e3c --- /dev/null +++ b/trunk/paradiseo-mo/src/algo/moNeutralHC.h @@ -0,0 +1,103 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + +Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +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". + +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, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +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 _moNeutralHC_h +#define _moNeutralHC_h + +#include +#include +#include +#include +#include + +/******************************************************** + * Hill-Climber local search + * + * At each iteration, + * one of the random best solution in the neighborhood is selected + * if the selected neighbor have higher or equal fitness than the current solution + * then the solution is replaced by the selected neighbor + * the algorithm stops when there is no higher or equal neighbor, or if the number of iterations is too large + ********************************************************/ +template +class moNeutralHC: public moLocalSearch +{ +public: + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Simple constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + */ + moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep): + moLocalSearch(explorer, trueCont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) + {} + + /** + * Simple constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _cont an external continuator + */ + moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) + {} + + /** + * Simple constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _cont an external continuator + * @param _compN a neighbor vs neighbor comparator + * @param _compSN a solution vs neighbor comparator + */ + moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, _compN, _compSN, _nbStep) + {} + +private: + // always true continuator + moTrueContinuator trueCont; + // compare the fitness values of neighbors: true is strictly greater + moNeighborComparator defaultNeighborComp; + // compare the fitness values of the solution and the neighbor: true if strictly greater + moSolNeighborComparator defaultSolNeighborComp; + // the explorer of the HC with neutral move (equals fitness move) + moNeutralHCexplorer explorer; +}; + +#endif diff --git a/trunk/paradiseo-mo/src/algo/moRandomBestHC.h b/trunk/paradiseo-mo/src/algo/moRandomBestHC.h index 016ff5089..14fb1f0e2 100644 --- a/trunk/paradiseo-mo/src/algo/moRandomBestHC.h +++ b/trunk/paradiseo-mo/src/algo/moRandomBestHC.h @@ -36,6 +36,16 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include +/******************************************************** + * Random Best HC: + * Hill-Climber local search + * + * At each iteration, + * one of the random best solution in the neighborhood is selected + * if the selected neighbor have higher fitness than the current solution + * then the solution is replaced by the selected neighbor + * the algorithm stops when there is no higher neighbor + ********************************************************/ template class moRandomBestHC: public moLocalSearch { diff --git a/trunk/paradiseo-mo/src/algo/moSimpleHC.h b/trunk/paradiseo-mo/src/algo/moSimpleHC.h index 0adc0b960..5e1feae57 100644 --- a/trunk/paradiseo-mo/src/algo/moSimpleHC.h +++ b/trunk/paradiseo-mo/src/algo/moSimpleHC.h @@ -36,6 +36,16 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include +/******************************************************** + * Simple HC: + * Hill-Climber local search + * + * At each iteration, + * the first best solution in the neighborhood is selected + * if the selected neighbor have higher fitness than the current solution + * then the solution is replaced by the selected neighbor + * the algorithm stops when there is no higher neighbor + ********************************************************/ template class moSimpleHC: public moLocalSearch { diff --git a/trunk/paradiseo-mo/src/explorer/moNeutralHCexplorer.h b/trunk/paradiseo-mo/src/explorer/moNeutralHCexplorer.h index ff710cff3..fb8ee7ddb 100644 --- a/trunk/paradiseo-mo/src/explorer/moNeutralHCexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moNeutralHCexplorer.h @@ -73,9 +73,6 @@ public: moRandomBestHCexplorer(_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 << "moNeutralHCexplorer::Warning -> the neighborhood used is not random" << std::endl; - } } /** diff --git a/trunk/paradiseo-mo/src/mo.h b/trunk/paradiseo-mo/src/mo.h index 1530bd0aa..7d109c52a 100755 --- a/trunk/paradiseo-mo/src/mo.h +++ b/trunk/paradiseo-mo/src/mo.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include diff --git a/trunk/paradiseo-mo/tutorial/Lesson1/CMakeLists.txt b/trunk/paradiseo-mo/tutorial/Lesson1/CMakeLists.txt index 8da7be7b1..b86c30e17 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson1/CMakeLists.txt +++ b/trunk/paradiseo-mo/tutorial/Lesson1/CMakeLists.txt @@ -7,9 +7,9 @@ LINK_DIRECTORIES(${EO_BIN_DIR}/lib) ADD_EXECUTABLE(lesson1_simpleHC lesson1_simpleHC.cpp) ADD_EXECUTABLE(lesson1_firstImprHC lesson1_firstImprHC.cpp) ADD_EXECUTABLE(lesson1_randomBestHC lesson1_randomBestHC.cpp) -ADD_EXECUTABLE(lesson1_HCneutral lesson1_HCneutral.cpp) +ADD_EXECUTABLE(lesson1_neutralHC lesson1_neutralHC.cpp) TARGET_LINK_LIBRARIES(lesson1_simpleHC eoutils ga eo) TARGET_LINK_LIBRARIES(lesson1_firstImprHC eoutils ga eo) TARGET_LINK_LIBRARIES(lesson1_randomBestHC eoutils ga eo) -TARGET_LINK_LIBRARIES(lesson1_HCneutral eoutils ga eo) +TARGET_LINK_LIBRARIES(lesson1_neutralHC eoutils ga eo) diff --git a/trunk/paradiseo-mo/tutorial/Lesson1/lesson1_HCneutral.cpp b/trunk/paradiseo-mo/tutorial/Lesson1/lesson1_HCneutral.cpp deleted file mode 100644 index bb99a5ce0..000000000 --- a/trunk/paradiseo-mo/tutorial/Lesson1/lesson1_HCneutral.cpp +++ /dev/null @@ -1,201 +0,0 @@ -//----------------------------------------------------------------------------- -/** testHCneutral.cpp - * - * SV - 24/01/10 - * - */ -//----------------------------------------------------------------------------- - -// standard includes -#define HAVE_SSTREAM - -#include // runtime_error -#include // cout -#include // ostrstream, istrstream -#include -#include - -// the general include for eo -#include -#include - -using namespace std; - -//----------------------------------------------------------------------------- -// fitness function -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -// REPRESENTATION -//----------------------------------------------------------------------------- -typedef eoBit Indi; -typedef moBitNeighbor Neighbor ; // incremental evaluation -typedef moOrderNeighborhood Neighborhood ; - -void main_function(int argc, char **argv) -{ - /* ========================================================= - * - * Parameters - * - * ========================================================= */ - - // 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 - - 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(); - - 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" ); - - // 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 - * - * ========================================================= */ - - //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 - * - * ========================================================= */ - - oneMaxFullEval eval; - - - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ - - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); - - - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ - - moFullEvalByModif fulleval(eval); - - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); - - - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ - - moNeighborComparator comparator; - moSolNeighborComparator solComparator; - - - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ - - Neighborhood neighborhood(vecSize); - - - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moHCneutralExplorer explorer(neighborhood, fulleval, comparator, solComparator, nbStep); - - - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ - - moTrueContinuator continuator;//always continue - - moLocalSearch localSearch(explorer, continuator, eval); - - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ - - Indi solution; - - random(solution); - - //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 ; - -} - -// A main that catches the exceptions - -int main(int argc, char **argv) -{ - try { - main_function(argc, argv); - } - catch (exception& e) { - cout << "Exception: " << e.what() << '\n'; - } - return 1; -} diff --git a/trunk/paradiseo-mo/tutorial/Lesson1/lesson1_firstImpr.cpp b/trunk/paradiseo-mo/tutorial/Lesson1/lesson1_firstImpr.cpp deleted file mode 100644 index 637e46e7f..000000000 --- a/trunk/paradiseo-mo/tutorial/Lesson1/lesson1_firstImpr.cpp +++ /dev/null @@ -1,197 +0,0 @@ -//----------------------------------------------------------------------------- -/** testFirstImpr.cpp - * - * SV - 12/01/10 - * - */ -//----------------------------------------------------------------------------- - -// standard includes -#define HAVE_SSTREAM - -#include // runtime_error -#include // cout -#include // ostrstream, istrstream -#include -#include - -// the general include for eo -#include -#include - -using namespace std; - -//----------------------------------------------------------------------------- -// fitness function -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -// REPRESENTATION -//----------------------------------------------------------------------------- -typedef eoBit Indi; -typedef moBitNeighbor Neighbor ; // incremental evaluation -typedef moRndWithoutReplNeighborhood Neighborhood ; - -void main_function(int argc, char **argv) -{ - /* ========================================================= - * - * Parameters - * - * ========================================================= */ - - // 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 - - 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(); - - // 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 - } - - /* ========================================================= - * - * 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); - - - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ - - oneMaxFullEval eval; - - - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ - - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); - - - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ - - moFullEvalByModif fulleval(eval); - - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); - - - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ - - moNeighborComparator comparator; - moSolNeighborComparator solComparator; - - - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ - - Neighborhood neighborhood(vecSize); - - - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moFirstImprExplorer explorer(neighborhood, fulleval, comparator, solComparator); - - - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ - - moTrueContinuator continuator;//always continue - - moLocalSearch< Neighbor > localSearch(explorer, continuator, eval); - - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ - - Indi solution; - - random(solution); - - //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 ; - -} - -// A main that catches the exceptions - -int main(int argc, char **argv) -{ - try { - main_function(argc, argv); - } - catch (exception& e) { - cout << "Exception: " << e.what() << '\n'; - } - return 1; -} diff --git a/trunk/paradiseo-mo/tutorial/Lesson1/lesson1_neutralHC.cpp b/trunk/paradiseo-mo/tutorial/Lesson1/lesson1_neutralHC.cpp new file mode 100644 index 000000000..42d7c9d51 --- /dev/null +++ b/trunk/paradiseo-mo/tutorial/Lesson1/lesson1_neutralHC.cpp @@ -0,0 +1,200 @@ +//----------------------------------------------------------------------------- +/** lesson1_neutralHC.cpp + * + * SV - 27/04/10 - version 1 + * + */ +//----------------------------------------------------------------------------- + +// standard includes +#define HAVE_SSTREAM + +#include // runtime_error +#include // cout +#include // ostrstream, istrstream +#include +#include + +// the general include for eo +#include + +// declaration of the namespace +using namespace std; + +//----------------------------------------------------------------------------- +// representation of solutions, and neighbors +#include // bit string : see also EO tutorial lesson 1: FirstBitGA.cpp +#include // neighbor of bit string + +//----------------------------------------------------------------------------- +// fitness function, and evaluation of neighbors +#include +#include +#include + +//----------------------------------------------------------------------------- +// neighborhood description +#include // visit all neighbors in increasing order of bit index + +//----------------------------------------------------------------------------- +// the neutral Hill-Climbing local search: move one of random best solution even it is the same fitness +#include + +// Declaration of types +//----------------------------------------------------------------------------- +// Indi is the typedef of the solution type like in paradisEO-eo +typedef eoBit Indi; // bit string with unsigned fitness type +// Neighbor is the typedef of the neighbor type, +// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness) +// all classes from paradisEO-mo use this template type +typedef moBitNeighbor Neighbor ; // bit string neighbor with unsigned fitness type + + +// Main function +//----------------------------------------------------------------------------- +void main_function(int argc, char **argv) +{ + /* ========================================================= + * + * Parameters from parser + * + * ========================================================= */ + // more information on the input parameters: see EO tutorial lesson 3 + // but don't care at first it just read the parameters of the bit string size and the random seed. + + // 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 + + // random seed parameter + eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); + parser.processParam( seedParam ); + unsigned seed = seedParam.value(); + + // length of the bit string + eoValueParam vecSizeParam(20, "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(); + + // 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 + } + + /* ========================================================= + * + * Random seed + * + * ========================================================= */ + + // reproducible random seed: if you don't change SEED above, + // you'll aways get the same result, NOT a random run + // more information: see EO tutorial lesson 1 (FirstBitGA.cpp) + rng.reseed(seed); + + /* ========================================================= + * + * Initialization of the solution + * + * ========================================================= */ + + // a Indi random initializer: each bit is random + // more information: see EO tutorial lesson 1 (FirstBitGA.cpp) + eoUniformGenerator uGen; + eoInitFixedLength random(vecSize, uGen); + + /* ========================================================= + * + * Eval fitness function (full evaluation) + * + * ========================================================= */ + + // the fitness function is just the number of 1 in the bit string + oneMaxFullEval fullEval; + + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ + + // Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution + // moFullEvalByModif neighborEval(fullEval); + + // Incremental evaluation of the neighbor: fitness is modified by +/- 1 + moOneMaxIncrEval neighborEval; + + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ + + // Exploration of the neighborhood in increasing order of the neigbor's index: + // bit-flip from bit 0 to bit (vecSize - 1) + moOrderNeighborhood neighborhood(vecSize); + + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ + + moNeutralHC hc(neighborhood, fullEval, neighborEval, nbStep); + + /* ========================================================= + * + * executes the local search from a random solution + * + * ========================================================= */ + + // The current solution + Indi solution; + + // Apply random initialization + random(solution); + + // Evaluation of the initial solution: + // can be evaluated here, or else it will be done at the beginning of the local search + fullEval(solution); + + // Output: the intial solution + std::cout << "initial: " << solution << std::endl ; + + // Apply the local search on the solution ! + hc(solution); + + // Output: the final solution + std::cout << "final: " << solution << std::endl ; + +} + +// A main that catches the exceptions + +int main(int argc, char **argv) +{ + try { + main_function(argc, argv); + } + catch (exception& e) { + cout << "Exception: " << e.what() << '\n'; + } + return 1; +} diff --git a/trunk/paradiseo-mo/tutorial/Lesson1/testFirstImpr.cpp b/trunk/paradiseo-mo/tutorial/Lesson1/testFirstImpr.cpp deleted file mode 100644 index 637e46e7f..000000000 --- a/trunk/paradiseo-mo/tutorial/Lesson1/testFirstImpr.cpp +++ /dev/null @@ -1,197 +0,0 @@ -//----------------------------------------------------------------------------- -/** testFirstImpr.cpp - * - * SV - 12/01/10 - * - */ -//----------------------------------------------------------------------------- - -// standard includes -#define HAVE_SSTREAM - -#include // runtime_error -#include // cout -#include // ostrstream, istrstream -#include -#include - -// the general include for eo -#include -#include - -using namespace std; - -//----------------------------------------------------------------------------- -// fitness function -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -// REPRESENTATION -//----------------------------------------------------------------------------- -typedef eoBit Indi; -typedef moBitNeighbor Neighbor ; // incremental evaluation -typedef moRndWithoutReplNeighborhood Neighborhood ; - -void main_function(int argc, char **argv) -{ - /* ========================================================= - * - * Parameters - * - * ========================================================= */ - - // 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 - - 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(); - - // 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 - } - - /* ========================================================= - * - * 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); - - - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ - - oneMaxFullEval eval; - - - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ - - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); - - - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ - - moFullEvalByModif fulleval(eval); - - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); - - - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ - - moNeighborComparator comparator; - moSolNeighborComparator solComparator; - - - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ - - Neighborhood neighborhood(vecSize); - - - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moFirstImprExplorer explorer(neighborhood, fulleval, comparator, solComparator); - - - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ - - moTrueContinuator continuator;//always continue - - moLocalSearch< Neighbor > localSearch(explorer, continuator, eval); - - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ - - Indi solution; - - random(solution); - - //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 ; - -} - -// A main that catches the exceptions - -int main(int argc, char **argv) -{ - try { - main_function(argc, argv); - } - catch (exception& e) { - cout << "Exception: " << e.what() << '\n'; - } - return 1; -} diff --git a/trunk/paradiseo-mo/tutorial/Lesson1/testHCneutral.cpp b/trunk/paradiseo-mo/tutorial/Lesson1/testHCneutral.cpp deleted file mode 100644 index bb99a5ce0..000000000 --- a/trunk/paradiseo-mo/tutorial/Lesson1/testHCneutral.cpp +++ /dev/null @@ -1,201 +0,0 @@ -//----------------------------------------------------------------------------- -/** testHCneutral.cpp - * - * SV - 24/01/10 - * - */ -//----------------------------------------------------------------------------- - -// standard includes -#define HAVE_SSTREAM - -#include // runtime_error -#include // cout -#include // ostrstream, istrstream -#include -#include - -// the general include for eo -#include -#include - -using namespace std; - -//----------------------------------------------------------------------------- -// fitness function -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -// REPRESENTATION -//----------------------------------------------------------------------------- -typedef eoBit Indi; -typedef moBitNeighbor Neighbor ; // incremental evaluation -typedef moOrderNeighborhood Neighborhood ; - -void main_function(int argc, char **argv) -{ - /* ========================================================= - * - * Parameters - * - * ========================================================= */ - - // 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 - - 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(); - - 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" ); - - // 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 - * - * ========================================================= */ - - //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 - * - * ========================================================= */ - - oneMaxFullEval eval; - - - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ - - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); - - - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ - - moFullEvalByModif fulleval(eval); - - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); - - - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ - - moNeighborComparator comparator; - moSolNeighborComparator solComparator; - - - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ - - Neighborhood neighborhood(vecSize); - - - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moHCneutralExplorer explorer(neighborhood, fulleval, comparator, solComparator, nbStep); - - - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ - - moTrueContinuator continuator;//always continue - - moLocalSearch localSearch(explorer, continuator, eval); - - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ - - Indi solution; - - random(solution); - - //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 ; - -} - -// A main that catches the exceptions - -int main(int argc, char **argv) -{ - try { - main_function(argc, argv); - } - catch (exception& e) { - cout << "Exception: " << e.what() << '\n'; - } - return 1; -} diff --git a/trunk/paradiseo-mo/tutorial/Lesson1/testRandomBestHC.cpp b/trunk/paradiseo-mo/tutorial/Lesson1/testRandomBestHC.cpp deleted file mode 100644 index 67e0f94df..000000000 --- a/trunk/paradiseo-mo/tutorial/Lesson1/testRandomBestHC.cpp +++ /dev/null @@ -1,197 +0,0 @@ -//----------------------------------------------------------------------------- -/** testRandomBestHC.cpp - * - * SV - 24/01/10 - * - */ -//----------------------------------------------------------------------------- - -// standard includes -#define HAVE_SSTREAM - -#include // runtime_error -#include // cout -#include // ostrstream, istrstream -#include -#include - -// the general include for eo -#include -#include - -using namespace std; - -//----------------------------------------------------------------------------- -// fitness function -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -// REPRESENTATION -//----------------------------------------------------------------------------- -typedef eoBit Indi; -typedef moBitNeighbor Neighbor ; // incremental evaluation -typedef moOrderNeighborhood Neighborhood ; - -void main_function(int argc, char **argv) -{ - /* ========================================================= - * - * Parameters - * - * ========================================================= */ - - // 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 - - 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(); - - // 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 - } - - /* ========================================================= - * - * 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); - - - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ - - oneMaxFullEval eval; - - - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ - - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); - - - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ - - moFullEvalByModif fulleval(eval); - - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); - - - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ - - moNeighborComparator comparator; - moSolNeighborComparator solComparator; - - - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ - - Neighborhood neighborhood(vecSize); - - - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moRandomBestHCExplorer explorer(neighborhood, fulleval, comparator, solComparator); - - - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ - - moTrueContinuator continuator;//always continue - - moLocalSearch localSearch(explorer, continuator, eval); - - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ - - Indi solution; - - random(solution); - - //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 ; - -} - -// A main that catches the exceptions - -int main(int argc, char **argv) -{ - try { - main_function(argc, argv); - } - catch (exception& e) { - cout << "Exception: " << e.what() << '\n'; - } - return 1; -} diff --git a/trunk/paradiseo-mo/tutorial/Lesson1/testSimpleHC.cpp b/trunk/paradiseo-mo/tutorial/Lesson1/testSimpleHC.cpp deleted file mode 100644 index bacd6f311..000000000 --- a/trunk/paradiseo-mo/tutorial/Lesson1/testSimpleHC.cpp +++ /dev/null @@ -1,197 +0,0 @@ -//----------------------------------------------------------------------------- -/** testSimpleHC.cpp - * - * SV - 12/01/10 - * - */ -//----------------------------------------------------------------------------- - -// standard includes -#define HAVE_SSTREAM - -#include // runtime_error -#include // cout -#include // ostrstream, istrstream -#include -#include - -// the general include for eo -#include -#include - -using namespace std; - -//----------------------------------------------------------------------------- -// fitness function -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -// REPRESENTATION -//----------------------------------------------------------------------------- -typedef eoBit Indi; -typedef moBitNeighbor Neighbor ; // incremental evaluation -typedef moOrderNeighborhood Neighborhood ; - -void main_function(int argc, char **argv) -{ - /* ========================================================= - * - * Parameters - * - * ========================================================= */ - - // 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 - - 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(); - - // 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 - } - - /* ========================================================= - * - * 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); - - - /* ========================================================= - * - * Eval fitness function - * - * ========================================================= */ - - oneMaxFullEval eval; - - - /* ========================================================= - * - * Initilisation of the solution - * - * ========================================================= */ - - // a Indi random initializer - eoUniformGenerator uGen; - eoInitFixedLength random(vecSize, uGen); - - - /* ========================================================= - * - * evaluation of a neighbor solution - * - * ========================================================= */ - - moFullEvalByModif fulleval(eval); - - //An eval by copy can be used instead of the eval by modif - //moFullEvalByCopy fulleval(eval); - - - /* ========================================================= - * - * Comparator of neighbors - * - * ========================================================= */ - - moNeighborComparator comparator; - moSolNeighborComparator solComparator; - - - /* ========================================================= - * - * the neighborhood of a solution - * - * ========================================================= */ - - Neighborhood neighborhood(vecSize); - - - /* ========================================================= - * - * a neighborhood explorer solution - * - * ========================================================= */ - - moSimpleHCexplorer explorer(neighborhood, fulleval, comparator, solComparator); - - - /* ========================================================= - * - * the local search algorithm - * - * ========================================================= */ - - moTrueContinuator continuator;//always continue - - moLocalSearch< Neighbor > localSearch(explorer, continuator, eval); - - /* ========================================================= - * - * execute the local search from random sollution - * - * ========================================================= */ - - Indi solution; - - random(solution); - - //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 ; - -} - -// A main that catches the exceptions - -int main(int argc, char **argv) -{ - try { - main_function(argc, argv); - } - catch (exception& e) { - cout << "Exception: " << e.what() << '\n'; - } - return 1; -}