git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1329 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
jhumeau 2009-01-14 12:32:48 +00:00
commit 8c6554b415
20 changed files with 137 additions and 157 deletions

View file

@ -1,3 +1,5 @@
######################################################################################
### 1) Include the sources
######################################################################################
@ -22,8 +24,10 @@ LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${TSP_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")
SOURCE_GROUP(src FILES hill_climbing.cpp)
SOURCE_GROUP(src FILES tabu_search.cpp)
SOURCE_GROUP(benchs FILES
${TSP_BIN_DIR}/benchs/berlin52.tsp
@ -32,9 +36,9 @@ IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "
${TSP_BIN_DIR}/benchs/rl5915.tsp
${TSP_BIN_DIR}/benchs/usa13509.tsp
)
ADD_EXECUTABLE(hill_climbing
hill_climbing.cpp
ADD_EXECUTABLE(tabu_search
tabu_search.cpp
${MO_BIN_DIR}/tutorial/Lesson2/param
${TSP_BIN_DIR}/benchs/berlin52.tsp
${TSP_BIN_DIR}/benchs/eil101.tsp
@ -42,18 +46,17 @@ IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "
${TSP_BIN_DIR}/benchs/rl5915.tsp
${TSP_BIN_DIR}/benchs/usa13509.tsp
)
ELSE(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
ELSE(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
ADD_COMMANDS_MO()
ADD_TARGET_MO(lesson2)
IF(ENABLE_CMAKE_EXAMPLE)
ADD_EXECUTABLE(hill_climbing hill_climbing.cpp)
ADD_EXECUTABLE(tabu_search tabu_search.cpp)
ELSE(ENABLE_CMAKE_EXAMPLE)
ADD_EXECUTABLE(hill_climbing EXCLUDE_FROM_ALL hill_climbing.cpp)
ADD_EXECUTABLE(tabu_search EXCLUDE_FROM_ALL tabu_search.cpp)
ENDIF(ENABLE_CMAKE_EXAMPLE)
ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
ADD_DEPENDENCIES(hill_climbing tsp)
ADD_DEPENDENCIES(tabu_search tsp)
######################################################################################
@ -62,8 +65,8 @@ ADD_DEPENDENCIES(hill_climbing tsp)
### 4) Optionnal: define your target(s)'s version: no effect for windows
######################################################################################
SET(HILLCLIMBING_VERSION ${GLOBAL_VERSION})
SET_TARGET_PROPERTIES(hill_climbing PROPERTIES VERSION "${HILLCLIMBING_VERSION}")
SET(TABUSEARCH_VERSION ${GLOBAL_VERSION})
SET_TARGET_PROPERTIES(tabu_search PROPERTIES VERSION "${TABUSEARCH_VERSION}")
######################################################################################
@ -72,7 +75,7 @@ SET_TARGET_PROPERTIES(hill_climbing PROPERTIES VERSION "${HILLCLIMBING_VERSION}"
### 5) Link the librairies for your target(s)
######################################################################################
TARGET_LINK_LIBRARIES(hill_climbing tsp eo eoutils)
TARGET_LINK_LIBRARIES(tabu_search tsp eo eoutils)
######################################################################################

View file

@ -4,6 +4,8 @@
# --stopOnUnknownParam=1 # Stop if unkown param entered
###### Configuration ######
# --instancePath=../examples/tsp/benchs/berlin52.tsp # Path to the instance.
# --seed=1203517190 # Seed for rand.
# --selectionType=Best # Type of the selection: 'Best', 'First' or 'Random'.
# --instancePath=../examples/tsp/benchs/berlin52.tsp # Path to the instance
# --seed=1202917905 # Seed for rand
# --tabuListSize=10 # Size of the tabu list
# --maxIter=1000 # Maximum number of iterations
# --tabuListType=TwoOpt # Type of the tabu list: 'TwoOpt', 'SimpleMove' or 'SimpleSolution'

View file

@ -1,5 +1,5 @@
/*
<hill_climbing.cpp>
<tabu_search.cpp>
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
(C) OPAC Team, LIFL, 2002-2008
@ -31,6 +31,7 @@
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <eo>
@ -42,27 +43,29 @@ void manage_configuration_file(eoParser & _parser);
int
main (int _argc, char* _argv [])
{
std::string instancePath, selectionType;
unsigned int seed;
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();
selectionType=parser.getParamWithLongName("selectionType")->getValue();
value=parser.getParamWithLongName("tabuListType")->getValue();
srand (seed);
Graph::load(instancePath.c_str());
Route solution;
RouteInit initializer;
initializer (solution);
initializer(solution);
RouteEval full_evaluation;
full_evaluation (solution);
full_evaluation(solution);
std :: cout << "[From] " << solution << std :: endl;
@ -75,32 +78,36 @@ main (int _argc, char* _argv [])
TwoOptIncrEval two_opt_incremental_evaluation;
moMoveSelect<TwoOpt>* two_opt_selection;
moTabuList<TwoOpt> *tabuList;
if(selectionType.compare("Best")==0)
if(value.compare("TwoOpt")==0)
{
two_opt_selection= new moBestImprSelect<TwoOpt>();
tabuList=new TwoOptTabuList();
}
else if (selectionType.compare("First")==0)
else if (value.compare("SimpleMove")==0)
{
two_opt_selection= new moFirstImprSelect<TwoOpt>();
tabuList=new moSimpleMoveTabuList<TwoOpt>(tabuListSize);
}
else if (selectionType.compare("Random")==0)
else if (value.compare("SimpleSolution")==0)
{
two_opt_selection= new moRandImprSelect<TwoOpt>();
tabuList=new moSimpleSolutionTabuList<TwoOpt>(tabuListSize);
}
else
{
throw std::runtime_error("[hill_climbing.cpp]: the type of selection '"+selectionType+"' is not correct.");
throw std::runtime_error("[tabu_search.cpp]: the type of tabu list '"+value+"' is not correct.");
}
moHC <TwoOpt> hill_climbing (two_opt_initializer, two_opt_next_move_generator, two_opt_incremental_evaluation,
*two_opt_selection, full_evaluation);
hill_climbing (solution) ;
moNoAspirCrit <TwoOpt> aspiration_criterion;
moGenSolContinue <Route> continu (maxIterations);
moTS <TwoOpt> 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(two_opt_selection);
delete(tabuList);
return EXIT_SUCCESS;
}
@ -109,13 +116,17 @@ void
manage_configuration_file(eoParser & _parser)
{
std::ofstream os;
_parser.createParam(std::string("../examples/tsp/benchs/berlin52.tsp"), "instancePath", "Path to the instance.",
0, "Configuration", false);
_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'.",
_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())
@ -127,7 +138,7 @@ manage_configuration_file(eoParser & _parser)
os.open("current_param");
if(!os.is_open())
{
throw std::runtime_error("[hill_climbing.cpp]: the file current_param cannot be created.");
throw std::runtime_error("[tabu_search.cpp]: the file current_param cannot be created.");
}
os <<_parser;
os.close();