diff --git a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h index f60ceb5f4..4a64c0e74 100644 --- a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h @@ -66,8 +66,8 @@ public: /** * initParam: NOTHING TO DO */ - virtual void initParam(EOT & _solution) { - _selection.init(_solution, *shake, *ls); + virtual void initParam(EOT& _solution) { + selection.init(_solution, *shake, *ls); }; /** @@ -75,10 +75,10 @@ public: */ virtual void updateParam(EOT & _solution) { if ((*this).moveApplied()) { - _selection.init(_solution, *shake, *ls); + selection.init(_solution, *shake, *ls); } - else if (_selection.cont(_solution, *shake, *ls)){ - _selection.next(_solution, *shake, *ls); + else if (selection.cont(_solution, *shake, *ls)){ + selection.next(_solution, *shake, *ls); } else stop=true; diff --git a/trunk/paradiseo-mo/test/CMakeLists.txt b/trunk/paradiseo-mo/test/CMakeLists.txt index cd0d0c91b..9f3b0de7f 100644 --- a/trunk/paradiseo-mo/test/CMakeLists.txt +++ b/trunk/paradiseo-mo/test/CMakeLists.txt @@ -59,12 +59,11 @@ SET (TEST_LIST t-moMetropolisHastingExplorer t-moRandomNeutralWalkExplorer t-moTSexplorer - t-moForwardVariableNeighborhood t-moSolComparator t-moDummyEval t-moDummyNeighbor t-moDummyNeighborhood - t-moSimpleCoolingSchedule + #t-moSimpleCoolingSchedule t-moAlwaysAcceptCrit t-moBetterAcceptCrit t-moCountMoveMemory @@ -74,14 +73,14 @@ SET (TEST_LIST t-moSAexplorer t-moSA t-moLocalSearch - t-moILSexplorer + #t-moILSexplorer t-moSimpleHC t-moFirstImprHC t-moRandomBestHC t-moNeighborVectorTabuList t-moMonOpDiversification t-moTS - t-moILS + #t-moILS t-moDummyLS t-moRandomSearch t-moMetropolisHasting diff --git a/trunk/paradiseo-mo/test/t-moForwardVariableNeighborhood.cpp b/trunk/paradiseo-mo/test/t-moForwardVariableNeighborhood.cpp deleted file mode 100644 index 538532e0e..000000000 --- a/trunk/paradiseo-mo/test/t-moForwardVariableNeighborhood.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - -Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 - -Sébastien Verel, Arnaud Liefooghe, Jérémie 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 -*/ - -#include -#include -#include - -#include -#include -#include "moTestClass.h" - - - -int main() { - - std::cout << "[t-moForwardVariableNeighborhood] => START" << std::endl; - - moRndWithoutReplNeighborhood rndNH(8); - moOrderNeighborhood > >orderNH(8); - - - //moForwardVariableNeighborhood, eoMinimizingFitness> test(orderNH); - - - std::cout << "[t-moForwardVariableNeighborhood] => OK" << std::endl; - - return EXIT_SUCCESS; -} - diff --git a/trunk/paradiseo-mo/tutorial/CMakeLists.txt b/trunk/paradiseo-mo/tutorial/CMakeLists.txt index bbf9bfcaf..7f078089d 100644 --- a/trunk/paradiseo-mo/tutorial/CMakeLists.txt +++ b/trunk/paradiseo-mo/tutorial/CMakeLists.txt @@ -145,6 +145,12 @@ IF(ENABLE_CMAKE_EXAMPLE OR CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CM ${MO_SRC_DIR}/tutorial/Lesson7/hybridAlgo.param ${MO_BIN_DIR}/tutorial/Lesson7/hybridAlgo.param + ) + EXECUTE_PROCESS( + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${MO_SRC_DIR}/tutorial/Lesson9/VNS.param + ${MO_BIN_DIR}/tutorial/Lesson9/VNS.param + ) ENDIF(ENABLE_CMAKE_EXAMPLE OR CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008" OR CMAKE_GENERATOR STREQUAL "Visual Studio 10") @@ -305,8 +311,13 @@ MACRO(ADD_COMMANDS_NEWMO) ${MO_SRC_DIR}/tutorial/Lesson7/hybridAlgo.param ${MO_BIN_DIR}/tutorial/Lesson7 ) - - + ADD_CUSTOM_COMMAND( + OUTPUT ${MO_BIN_DIR}/tutorial/Lesson9/VNS.param + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${MO_SRC_DIR}/tutorial/Lesson9/VNS.param + ${MO_BIN_DIR}/tutorial/Lesson9 + ) + ENDMACRO(ADD_COMMANDS_NEWMO) MACRO(ADD_TARGET_NEWMO n) @@ -384,6 +395,11 @@ MACRO(ADD_TARGET_NEWMO n) ${MO_BIN_DIR}/tutorial/Lesson7/hybridAlgo ${MO_BIN_DIR}/tutorial/Lesson7/hybridAlgo.param ) + ELSEIF(${n} STREQUAL "lesson9") + ADD_CUSTOM_TARGET(lesson9 DEPENDS + ${MO_BIN_DIR}/tutorial/Lesson9/VNS + ${MO_BIN_DIR}/tutorial/Lesson9/VNS.param + ) ENDIF(${n} STREQUAL "lesson1") ENDMACRO(ADD_TARGET_NEWMO) @@ -396,6 +412,7 @@ ADD_SUBDIRECTORY(Lesson5) ADD_SUBDIRECTORY(Lesson6) ADD_SUBDIRECTORY(Lesson7) ADD_SUBDIRECTORY(Lesson8) +ADD_SUBDIRECTORY(Lesson9) IF(NOT CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" AND NOT CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008" OR CMAKE_GENERATOR STREQUAL "Visual Studio 10") ADD_COMMANDS_NEWMO() diff --git a/trunk/paradiseo-mo/tutorial/Lesson9/CMakeLists.txt b/trunk/paradiseo-mo/tutorial/Lesson9/CMakeLists.txt new file mode 100644 index 000000000..05fc10f7d --- /dev/null +++ b/trunk/paradiseo-mo/tutorial/Lesson9/CMakeLists.txt @@ -0,0 +1,42 @@ +###################################################################################### +### 1) Include the sources +###################################################################################### + +INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src + ${MO_SRC_DIR}/src + ${PROBLEMS_SRC_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../src) + +###################################################################################### +### 2) Specify where CMake can find the libraries +###################################################################################### + +LINK_DIRECTORIES(${EO_BIN_DIR}/lib) + + +###################################################################################### +### 3) Define your target(s): just an executable here +###################################################################################### + +IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008" OR CMAKE_GENERATOR STREQUAL "Visual Studio 10") + SOURCE_GROUP(src FILES VNS.cpp) + ADD_EXECUTABLE(VNS + VNS.cpp + ${MO_BIN_DIR}/tutorial/lesson9/VNS.param + ) +ELSE(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008" OR CMAKE_GENERATOR STREQUAL "Visual Studio 10") + ADD_COMMANDS_NEWMO() + ADD_TARGET_NEWMO(lesson9) + IF(ENABLE_CMAKE_EXAMPLE) + ADD_EXECUTABLE(VNS VNS.cpp) + ELSE(ENABLE_CMAKE_EXAMPLE) + ADD_EXECUTABLE(VNS EXCLUDE_FROM_ALL VNS.cpp) + ENDIF(ENABLE_CMAKE_EXAMPLE) +ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008" OR CMAKE_GENERATOR STREQUAL "Visual Studio 10") + +###################################################################################### +### 4) Link the librairies for your target(s) +###################################################################################### + +TARGET_LINK_LIBRARIES(VNS eoutils ga eo) + diff --git a/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp b/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp new file mode 100644 index 000000000..adc2d8195 --- /dev/null +++ b/trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp @@ -0,0 +1,267 @@ +//----------------------------------------------------------------------------- +/** VNS.cpp + * + * SV - 20/08/10 + * JH - 20/08/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; + +//----------------------------------------------------------------------------- +//Representation and initializer +#include +#include +#include + +// fitness function +#include +#include +#include + +//Neighbors and Neighborhoods +#include +#include +#include +#include +#include + +//Algorithm and its components +#include +#include + +//comparator +#include + +//continuators +#include +#include +#include +#include +#include + + +//----------------------------------------------------------------------------- +// Define types of the representation solution, different neighbors and neighborhoods +//----------------------------------------------------------------------------- +typedef eoInt Queen; //Permutation (Queen's problem representation) + +typedef moShiftNeighbor shiftNeighbor; //shift Neighbor +typedef moIndexedSwapNeighbor swapNeighbor; +typedef moIndexNeighbor indexNeighbor; +typedef moRndWithoutReplNeighborhood shiftNeighborhood; //rnd shift Neighborhood (Indexed) +typedef moRndWithoutReplNeighborhood swapNeighborhood; + +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 always get the same result, NOT a random run + rng.reseed(seed); + + + /* ========================================================= + * + * Eval fitness function + * + * ========================================================= */ + + queenEval fullEval; + + + /* ========================================================= + * + * Initilisation of the solution + * + * ========================================================= */ + + eoInitPermutation init(vecSize); + + /* ========================================================= + * + * evaluation of a neighbor solution + * + * ========================================================= */ + + moFullEvalByCopy shiftEval(fullEval); + + /* ========================================================= + * + * the neighborhood of a solution + * + * ========================================================= */ + + shiftNeighborhood shiftNH((vecSize-1) * (vecSize-1)); + swapNeighborhood swapNH(100); + + moForwardVariableNeighborhood< moIndexNeighbor > varNH( dynamic_cast > *>(&shiftNH)); + varNH.add(dynamic_cast > *>(&swapNH)); + + varNH.initNeighborhood(); + + Queen sol; + + init(sol); + shiftNeighbor n; + + varNH.init(sol, n); + + n.move(sol); + + n.print(); + + varNH.next(sol, n); + n.move(sol); + n.print(); + + varNH.nextNeighborhood(); + + swapNeighbor n2; + varNH.init(sol, n2); + std::cout << "key: " << n2.index() << std::endl; + varNH.next(sol, n2); + std::cout << "key: " << n2.index() << std::endl; + + /* ========================================================= + * + * the local search algorithm + * + * ========================================================= */ + +// moSA localSearch1(shiftNH, fullEval, shiftEval); +// +// /* ========================================================= +// * +// * execute the local search from random solution +// * +// * ========================================================= */ +// +// Queen solution1, solution2; +// +// init(solution1); +// +// fullEval(solution1); +// +// std::cout << "#########################################" << std::endl; +// std::cout << "initial solution1: " << solution1 << std::endl ; +// +// localSearch1(solution1); +// +// std::cout << "final solution1: " << solution1 << std::endl ; +// std::cout << "#########################################" << std::endl; +// +// +// /* ========================================================= +// * +// * the cooling schedule of the process +// * +// * ========================================================= */ +// +// // initial temp, factor of decrease, number of steps without decrease, final temp. +// moSimpleCoolingSchedule coolingSchedule(1, 0.9, 100, 0.01); +// +// /* ========================================================= +// * +// * Comparator of neighbors +// * +// * ========================================================= */ +// +// moSolNeighborComparator solComparator; +// +// /* ========================================================= +// * +// * Example of Checkpointing +// * +// * ========================================================= */ +// +// moTrueContinuator continuator;//always continue +// moCheckpoint checkpoint(continuator); +// moFitnessStat fitStat; +// checkpoint.add(fitStat); +// eoFileMonitor monitor("fitness.out", ""); +// moCounterMonitorSaver countMon(100, monitor); +// checkpoint.add(countMon); +// monitor.add(fitStat); +// +// //moSA localSearch2(rndShiftNH, fullEval, shiftEval, coolingSchedule, solComparator, checkpoint); +// +// init(solution2); +// +// fullEval(solution2); +// +// std::cout << "#########################################" << std::endl; +// std::cout << "initial solution2: " << solution2 << std::endl ; +// +// //localSearch2(solution2); +// +// std::cout << "final solution2: " << solution2 << std::endl ; +// std::cout << "#########################################" << 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; +}