From 127a53f33b37d101a473dbc6dd5957dec1e2c339 Mon Sep 17 00:00:00 2001 From: jboisson Date: Tue, 4 Mar 2008 08:51:52 +0000 Subject: [PATCH] MO has really five lessons ;-) , some files have been added git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1056 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-mo/CMakeLists.txt | 153 ++++++++++++++-- trunk/paradiseo-mo/test/CMakeLists.txt | 40 ++--- .../tutorial/Lesson2/hill_climbing.cpp | 149 ++++++++++++++++ .../tutorial/Lesson3/tabu_search.cpp | 160 +++++++++++++++++ .../tutorial/Lesson4/simulated_annealing.cpp | 163 ++++++++++++++++++ .../tutorial/examples/function/CMakeLists.txt | 12 +- .../tutorial/examples/tsp/CMakeLists.txt | 30 ++-- 7 files changed, 652 insertions(+), 55 deletions(-) create mode 100644 trunk/paradiseo-mo/tutorial/Lesson2/hill_climbing.cpp create mode 100644 trunk/paradiseo-mo/tutorial/Lesson3/tabu_search.cpp create mode 100644 trunk/paradiseo-mo/tutorial/Lesson4/simulated_annealing.cpp diff --git a/trunk/paradiseo-mo/CMakeLists.txt b/trunk/paradiseo-mo/CMakeLists.txt index 6013d3ab4..aeacd2e96 100644 --- a/trunk/paradiseo-mo/CMakeLists.txt +++ b/trunk/paradiseo-mo/CMakeLists.txt @@ -1,32 +1,63 @@ -########################################################################################################################################## +###################################################################################### ### 0) If you want to set your own variables in mo-conf.cmake and avoid the cmd line -########################################################################################################################################## +###################################################################################### INCLUDE(mo-conf.cmake OPTIONAL) -########################################################################################################################################## +###################################################################################### -########################################################################################################################################## +###################################################################################### ### 1) Project properties -########################################################################################################################################## +###################################################################################### # set the project name PROJECT(ParadisEO-MO) SET(PACKAGE_BUGREPORT "paradiseo-help@lists.gforge.inria.fr" CACHE STRING "Package bug report" FORCE) SET(PACKAGE_NAME "ParadisEO-MO - Moving Objects" CACHE STRING "Package name" FORCE) -SET(PACKAGE_STRING "ParadisEO-MO 1.1" CACHE STRING "MO Package string full name" FORCE) -SET(PACKAGE_VERSION "1.1" CACHE STRING "Package version" FORCE) -SET(GLOBAL_VERSION "1.1" CACHE STRING "Global version" FORCE) -SET(VERSION "1.1" CACHE STRING "Version" FORCE) -########################################################################################################################################## +SET(PACKAGE_STRING "ParadisEO-MO 1.0" CACHE STRING "Package string full name" FORCE) +SET(PACKAGE_VERSION "1.0" CACHE STRING "Package version" FORCE) +SET(GLOBAL_VERSION "1.0" CACHE STRING "Global version" FORCE) +SET(VERSION "1.0" CACHE STRING "Version" FORCE) + +# check cmake version compatibility +CMAKE_MINIMUM_REQUIRED(VERSION 2.4 FATAL_ERROR) + +# regular expression checking +INCLUDE_REGULAR_EXPRESSION("^.*$" "^$") + +# set a language for the entire project. +ENABLE_LANGUAGE(CXX) +ENABLE_LANGUAGE(C) + +##################################################################################### -########################################################################################################################################## -### 2) Include the common CMake configuration -########################################################################################################################################## +##################################################################################### +### 2) Include required modules +##################################################################################### + +INCLUDE(CMakeBackwardCompatibilityCXX) + +INCLUDE(FindDoxygen) + +INCLUDE(FindGnuplot) + +# check for some functions +INCLUDE(CheckLibraryExists) + +INCLUDE(Dart OPTIONNAL) + +# the project can have a DartConfig.cmake file +INCLUDE(DartConfig.cmake OPTIONNAL) +###################################################################################### + + +###################################################################################### +### 3) Include the main configuration variables +###################################################################################### # The "config" variable must be provided on the command line IF(NOT DEFINED config OR NOT config) @@ -36,5 +67,99 @@ ENDIF(NOT DEFINED config OR NOT config) # Need the config file whose full path is given thanks to the "config" variable INCLUDE(${config}) -########################################################################################################################################## +###################################################################################### + + +###################################################################################### +### 4) Paths checking +###################################################################################### + +IF(WIN32) + SET (ABSOLUTE_PATH_REGEX "^[A-Z]:|^[a-z]:") +ELSE(WIN32) + SET (ABSOLUTE_PATH_REGEX "^/") +ENDIF(WIN32) + +SET(REQUIRED_PATHS "EO_SRC_DIR" "EO_BIN_DIR") +FOREACH (path ${REQUIRED_PATHS}) + IF(EXISTS ${${path}}) + MESSAGE (STATUS "Using ${path}=${${path}}") + ELSE(EXISTS ${${path}}) + MESSAGE (FATAL_ERROR "\n Cannot find \"${${path}}\". Please, fill \"${config}\" with a correct value") + ENDIF(EXISTS ${${path}}) + + IF(NOT ${${path}} MATCHES "${ABSOLUTE_PATH_REGEX}") + MESSAGE (FATAL_ERROR "${${path}} MUST BE an absolute path") + ENDIF(NOT ${${path}} MATCHES "${ABSOLUTE_PATH_REGEX}") +ENDFOREACH (path ${REQUIRED_PATHS}) +###################################################################################### + + +##################################################################################### +### 5) Manage the build type +##################################################################################### + +# the user should choose the build type on windows environments,excepted under cygwin (default=none) +SET(CMAKE_DEFAULT_BUILD_TYPE "Release" CACHE STRING "Variable that stores the default CMake build type" FORCE) + +FIND_PROGRAM(MEMORYCHECK_COMMAND + NAMES purify valgrind + PATHS + "/usr/local/bin /usr/bin [HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder]" + DOC "Path to the memory checking command, used for memory error detection.") +IF(NOT CMAKE_BUILD_TYPE) + SET( CMAKE_BUILD_TYPE + ${CMAKE_DEFAULT_BUILD_TYPE} CACHE STRING + "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." + FORCE) +ENDIF(NOT CMAKE_BUILD_TYPE) + +IF(WIN32 AND NOT CYGWIN) + IF(CMAKE_CXX_COMPILER MATCHES cl) + IF(NOT WITH_SHARED_LIBS) + IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005") + SET(CMAKE_CXX_FLAGS "/nologo /W3 /Gy") + SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od") + SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2") + SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2") + SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE") + ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005") + ENDIF(NOT WITH_SHARED_LIBS) + ENDIF(CMAKE_CXX_COMPILER MATCHES cl) +ELSE(WIN32 AND NOT CYGWIN) + IF(CMAKE_COMPILER_IS_GNUCXX) + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -Wall -pedantic -Wextra -Wno-import -Winit-self -Wmissing-include-dirs -Wunused-parameter -Wundef -Wshadow -Wunsafe-loop-optimizations -Wcast-align -Wconversion -Wsign-compare -Winline -Wdisabled-optimization") + SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") + SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -O6") + ENDIF(CMAKE_COMPILER_IS_GNUCXX) +ENDIF(WIN32 AND NOT CYGWIN) + +IF(CMAKE_BUILD_TYPE MATCHES Debug) + ADD_DEFINITIONS(-DCMAKE_VERBOSE_MAKEFILE=ON) +ENDIF(CMAKE_BUILD_TYPE MATCHES Debug) + +##################################################################################### + + +###################################################################################### +### 6) Where must cmake go now ? +###################################################################################### + +SUBDIRS(doc test tutorial) + +###################################################################################### + + +###################################################################################### +### 7) Test config +###################################################################################### + +#SET(ENABLE_CMAKE_TESTING TRUE CACHE BOOL "Should we test using Dart") + +IF (ENABLE_CMAKE_TESTING) + ENABLE_TESTING() +ENDIF (ENABLE_CMAKE_TESTING) + +###################################################################################### diff --git a/trunk/paradiseo-mo/test/CMakeLists.txt b/trunk/paradiseo-mo/test/CMakeLists.txt index 9d46369d5..0a6591d60 100644 --- a/trunk/paradiseo-mo/test/CMakeLists.txt +++ b/trunk/paradiseo-mo/test/CMakeLists.txt @@ -40,27 +40,27 @@ ENDIF(WIN32 AND NOT CYGWIN) ###################################################################################### SET (TEST_LIST t-moBestImprSelect - t-moExponentialCoolingSchedule - t-moFirstImprSelect - t-moFitComparator - t-moFitSolContinue - t-moGenSolContinue - t-moHC - t-moHCMoveLoopExpl - t-moILS - t-moImprBestFitAspirCrit - t-moItRandNextMove - t-moLinearCoolingSchedule - t-moLSCheckPoint - t-moNoAspirCrit - t-moNoFitImprSolContinue - t-moRandImprSelect - t-moSA - t-moSimpleMoveTabuList - t-moSimpleSolutionTabuList + t-moExponentialCoolingSchedule + t-moFirstImprSelect + t-moFitComparator + t-moFitSolContinue + t-moGenSolContinue + t-moHC + t-moHCMoveLoopExpl + t-moILS + t-moImprBestFitAspirCrit + t-moItRandNextMove + t-moLinearCoolingSchedule + t-moLSCheckPoint + t-moNoAspirCrit + t-moNoFitImprSolContinue + t-moRandImprSelect + t-moSA + t-moSimpleMoveTabuList + t-moSimpleSolutionTabuList t-moSteadyFitSolContinue - t-moTS - t-moTSMoveLoopExpl ) + t-moTS + t-moTSMoveLoopExpl ) FOREACH (test ${TEST_LIST}) SET ("T_${test}_SOURCES" "${test}.cpp") diff --git a/trunk/paradiseo-mo/tutorial/Lesson2/hill_climbing.cpp b/trunk/paradiseo-mo/tutorial/Lesson2/hill_climbing.cpp new file mode 100644 index 000000000..7a29c8694 --- /dev/null +++ b/trunk/paradiseo-mo/tutorial/Lesson2/hill_climbing.cpp @@ -0,0 +1,149 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008 + (C) OPAC Team, LIFL, 2002-2008 + + Sébastien Cahon, Jean-Charles Boisson + + 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 +*/ + +#include +#include +#include + +void manage_configuration_file(eoParser & _parser); + +int +main (int _argc, char* _argv []) +{ + std::string instancePath, selectionType; + unsigned int seed; + + eoParser parser(_argc, _argv); + + manage_configuration_file(parser); + + seed=atoi( (parser.getParamWithLongName("seed")->getValue()).c_str() ); + instancePath=parser.getParamWithLongName("instancePath")->getValue(); + selectionType=parser.getParamWithLongName("selectionType")->getValue(); + + srand (seed); + Graph::load(instancePath.c_str()); + + Route solution; + + RouteInit initializer; + initializer (solution); + + RouteEval full_evaluation; + full_evaluation (solution); + + std :: cout << "[From] " << solution << std :: endl; + + /* Tools for an efficient (? :-)) + local search ! */ + + TwoOptInit two_opt_initializer; + + TwoOptNext two_opt_next_move_generator; + + TwoOptIncrEval two_opt_incremental_evaluation; + + moMoveSelect* two_opt_selection; + + if(selectionType.compare("Best")==0) + { + two_opt_selection= new moBestImprSelect(); + } + else if (selectionType.compare("First")==0) + { + two_opt_selection= new moFirstImprSelect(); + } + else if (selectionType.compare("Random")==0) + { + two_opt_selection= new moRandImprSelect(); + } + else + { + throw std::runtime_error("[hill_climbing.cpp]: the type of selection '"+selectionType+"' is not correct."); + } + + moHC hill_climbing (two_opt_initializer, two_opt_next_move_generator, two_opt_incremental_evaluation, + *two_opt_selection, full_evaluation); + hill_climbing (solution) ; + + std :: cout << "[To] " << solution << std :: endl; + + delete(two_opt_selection); + + return EXIT_SUCCESS; +} + +void +manage_configuration_file(eoParser & _parser) +{ + std::ofstream os; + +#ifdef _MSVC + os.open("..\examples\tsp\benchs\berlin52.tsp"); + if(os.is_open()) + { + _parser.createParam(std::string("..\examples\tsp\benchs\berlin52.tsp"), "instancePath", "Path to the instance.", + 0, "Configuration", false); + } + else + { + _parser.createParam(std::string("..\..\examples\tsp\benchs\berlin52.tsp"), "instancePath", "Path to the instance.", + 0, "Configuration", false); + } + os.close(); +#else + _parser.createParam(std::string("../examples/tsp/benchs/berlin52.tsp"), "instancePath", "Path to the instance.", + 0, "Configuration", false); +#endif + + _parser.getORcreateParam((unsigned int)time(0), "seed", "Seed for rand.", 0, "Configuration", false); + + _parser.getORcreateParam(std::string("Best"), "selectionType", "Type of the selection: 'Best', 'First' or 'Random'.", + 0, "Configuration", false); + + if (_parser.userNeedsHelp()) + { + _parser.printHelp(std::cout); + exit(EXIT_FAILURE); + } + + os.open("current_param"); + if(!os.is_open()) + { + throw std::runtime_error("[hill_climbing.cpp]: the file current_param cannot be created."); + } + os <<_parser; + os.close(); +} diff --git a/trunk/paradiseo-mo/tutorial/Lesson3/tabu_search.cpp b/trunk/paradiseo-mo/tutorial/Lesson3/tabu_search.cpp new file mode 100644 index 000000000..12ae801ec --- /dev/null +++ b/trunk/paradiseo-mo/tutorial/Lesson3/tabu_search.cpp @@ -0,0 +1,160 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008 + (C) OPAC Team, LIFL, 2002-2008 + + Sébastien Cahon, Jean-Charles Boisson + + 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 + +*/ + +#include +#include +#include + +void manage_configuration_file(eoParser & _parser); + +int +main (int _argc, char* _argv []) +{ + std::string instancePath, value; + unsigned int seed, maxIterations, tabuListSize; + + eoParser parser(_argc, _argv); + + manage_configuration_file(parser); + + seed=atoi( (parser.getParamWithLongName("seed")->getValue()).c_str() ); + maxIterations=atoi( (parser.getParamWithLongName("maxIter")->getValue()).c_str() ); + tabuListSize=atoi( (parser.getParamWithLongName("tabuListSize")->getValue()).c_str() ); + instancePath=parser.getParamWithLongName("instancePath")->getValue(); + value=parser.getParamWithLongName("tabuListType")->getValue(); + + srand (seed); + Graph::load(instancePath.c_str()); + + Route solution; + + RouteInit initializer; + initializer(solution); + + RouteEval full_evaluation; + full_evaluation(solution); + + std :: cout << "[From] " << solution << std :: endl; + + /* Tools for an efficient (? :-)) + local search ! */ + + TwoOptInit two_opt_initializer; + + TwoOptNext two_opt_next_move_generator; + + TwoOptIncrEval two_opt_incremental_evaluation; + + moTabuList *tabuList; + + if(value.compare("TwoOpt")==0) + { + tabuList=new TwoOptTabuList(); + } + else if (value.compare("SimpleMove")==0) + { + tabuList=new moSimpleMoveTabuList(tabuListSize); + } + else if (value.compare("SimpleSolution")==0) + { + tabuList=new moSimpleSolutionTabuList(tabuListSize); + } + else + { + throw std::runtime_error("[tabu_search.cpp]: the type of tabu list '"+value+"' is not correct."); + } + + moNoAspirCrit aspiration_criterion; + + moGenSolContinue continu (maxIterations); + + moTS tabu_search (two_opt_initializer, two_opt_next_move_generator, + two_opt_incremental_evaluation, *tabuList, aspiration_criterion, continu, full_evaluation); + tabu_search(solution); + + std :: cout << "[To] " << solution << std :: endl; + + delete(tabuList); + + return EXIT_SUCCESS; +} + +void +manage_configuration_file(eoParser & _parser) +{ + std::ofstream os; + +#ifdef _MSVC + os.open("..\examples\tsp\benchs\berlin52.tsp"); + if(os.is_open()) + { + _parser.createParam(std::string("..\examples\tsp\benchs\berlin52.tsp"), "instancePath", "Path to the instance.", + 0, "Configuration", false); + } + else + { + _parser.createParam(std::string("..\..\examples\tsp\benchs\berlin52.tsp"), "instancePath", "Path to the instance.", + 0, "Configuration", false); + } + os.close(); +#else + _parser.createParam(std::string("../examples/tsp/benchs/berlin52.tsp"), "instancePath", "Path to the instance.", + 0, "Configuration", false); +#endif + + _parser.getORcreateParam((unsigned int)time(0), "seed", "Seed for rand.", 0, "Configuration", false); + + _parser.getORcreateParam((unsigned int)10, "tabuListSize", "Size of the tabu list.", 0, "Configuration", false); + + _parser.getORcreateParam((unsigned int)1000, "maxIter", "Maximum number of iterations.", 0, "Configuration", false); + + _parser.getORcreateParam(std::string("TwoOpt"), "tabuListType", "Type of the tabu list: 'TwoOpt', 'SimpleMove' or 'SimpleSolution'.", + 0, "Configuration", false); + + if (_parser.userNeedsHelp()) + { + _parser.printHelp(std::cout); + exit(EXIT_FAILURE); + } + + os.open("current_param"); + if(!os.is_open()) + { + throw std::runtime_error("[tabu_search.cpp]: the file current_param cannot be created."); + } + os <<_parser; + os.close(); +} diff --git a/trunk/paradiseo-mo/tutorial/Lesson4/simulated_annealing.cpp b/trunk/paradiseo-mo/tutorial/Lesson4/simulated_annealing.cpp new file mode 100644 index 000000000..b37569c5e --- /dev/null +++ b/trunk/paradiseo-mo/tutorial/Lesson4/simulated_annealing.cpp @@ -0,0 +1,163 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008 + (C) OPAC Team, LIFL, 2002-2008 + + Sébastien Cahon, Jean-Charles Boisson + + 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 +*/ + +#include +#include +#include + +void manage_configuration_file(eoParser & _parser); + +int +main (int _argc, char* _argv []) +{ + std::string instancePath, value; + unsigned int seed, maxIterations; + double threshold, exponentialRatio, linearRatio, initialTemperature; + + eoParser parser(_argc, _argv); + + manage_configuration_file(parser); + + seed=atoi( (parser.getParamWithLongName("seed")->getValue()).c_str() ); + instancePath=parser.getParamWithLongName("instancePath")->getValue(); + maxIterations=atoi( (parser.getParamWithLongName("maxIter")->getValue()).c_str() ); + initialTemperature=atof( (parser.getParamWithLongName("initialTemp")->getValue()).c_str() ); + threshold=atof( (parser.getParamWithLongName("threshold")->getValue()).c_str() ); + exponentialRatio=atof( (parser.getParamWithLongName("expoRatio")->getValue()).c_str() ); + linearRatio=atof( (parser.getParamWithLongName("lineaRatio")->getValue()).c_str() ); + value=parser.getParamWithLongName("coolSchedType")->getValue(); + + srand (seed); + Graph::load(instancePath.c_str()); + + Route solution; + + RouteInit initializer; + initializer (solution); + + RouteEval full_evaluation; + full_evaluation (solution); + + std :: cout << "[From] " << solution << std :: endl; + + /* Tools for an efficient (? :-)) + local search ! */ + + TwoOptRand two_opt_random_move_generator; + + TwoOptIncrEval two_opt_incremental_evaluation; + + TwoOpt move; + + moCoolingSchedule* coolingSchedule; + + if(value.compare("Expo")==0) + { + coolingSchedule=new moExponentialCoolingSchedule(threshold, exponentialRatio); + } + else if (value.compare("Linear")==0) + { + coolingSchedule=new moLinearCoolingSchedule(threshold, linearRatio); + } + else + { + throw std::runtime_error("[simulated_annealing.cpp]: the type of cooling schedule '"+value+"' is not correct."); + } + + moGenSolContinue continu (maxIterations); + + moSA simulated_annealing (two_opt_random_move_generator, two_opt_incremental_evaluation, + continu, initialTemperature, *coolingSchedule, full_evaluation); + simulated_annealing (solution); + + std :: cout << "[To] " << solution << std :: endl; + + delete(coolingSchedule); + + return EXIT_SUCCESS ; +} + +void +manage_configuration_file(eoParser & _parser) +{ + std::ofstream os; + +#ifdef _MSVC + os.open("..\examples\tsp\benchs\berlin52.tsp"); + if(os.is_open()) + { + _parser.createParam(std::string("..\examples\tsp\benchs\berlin52.tsp"), "instancePath", "Path to the instance.", + 0, "Configuration", false); + } + else + { + _parser.createParam(std::string("..\..\examples\tsp\benchs\berlin52.tsp"), "instancePath", "Path to the instance.", + 0, "Configuration", false); + } + os.close(); +#else + _parser.createParam(std::string("../examples/tsp/benchs/berlin52.tsp"), "instancePath", "Path to the instance.", + 0, "Configuration", false); +#endif + + _parser.getORcreateParam((unsigned int)time(0), "seed", "Seed for rand.", 0, "Configuration", false); + + _parser.getORcreateParam((unsigned int)1000, "maxIter", "Maximum number of iterations.", 0, "Configuration", false); + + _parser.getORcreateParam((double)1000, "initialTemp", "Initial temperature.", 0, "Configuration", false); + + _parser.getORcreateParam((double)0.1, "threshold", "Minimum temperature allowed.", 0, "Configuration", false); + + _parser.getORcreateParam((double)0.98, "expoRatio", "Ratio used if exponential cooling schedule is chosen.", 0, "Configuration", false); + + _parser.getORcreateParam((double)0.5, "lineaRatio", "Ratio used if linear cooling schedule is chosen.", 0, "Configuration", false); + + _parser.getORcreateParam(std::string("Expo"), "coolSchedType", "Type the cooling schedule: 'Expo' or 'Linear'.", + 0, "Configuration", false); + + if (_parser.userNeedsHelp()) + { + _parser.printHelp(std::cout); + exit(EXIT_FAILURE); + } + + os.open("current_param"); + if(!os.is_open()) + { + throw std::runtime_error("[simulated_annealing.cpp]: the file current_param cannot be created."); + } + os <<_parser; + os.close(); +} diff --git a/trunk/paradiseo-mo/tutorial/examples/function/CMakeLists.txt b/trunk/paradiseo-mo/tutorial/examples/function/CMakeLists.txt index ae46cc44e..2407bf81b 100644 --- a/trunk/paradiseo-mo/tutorial/examples/function/CMakeLists.txt +++ b/trunk/paradiseo-mo/tutorial/examples/function/CMakeLists.txt @@ -15,12 +15,12 @@ INCLUDE_DIRECTORIES(${ParadisEO-MO_SOURCE_DIR}/src) SET(FUNCTION_LIB_OUTPUT_PATH ${FUNCTION_BINARY_DIR}/lib) SET(LIBRARY_OUTPUT_PATH ${FUNCTION_LIB_OUTPUT_PATH}) -SET (FUNCTION_SOURCES affectation_eval.cpp - affectation_init.cpp - deviation.cpp - deviation_init.cpp - deviation_next.cpp - deviation_incr_eval.cpp ) +SET (FUNCTION_SOURCES affectation_eval.cpp + affectation_init.cpp + deviation.cpp + deviation_init.cpp + deviation_next.cpp + deviation_incr_eval.cpp ) ADD_LIBRARY(function STATIC ${FUNCTION_SOURCES}) diff --git a/trunk/paradiseo-mo/tutorial/examples/tsp/CMakeLists.txt b/trunk/paradiseo-mo/tutorial/examples/tsp/CMakeLists.txt index cbcfeb3ff..af8712140 100755 --- a/trunk/paradiseo-mo/tutorial/examples/tsp/CMakeLists.txt +++ b/trunk/paradiseo-mo/tutorial/examples/tsp/CMakeLists.txt @@ -32,21 +32,21 @@ INCLUDE_DIRECTORIES(${ParadisEO-MO_SOURCE_DIR}/src) SET(TSP_LIB_OUTPUT_PATH ${TSP_BINARY_DIR}/lib) SET(LIBRARY_OUTPUT_PATH ${TSP_LIB_OUTPUT_PATH}) -SET (TSP_SOURCES graph.cpp - route_init.cpp - route_eval.cpp - part_route_eval.cpp - edge_xover.cpp - order_xover.cpp - route_valid.cpp - partial_mapped_xover.cpp - city_swap.cpp - two_opt.cpp - two_opt_init.cpp - two_opt_next.cpp - two_opt_incr_eval.cpp - two_opt_tabu_list.cpp - two_opt_rand.cpp) +SET (TSP_SOURCES graph.cpp + route_init.cpp + route_eval.cpp + part_route_eval.cpp + edge_xover.cpp + order_xover.cpp + route_valid.cpp + partial_mapped_xover.cpp + city_swap.cpp + two_opt.cpp + two_opt_init.cpp + two_opt_next.cpp + two_opt_incr_eval.cpp + two_opt_tabu_list.cpp + two_opt_rand.cpp) ADD_LIBRARY(tsp STATIC ${TSP_SOURCES})