Nettoyage VNS
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1920 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
f16abb9d6b
commit
5bd7771afe
6 changed files with 336 additions and 66 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
<t-moForwardVariableNeighborhood.cpp>
|
||||
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 <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include <neighborhood/moRndWithoutReplNeighborhood.h>
|
||||
#include <neighborhood/moForwardVariableNeighborhood.h>
|
||||
#include "moTestClass.h"
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
std::cout << "[t-moForwardVariableNeighborhood] => START" << std::endl;
|
||||
|
||||
moRndWithoutReplNeighborhood<bitNeighbor> rndNH(8);
|
||||
moOrderNeighborhood<moIndexNeighbor<eoBit<eoMinimizingFitness> > >orderNH(8);
|
||||
|
||||
|
||||
//moForwardVariableNeighborhood<eoBit<eoMinimizingFitness>, eoMinimizingFitness> test(orderNH);
|
||||
|
||||
|
||||
std::cout << "[t-moForwardVariableNeighborhood] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
42
trunk/paradiseo-mo/tutorial/Lesson9/CMakeLists.txt
Normal file
42
trunk/paradiseo-mo/tutorial/Lesson9/CMakeLists.txt
Normal file
|
|
@ -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)
|
||||
|
||||
267
trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp
Normal file
267
trunk/paradiseo-mo/tutorial/Lesson9/VNS.cpp
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** VNS.cpp
|
||||
*
|
||||
* SV - 20/08/10
|
||||
* JH - 20/08/10
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//Representation and initializer
|
||||
#include <eoInt.h>
|
||||
#include <eoInit.h>
|
||||
#include <eoScalarFitness.h>
|
||||
|
||||
// fitness function
|
||||
#include <eval/queenEval.h>
|
||||
#include <eval/moFullEvalByModif.h>
|
||||
#include <eval/moFullEvalByCopy.h>
|
||||
|
||||
//Neighbors and Neighborhoods
|
||||
#include <problems/permutation/moShiftNeighbor.h>
|
||||
#include <problems/permutation/moIndexedSwapNeighbor.h>
|
||||
#include <neighborhood/moIndexNeighbor.h>
|
||||
#include <neighborhood/moRndWithoutReplNeighborhood.h>
|
||||
#include <neighborhood/moOrderNeighborhood.h>
|
||||
|
||||
//Algorithm and its components
|
||||
#include <coolingSchedule/moCoolingSchedule.h>
|
||||
#include <algo/moSA.h>
|
||||
|
||||
//comparator
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
|
||||
//continuators
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
#include <continuator/moCheckpoint.h>
|
||||
#include <continuator/moFitnessStat.h>
|
||||
#include <utils/eoFileMonitor.h>
|
||||
#include <continuator/moCounterMonitorSaver.h>
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Define types of the representation solution, different neighbors and neighborhoods
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoInt<eoMinimizingFitness> Queen; //Permutation (Queen's problem representation)
|
||||
|
||||
typedef moShiftNeighbor<Queen> shiftNeighbor; //shift Neighbor
|
||||
typedef moIndexedSwapNeighbor <Queen> swapNeighbor;
|
||||
typedef moIndexNeighbor<Queen> indexNeighbor;
|
||||
typedef moRndWithoutReplNeighborhood<shiftNeighbor> shiftNeighborhood; //rnd shift Neighborhood (Indexed)
|
||||
typedef moRndWithoutReplNeighborhood<swapNeighbor> 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<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> 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<string> 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<Queen> fullEval;
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
eoInitPermutation<Queen> init(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalByCopy<shiftNeighbor> shiftEval(fullEval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
shiftNeighborhood shiftNH((vecSize-1) * (vecSize-1));
|
||||
swapNeighborhood swapNH(100);
|
||||
|
||||
moForwardVariableNeighborhood< moIndexNeighbor<Queen> > varNH( dynamic_cast<moNeighborhood<moIndexNeighbor<Queen> > *>(&shiftNH));
|
||||
varNH.add(dynamic_cast<moNeighborhood<moIndexNeighbor<Queen> > *>(&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<shiftNeighbor> 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<Queen> coolingSchedule(1, 0.9, 100, 0.01);
|
||||
//
|
||||
// /* =========================================================
|
||||
// *
|
||||
// * Comparator of neighbors
|
||||
// *
|
||||
// * ========================================================= */
|
||||
//
|
||||
// moSolNeighborComparator<shiftNeighbor> solComparator;
|
||||
//
|
||||
// /* =========================================================
|
||||
// *
|
||||
// * Example of Checkpointing
|
||||
// *
|
||||
// * ========================================================= */
|
||||
//
|
||||
// moTrueContinuator<shiftNeighbor> continuator;//always continue
|
||||
// moCheckpoint<shiftNeighbor> checkpoint(continuator);
|
||||
// moFitnessStat<Queen> fitStat;
|
||||
// checkpoint.add(fitStat);
|
||||
// eoFileMonitor monitor("fitness.out", "");
|
||||
// moCounterMonitorSaver countMon(100, monitor);
|
||||
// checkpoint.add(countMon);
|
||||
// monitor.add(fitStat);
|
||||
//
|
||||
// //moSA<shiftNeighbor> 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue