git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1329 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
6a3cdb4910
commit
8c6554b415
20 changed files with 137 additions and 157 deletions
|
|
@ -5,54 +5,65 @@
|
|||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src/utils)
|
||||
INCLUDE_DIRECTORIES(${MO_SRC_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${FUNCTION_SRC_DIR})
|
||||
|
||||
INCLUDE_DIRECTORIES(${TSP_SRC_DIR})
|
||||
######################################################################################
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${FUNCTION_BIN_DIR}/lib)
|
||||
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 minimize_function.cpp)
|
||||
ADD_EXECUTABLE(minimize_function
|
||||
minimize_function.cpp
|
||||
SOURCE_GROUP(src FILES hill_climbing.cpp)
|
||||
|
||||
SOURCE_GROUP(benchs FILES
|
||||
${TSP_BIN_DIR}/benchs/berlin52.tsp
|
||||
${TSP_BIN_DIR}/benchs/eil101.tsp
|
||||
${TSP_BIN_DIR}/benchs/pr2392.tsp
|
||||
${TSP_BIN_DIR}/benchs/rl5915.tsp
|
||||
${TSP_BIN_DIR}/benchs/usa13509.tsp
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(hill_climbing
|
||||
hill_climbing.cpp
|
||||
${MO_BIN_DIR}/tutorial/Lesson1/param
|
||||
)
|
||||
ELSE(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
|
||||
${TSP_BIN_DIR}/benchs/berlin52.tsp
|
||||
${TSP_BIN_DIR}/benchs/eil101.tsp
|
||||
${TSP_BIN_DIR}/benchs/pr2392.tsp
|
||||
${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")
|
||||
ADD_COMMANDS_MO()
|
||||
ADD_TARGET_MO(lesson1)
|
||||
IF(ENABLE_CMAKE_EXAMPLE)
|
||||
ADD_EXECUTABLE(minimize_function minimize_function.cpp)
|
||||
ELSE(ENABLE_CMAKE_EXAMPLE)
|
||||
ADD_EXECUTABLE(minimize_function EXCLUDE_FROM_ALL minimize_function.cpp)
|
||||
ENDIF(ENABLE_CMAKE_EXAMPLE)
|
||||
ADD_EXECUTABLE(hill_climbing hill_climbing.cpp)
|
||||
ELSE(ENABLE_CMAKE_EXAMPLE)
|
||||
ADD_EXECUTABLE(hill_climbing EXCLUDE_FROM_ALL hill_climbing.cpp)
|
||||
ENDIF(ENABLE_CMAKE_EXAMPLE)
|
||||
ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
|
||||
|
||||
ADD_DEPENDENCIES(minimize_function function)
|
||||
|
||||
ADD_DEPENDENCIES(hill_climbing tsp)
|
||||
######################################################################################
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal: define your target(s)'s version: no effect for windows
|
||||
######################################################################################
|
||||
|
||||
|
||||
SET(MINIMIZEFUNCTION_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(minimize_function PROPERTIES VERSION "${MINIMIZEFUNCTION_VERSION}")
|
||||
SET(HILLCLIMBING_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(hill_climbing PROPERTIES VERSION "${HILLCLIMBING_VERSION}")
|
||||
######################################################################################
|
||||
|
||||
|
||||
|
|
@ -61,6 +72,7 @@ SET_TARGET_PROPERTIES(minimize_function PROPERTIES VERSION "${MINIMIZEFUNCTION_V
|
|||
### 5) Link the librairies for your target(s)
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(minimize_function function eo eoutils)
|
||||
TARGET_LINK_LIBRARIES(hill_climbing tsp eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
<minimize_function.cpp>
|
||||
<hill_climbing.cpp>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
(C) OPAC Team, LIFL, 2002-2008
|
||||
|
||||
|
|
@ -35,72 +35,72 @@
|
|||
|
||||
#include <eo>
|
||||
#include <mo>
|
||||
#include <function>
|
||||
#include <tsp>
|
||||
|
||||
void manage_configuration_file(eoParser & _parser);
|
||||
|
||||
int
|
||||
main (int _argc, char* _argv [])
|
||||
{
|
||||
std::string selectionType;
|
||||
double initialBound, searchBound, searchStep;
|
||||
std::string instancePath, selectionType;
|
||||
unsigned int seed;
|
||||
|
||||
eoParser parser(_argc, _argv);
|
||||
|
||||
manage_configuration_file(parser);
|
||||
|
||||
initialBound=atof( (parser.getParamWithLongName("initialBound")->getValue()).c_str() );
|
||||
searchBound=atof( (parser.getParamWithLongName("searchBound")->getValue()).c_str() );
|
||||
searchStep=atof( (parser.getParamWithLongName("searchStep")->getValue()).c_str() );
|
||||
seed=atoi( (parser.getParamWithLongName("seed")->getValue()).c_str() );
|
||||
instancePath=parser.getParamWithLongName("instancePath")->getValue();
|
||||
selectionType=parser.getParamWithLongName("selectionType")->getValue();
|
||||
|
||||
Affectation solution;
|
||||
srand (seed);
|
||||
Graph::load(instancePath.c_str());
|
||||
|
||||
AffectationInit initialize(initialBound);
|
||||
initialize (solution);
|
||||
Route solution;
|
||||
|
||||
AffectationEval evaluation;
|
||||
evaluation (solution);
|
||||
RouteInit initializer;
|
||||
initializer (solution);
|
||||
|
||||
std::cout << "Initial affectation : " << std::endl;
|
||||
std::cout << "\t x1 = " << solution.first << std::endl;
|
||||
std::cout << "\t x2 = " << solution.second << std::endl;
|
||||
std::cout << "\t f(x1,x2) = " << solution.fitness() << std::endl;
|
||||
RouteEval full_evaluation;
|
||||
full_evaluation (solution);
|
||||
|
||||
DeviationInit deviation_initializer(searchBound);
|
||||
std :: cout << "[From] " << solution << std :: endl;
|
||||
|
||||
DeviationNext deviation_next_move_generator(searchBound, searchStep);
|
||||
/* Tools for an efficient (? :-))
|
||||
local search ! */
|
||||
|
||||
DeviationIncrEval deviation_incremental_evaluation;
|
||||
TwoOptInit two_opt_initializer;
|
||||
|
||||
TwoOptNext two_opt_next_move_generator;
|
||||
|
||||
TwoOptIncrEval two_opt_incremental_evaluation;
|
||||
|
||||
moMoveSelect<TwoOpt>* two_opt_selection;
|
||||
|
||||
moMoveSelect<Deviation>* deviation_selection;
|
||||
|
||||
if(selectionType.compare("Best")==0)
|
||||
{
|
||||
deviation_selection= new moBestImprSelect<Deviation>();
|
||||
two_opt_selection= new moBestImprSelect<TwoOpt>();
|
||||
}
|
||||
else if (selectionType.compare("First")==0)
|
||||
{
|
||||
deviation_selection= new moFirstImprSelect<Deviation>();
|
||||
two_opt_selection= new moFirstImprSelect<TwoOpt>();
|
||||
}
|
||||
else if (selectionType.compare("Random")==0)
|
||||
{
|
||||
deviation_selection= new moRandImprSelect<Deviation>();
|
||||
two_opt_selection= new moRandImprSelect<TwoOpt>();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("[minimize_function.cpp]: the type of selection '"+selectionType+"' is not correct.");
|
||||
throw std::runtime_error("[hill_climbing.cpp]: the type of selection '"+selectionType+"' is not correct.");
|
||||
}
|
||||
|
||||
moHC <Deviation> hill_climbing (deviation_initializer, deviation_next_move_generator, deviation_incremental_evaluation,
|
||||
*deviation_selection, evaluation);
|
||||
moHC <TwoOpt> hill_climbing (two_opt_initializer, two_opt_next_move_generator, two_opt_incremental_evaluation,
|
||||
*two_opt_selection, full_evaluation);
|
||||
hill_climbing (solution) ;
|
||||
|
||||
std::cout << "Final affectation : " << std::endl;
|
||||
std::cout << "\t x1 = " << solution.first << std::endl;
|
||||
std::cout << "\t x2 = " << solution.second << std::endl;
|
||||
std::cout << "\t f(x1,x2) = " << solution.fitness() << std::endl;
|
||||
std :: cout << "[To] " << solution << std :: endl;
|
||||
|
||||
delete(deviation_selection);
|
||||
delete(two_opt_selection);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -110,26 +110,24 @@ manage_configuration_file(eoParser & _parser)
|
|||
{
|
||||
std::ofstream os;
|
||||
|
||||
_parser.createParam((double)1, "initialBound", "Bound for the initial affectation.", 0, "Configuration", false);
|
||||
|
||||
_parser.createParam((double)1, "searchBound", "Bound for neighbourhood exploration.", 0, "Configuration", false);
|
||||
|
||||
_parser.createParam((double)1, "searchStep", "Step between two values during the neighbourhood exploration.",
|
||||
_parser.createParam(std::string("../examples/tsp/benchs/berlin52.tsp"), "instancePath", "Path to the instance.",
|
||||
0, "Configuration", false);
|
||||
|
||||
_parser.createParam(std::string("First"), "selectionType", "Type of the selection: 'Best', 'First' or 'Random'.",
|
||||
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'.",
|
||||
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("[minimize_function.cpp]: the file current_param cannot be created.");
|
||||
throw std::runtime_error("[hill_climbing.cpp]: the file current_param cannot be created.");
|
||||
}
|
||||
os <<_parser;
|
||||
os.close();
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
||||
|
||||
###### Configuration ######
|
||||
# --initialBound=1 # Bound for the initial affectation.
|
||||
# --searchBound=1 # Bound for neighbourhood exploration.
|
||||
# --searchStep=1 # Step between two values during the neighbourhood exploration.
|
||||
# --selectionType=First # Type of the selection: 'Best', 'First' or 'Random'.
|
||||
# --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'.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue