From ff7b15fe228fe12e5db4263843cbd581fb609876 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Fri, 4 Jun 2010 13:17:42 +0000 Subject: [PATCH] Ajout d'une Lesson sur les DMLS git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1840 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-moeo/CMakeLists.txt | 8 +- .../moeoFirstImprovingNeighborhoodExplorer.h | 1 + .../src/utils/moeoFullEvalByCopy.h | 48 ++++++ trunk/paradiseo-moeo/tutorial/CMakeLists.txt | 28 ++++ .../{Lesson3 => Lesson4}/CMakeLists.txt | 22 +-- .../tutorial/Lesson4/FlowShopDMLS.cpp | 149 ++++++++++++++++++ 6 files changed, 241 insertions(+), 15 deletions(-) create mode 100644 trunk/paradiseo-moeo/src/utils/moeoFullEvalByCopy.h rename trunk/paradiseo-moeo/tutorial/{Lesson3 => Lesson4}/CMakeLists.txt (87%) create mode 100644 trunk/paradiseo-moeo/tutorial/Lesson4/FlowShopDMLS.cpp diff --git a/trunk/paradiseo-moeo/CMakeLists.txt b/trunk/paradiseo-moeo/CMakeLists.txt index 26e8edbfa..db54aefc9 100644 --- a/trunk/paradiseo-moeo/CMakeLists.txt +++ b/trunk/paradiseo-moeo/CMakeLists.txt @@ -18,10 +18,10 @@ PROJECT(ParadisEO-MOEO) SET(PACKAGE_BUGREPORT "paradiseo-help@lists.gforge.inria.fr" CACHE STRING "Package bug report" FORCE) SET(PACKAGE_NAME "ParadisEO-MOEO - Multi Objective Evolving Objects" CACHE STRING "Package name" FORCE) -SET(PACKAGE_STRING "ParadisEO-MOEO 1.2" CACHE STRING "MOEO Package string full name" FORCE) -SET(PACKAGE_VERSION "1.2" CACHE STRING "Package version" FORCE) -SET(GLOBAL_VERSION "1.2" CACHE STRING "Global version" FORCE) -SET(VERSION "1.2" CACHE STRING "Version" FORCE) +SET(PACKAGE_STRING "ParadisEO-MOEO 1.3" CACHE STRING "MOEO Package string full name" FORCE) +SET(PACKAGE_VERSION "1.3" CACHE STRING "Package version" FORCE) +SET(GLOBAL_VERSION "1.3" CACHE STRING "Global version" FORCE) +SET(VERSION "1.3" CACHE STRING "Version" FORCE) ########################################################################################################################################## diff --git a/trunk/paradiseo-moeo/src/explorer/moeoFirstImprovingNeighborhoodExplorer.h b/trunk/paradiseo-moeo/src/explorer/moeoFirstImprovingNeighborhoodExplorer.h index 61db2973c..fdc3ad4e7 100644 --- a/trunk/paradiseo-moeo/src/explorer/moeoFirstImprovingNeighborhoodExplorer.h +++ b/trunk/paradiseo-moeo/src/explorer/moeoFirstImprovingNeighborhoodExplorer.h @@ -110,6 +110,7 @@ private: _dest.back().objectiveVector(neighbor.fitness()); //fix its flag to 0 (unvisited solution) _dest.back().flag(0); + _dest.back().fitness(0); } } diff --git a/trunk/paradiseo-moeo/src/utils/moeoFullEvalByCopy.h b/trunk/paradiseo-moeo/src/utils/moeoFullEvalByCopy.h new file mode 100644 index 000000000..f681212ee --- /dev/null +++ b/trunk/paradiseo-moeo/src/utils/moeoFullEvalByCopy.h @@ -0,0 +1,48 @@ +#ifndef moeoFullEvalByCopy_H +#define moeoFullEvalByCopy_H + +#include +#include + +/** + * Evaluation by copy + */ +template +class moeoFullEvalByCopy : public moEval +{ +public: + typedef typename moEval::EOT EOT; + typedef typename moEval::Fitness Fitness; + + /** + * Ctor + * @param _eval the full evaluation object + */ + moeoFullEvalByCopy(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.objectiveVector()); + } + + +private: + /** the full evaluation object */ + eoEvalFunc & eval; + +}; + +#endif diff --git a/trunk/paradiseo-moeo/tutorial/CMakeLists.txt b/trunk/paradiseo-moeo/tutorial/CMakeLists.txt index dea0167c2..6b78db2c0 100644 --- a/trunk/paradiseo-moeo/tutorial/CMakeLists.txt +++ b/trunk/paradiseo-moeo/tutorial/CMakeLists.txt @@ -47,6 +47,9 @@ IF(ENABLE_CMAKE_EXAMPLE OR CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CM COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ParadisEO-MOEO_SOURCE_DIR}/tutorial/Lesson3/FlowShopEA2.param ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson3/FlowShopEA2.param + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${ParadisEO-MOEO_SOURCE_DIR}/tutorial/Lesson4/FlowShopDMLS.param + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson4/FlowShopDMLS.param ) ENDIF(ENABLE_CMAKE_EXAMPLE OR CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008") @@ -127,6 +130,13 @@ MACRO(ADD_COMMANDS_MOEO) ${ParadisEO-MOEO_SOURCE_DIR}/tutorial/Lesson3/FlowShopEA2.param ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson3 ) + + ADD_CUSTOM_COMMAND( + OUTPUT ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson4/FlowShopDMLS.param + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${ParadisEO-MOEO_SOURCE_DIR}/tutorial/Lesson4/FlowShopDMLS.param + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson4 + ) ENDMACRO(ADD_COMMANDS_MOEO) MACRO(ADD_TARGET_MOEO n) @@ -169,6 +179,23 @@ MACRO(ADD_TARGET_MOEO n) ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/100_20_01.txt ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/200_10_01.txt ) + ELSEIF(${n} STREQUAL "lesson4") + ADD_CUSTOM_TARGET(lesson4 DEPENDS + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson4/FlowShopDMLS + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson4/FlowShopDMLS.param + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_05_01.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_05_02.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_10_01.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_10_02.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_20_01.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/050_05_01.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/050_10_01.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/050_20_01.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/100_05_01.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/100_10_01.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/100_20_01.txt + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/200_10_01.txt + ) ELSEIF(${n} STREQUAL "install") ADD_CUSTOM_TARGET(install DEPENDS ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson1/Sch1.param @@ -215,6 +242,7 @@ ADD_SUBDIRECTORY(examples) ADD_SUBDIRECTORY(Lesson1) ADD_SUBDIRECTORY(Lesson2) ADD_SUBDIRECTORY(Lesson3) +ADD_SUBDIRECTORY(Lesson4) ###################################################################################### diff --git a/trunk/paradiseo-moeo/tutorial/Lesson3/CMakeLists.txt b/trunk/paradiseo-moeo/tutorial/Lesson4/CMakeLists.txt similarity index 87% rename from trunk/paradiseo-moeo/tutorial/Lesson3/CMakeLists.txt rename to trunk/paradiseo-moeo/tutorial/Lesson4/CMakeLists.txt index da3de04c1..75ff3caf4 100644 --- a/trunk/paradiseo-moeo/tutorial/Lesson3/CMakeLists.txt +++ b/trunk/paradiseo-moeo/tutorial/Lesson4/CMakeLists.txt @@ -17,7 +17,7 @@ LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${ParadisEO-MOEO_BINARY_DIR}/lib ${FLOWSHOP_B ###################################################################################### IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008") - SOURCE_GROUP(src FILES FlowShopEA2.cpp) + SOURCE_GROUP(src FILES FlowShopDMLS.cpp) SOURCE_GROUP(benchs FILES ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_05_01.txt ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_05_02.txt @@ -32,9 +32,9 @@ IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL " ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/100_20_01.txt ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/200_10_01.txt ) - ADD_EXECUTABLE(FlowShopEA2 - FlowShopEA2.cpp - ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson3/FlowShopEA2.param + ADD_EXECUTABLE(FlowShopDMLS + FlowShopDMLS.cpp + ${ParadisEO-MOEO_BINARY_DIR}/tutorial/Lesson4/FlowShopDMLS.param ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_05_01.txt ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_05_02.txt ${ParadisEO-MOEO_BINARY_DIR}/tutorial/examples/flowshop/benchs/020_10_01.txt @@ -50,27 +50,27 @@ IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL " ) ELSE(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008") ADD_COMMANDS_MOEO() - ADD_TARGET_MOEO(lesson3) + ADD_TARGET_MOEO(lesson4) IF(ENABLE_CMAKE_EXAMPLE) - ADD_EXECUTABLE(FlowShopEA2 FlowShopEA2.cpp) + ADD_EXECUTABLE(FlowShopDMLS FlowShopDMLS.cpp) ELSE(ENABLE_CMAKE_EXAMPLE) - ADD_EXECUTABLE(FlowShopEA2 EXCLUDE_FROM_ALL FlowShopEA2.cpp) + ADD_EXECUTABLE(FlowShopDMLS EXCLUDE_FROM_ALL FlowShopDMLS.cpp) ENDIF(ENABLE_CMAKE_EXAMPLE) ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008") -ADD_DEPENDENCIES(FlowShopEA2 flowshop moeo) +ADD_DEPENDENCIES(FlowShopDMLS flowshop moeo) ###################################################################################### ### 4) Optionnal: define your target(s)'s version: no effect for windows ###################################################################################### -SET(FlowShopEA2_VERSION ${GLOBAL_VERSION}) -SET_TARGET_PROPERTIES(FlowShopEA2 PROPERTIES VERSION "${FlowShopEA2_VERSION}") +SET(FlowShopDMLS_VERSION ${GLOBAL_VERSION}) +SET_TARGET_PROPERTIES(FlowShopDMLS PROPERTIES VERSION "${FlowShopDMLS_VERSION}") ###################################################################################### ### 5) Link the librairies for your target(s) ###################################################################################### -TARGET_LINK_LIBRARIES(FlowShopEA2 moeo flowshop eo eoutils) +TARGET_LINK_LIBRARIES(FlowShopDMLS moeo flowshop eo eoutils) ###################################################################################### diff --git a/trunk/paradiseo-moeo/tutorial/Lesson4/FlowShopDMLS.cpp b/trunk/paradiseo-moeo/tutorial/Lesson4/FlowShopDMLS.cpp new file mode 100644 index 000000000..728ab8cd1 --- /dev/null +++ b/trunk/paradiseo-moeo/tutorial/Lesson4/FlowShopDMLS.cpp @@ -0,0 +1,149 @@ +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 +* (C) OPAC Team, LIFL, 2002-2007 +* +* 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 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, +* 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 +* +*/ +//----------------------------------------------------------------------------- + + +// moeo general include +#include +// for the creation of an evaluator +#include +// for the creation of an initializer +#include +// for the creation of the variation operators +#include +// how to initialize the population +#include +// checks for help demand, and writes the status file and make_help; in libutils +void make_help(eoParser & _parser); +// definition of the representation +#include + +#include +#include +#include + +using namespace std; + + +int main(int argc, char* argv[]) +{ + try + { + + //define a neighbor + typedef moShiftNeighbor Neighbor; + + + eoParser parser(argc, argv); // for user-parameter reading + eoState state; // to keep all things allocated + + + /*** the representation-dependent things ***/ + + // The fitness evaluation + eoEvalFuncCounter& eval = do_make_eval(parser, state); + // the genotype (through a genotype initializer) + eoInit& init = do_make_genotype(parser, state); + // the variation operators + eoGenOp& op = do_make_op(parser, state); + + + /*** the representation-independent things ***/ + + // initialization of the population + eoPop& pop = do_make_pop(parser, state, init); + // definition of the archive + moeoUnboundedArchive arch; + // stopping criteria + unsigned int maxGen = parser.createParam((unsigned int)(100), "maxGen", "Maximum number of gen.",'G',"Stopping criterion").value(); + eoGenContinue term(maxGen); + unsigned int nhSize = parser.createParam((unsigned int)(20), "nhSize", "neighborhood size",'G',"Evolution Engine").value(); + // checkpointing + eoCheckPoint checkpoint(term); + moeoArchiveUpdater < FlowShop > updater(arch, pop); + checkpoint.add(updater); + + //neighborhood + moOrderNeighborhood neighborhood((nhSize-1) * (nhSize-1)); //!!!!!!!!!!!!!!!CHANGER CET VALEUR PAR RAPPORT AU PARAM + //neighbor Evaluation function + moeoFullEvalByCopy moEval(eval); + //Selection in the archive + moeoNumberUnvisitedSelect select(1); + //explorer + moeoFirstImprovingNeighborhoodExplorer explor(neighborhood, moEval); + + moeoUnifiedDominanceBasedLS algo(checkpoint, eval, arch, explor, select); + + + /*** Go ! ***/ + + // help ? + make_help(parser); + + // first evalution (for printing) + apply(eval, pop); + for(int i=0; i