Début du dev de newMo
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1639 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
25c45dd1fa
commit
e13fd250d1
34 changed files with 1946 additions and 48 deletions
|
|
@ -1,41 +1,108 @@
|
|||
######################################################################################
|
||||
### 0) Set your application properties
|
||||
######################################################################################
|
||||
# check cmake version compatibility
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
||||
|
||||
##########################################################################################################################################
|
||||
### 0) If you want to set your own variables in mo-conf.cmake and avoid the cmd line
|
||||
##########################################################################################################################################
|
||||
# Here define your project name
|
||||
PROJECT(NEWMO)
|
||||
|
||||
INCLUDE(mo-conf.cmake OPTIONAL)
|
||||
|
||||
##########################################################################################################################################
|
||||
# Here define the name and the version of your package
|
||||
SET(PACKAGE_NAME "VRP" CACHE STRING "Package name" FORCE)
|
||||
SET(PACKAGE_VERSION "0" CACHE STRING "Package version" FORCE)
|
||||
|
||||
|
||||
##########################################################################################################################################
|
||||
### 1) Project properties
|
||||
##########################################################################################################################################
|
||||
# regular expression checking
|
||||
INCLUDE_REGULAR_EXPRESSION("^.*$" "^$")
|
||||
|
||||
# set the project name
|
||||
PROJECT(ParadisEO-MO)
|
||||
# set a language for the entire project.
|
||||
ENABLE_LANGUAGE(CXX)
|
||||
ENABLE_LANGUAGE(C)
|
||||
|
||||
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.2" CACHE STRING "MO 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)
|
||||
##########################################################################################################################################
|
||||
######################################################################################
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the install configuration file where are defined the main variables
|
||||
######################################################################################
|
||||
|
||||
##########################################################################################################################################
|
||||
### 2) Include the common CMake configuration
|
||||
##########################################################################################################################################
|
||||
INCLUDE(${CMAKE_SOURCE_DIR}/install.cmake)
|
||||
|
||||
# The "config" variable must be provided on the command line
|
||||
IF(NOT DEFINED config OR NOT config)
|
||||
MESSAGE(FATAL_ERROR "The \"config\" variable must be set on the command line to
|
||||
give the path of the install configuration file. ")
|
||||
ENDIF(NOT DEFINED config OR NOT config)
|
||||
######################################################################################
|
||||
|
||||
# Need the config file whose full path is given thanks to the "config" variable
|
||||
INCLUDE(${config})
|
||||
##########################################################################################################################################
|
||||
######################################################################################
|
||||
### 2) Include the sources
|
||||
######################################################################################
|
||||
######################################
|
||||
### Include required modules & utilities
|
||||
#####################################################################################
|
||||
INCLUDE(CMakeBackwardCompatibilityCXX)
|
||||
|
||||
INCLUDE(FindDoxygen)
|
||||
|
||||
INCLUDE(CheckLibraryExists)
|
||||
|
||||
INCLUDE(Dart OPTIONAL)
|
||||
|
||||
# Set a special flag if the environment is windows (should do the same in a config.g file)
|
||||
IF (WIN32)
|
||||
ADD_DEFINITIONS(-D_WINDOWS=1)
|
||||
ENDIF (WIN32)
|
||||
|
||||
######################################################################################
|
||||
|
||||
#####################################################################################
|
||||
### 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" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
|
||||
SET(CMAKE_CXX_FLAGS "/nologo /Gy")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "/W3 /MTd /Z7 /Od")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "/w /MT /O2 /wd4530")
|
||||
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" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
|
||||
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 -fprofile-arcs -ftest-coverage -Wall -Wextra -Wno-unused-parameter")
|
||||
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)
|
||||
|
||||
######################################################################################
|
||||
### 3) Link the librairies for your executable
|
||||
######################################################################################
|
||||
|
||||
ADD_SUBDIRECTORY(doc)
|
||||
ADD_SUBDIRECTORY(src)
|
||||
ADD_SUBDIRECTORY(test)
|
||||
ADD_SUBDIRECTORY(tutorial)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
|
|
|||
19
branches/newMo/install.cmake
Normal file
19
branches/newMo/install.cmake
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#########################################################################################################
|
||||
# 1) ParadisEO install: SIMPLE Configuration
|
||||
#########################################################################################################
|
||||
|
||||
# Here, just specify PARADISEO_DIR : the directory where ParadisEO has been installed
|
||||
SET(PARADISEO_DIR "/home/humeau/paradiseo-1.2.1" CACHE PATH "ParadisEO directory" FORCE)
|
||||
|
||||
#########################################################################################################
|
||||
|
||||
|
||||
|
||||
#########################################################################################################
|
||||
# 2) ParadisEO install: ADVANCED Configuration
|
||||
#########################################################################################################
|
||||
|
||||
SET(PARADISEO_EO_SRC_DIR "${PARADISEO_DIR}/paradiseo-eo" CACHE PATH "ParadisEO-EO source directory" FORCE)
|
||||
SET(PARADISEO_EO_BIN_DIR "${PARADISEO_DIR}/paradiseo-eo/build" CACHE PATH "ParadisEO-EO binary directory" FORCE)
|
||||
|
||||
|
||||
64
branches/newMo/src/algo/moLocalSearch.h
Normal file
64
branches/newMo/src/algo/moLocalSearch.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef _moLocalSearch_h
|
||||
#define _moLocalSearch_h
|
||||
|
||||
#include <explorer/moNeighborhoodExplorer.h>
|
||||
#include <continuator/moContinuator.h>
|
||||
|
||||
/*
|
||||
the main algorithm of the local search
|
||||
*/
|
||||
template< class NHE , class C >
|
||||
class moLocalSearch: public eoMonOp<typename NHE::EOT>
|
||||
{
|
||||
public:
|
||||
typedef NHE NeighborhoodExplorer ;
|
||||
typedef C Continuator ;
|
||||
typedef typename NeighborhoodExplorer::EOT EOT ;
|
||||
|
||||
moLocalSearch(NeighborhoodExplorer & __searchExpl, Continuator & __continuator) : searchExplorer(__searchExpl), continuator(__continuator) { } ;
|
||||
|
||||
virtual bool operator() (EOT & solution) {
|
||||
|
||||
// initialization of the external continuator (for example the time, or the number of generations)
|
||||
continuator.init(solution);
|
||||
|
||||
// initialization of the parameter of the search (for example fill empty the tabu list)
|
||||
searchExplorer.initParam(solution);
|
||||
|
||||
unsigned num = 0;
|
||||
|
||||
do {
|
||||
// explore the neighborhood of the solution
|
||||
searchExplorer(solution);
|
||||
|
||||
// if a solution in the neighborhood can be accepted
|
||||
if (searchExplorer.accept(solution))
|
||||
searchExplorer.move(solution);
|
||||
|
||||
// update the parameter of the search (for ex. Temperature of the SA)
|
||||
searchExplorer.updateParam(solution);
|
||||
|
||||
std::cout << num << " : " << solution << std::endl ;
|
||||
num++;
|
||||
} while (continuator(solution) && searchExplorer.isContinue(solution));
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
// make the exploration of the neighborhood according to a local search heuristic
|
||||
NeighborhoodExplorer & searchExplorer ;
|
||||
|
||||
// external continuator
|
||||
Continuator & continuator ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
34
branches/newMo/src/comparator/moNeighborComparator.h
Normal file
34
branches/newMo/src/comparator/moNeighborComparator.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef _moNeighborComparator_h
|
||||
#define _moNeighborComparator_h
|
||||
|
||||
#include <neighborhood/moNeighbor.h>
|
||||
|
||||
template< class Neigh >
|
||||
class moNeighborComparator : public eoBF<const Neigh & , const Neigh & , bool>
|
||||
{
|
||||
public:
|
||||
|
||||
/*
|
||||
* true if the neighbor1 is better than neighbor2
|
||||
*/
|
||||
virtual bool operator()(const Neigh & neighbor1, const Neigh & neighbor2) {
|
||||
return (neighbor1.fitness() > neighbor2.fitness());
|
||||
}
|
||||
|
||||
/** Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moNeighborComparator"; }
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
29
branches/newMo/src/continuator/moContinuator.h
Normal file
29
branches/newMo/src/continuator/moContinuator.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef _moContinuator_h
|
||||
#define _moContinuator_h
|
||||
|
||||
/*
|
||||
to make specific continuator from a solution
|
||||
*/
|
||||
template< class NH >
|
||||
class moContinuator : public eoUF<typename NH::EOT &, bool>
|
||||
{
|
||||
public:
|
||||
typedef NH Neighborhood ;
|
||||
typedef typename Neighborhood::EOT EOT ;
|
||||
|
||||
// empty constructor
|
||||
moContinuator() { } ;
|
||||
|
||||
virtual void init(EOT & solution) = 0 ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
42
branches/newMo/src/continuator/moTrueContinuator.h
Normal file
42
branches/newMo/src/continuator/moTrueContinuator.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef _moTrueContinuator_h
|
||||
#define _moTrueContinuator_h
|
||||
|
||||
#include <continuator/moContinuator.h>
|
||||
|
||||
/*
|
||||
to make specific continuator from a solution
|
||||
*/
|
||||
template< class NH >
|
||||
class moTrueContinuator : public moContinuator<NH>
|
||||
{
|
||||
public:
|
||||
typedef NH Neighborhood ;
|
||||
typedef typename Neighborhood::EOT EOT ;
|
||||
|
||||
// empty constructor
|
||||
moTrueContinuator() { i=0;} ;
|
||||
|
||||
/*
|
||||
always true
|
||||
*/
|
||||
virtual bool operator()(EOT & solution) {
|
||||
i++;
|
||||
return i<10;
|
||||
};
|
||||
|
||||
virtual void init(EOT & solution) {
|
||||
}
|
||||
|
||||
int i;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
43
branches/newMo/src/explorer/moNeighborhoodExplorer.h
Normal file
43
branches/newMo/src/explorer/moNeighborhoodExplorer.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef _neighborhoodExplorer_h
|
||||
#define _neighborhoodExplorer_h
|
||||
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
/*
|
||||
explore the neighborhood
|
||||
*/
|
||||
template< class NH >
|
||||
class moNeighborhoodExplorer : public eoUF<typename NH::EOT & , void>
|
||||
{
|
||||
public:
|
||||
typedef NH Neighborhood ;
|
||||
typedef typename Neighborhood::EOT EOT ;
|
||||
|
||||
// empty constructor
|
||||
moNeighborhoodExplorer() { } ;
|
||||
|
||||
virtual void initParam (EOT & solution) = 0 ;
|
||||
|
||||
virtual void updateParam (EOT & solution) = 0 ;
|
||||
|
||||
virtual bool isContinue(EOT & solution) = 0 ;
|
||||
|
||||
virtual void move(EOT & solution) = 0 ;
|
||||
|
||||
virtual bool accept(EOT & solution) = 0 ;
|
||||
|
||||
/** Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moNeighborhoodExplorer"; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
91
branches/newMo/src/explorer/moSimpleHCexplorer.h
Normal file
91
branches/newMo/src/explorer/moSimpleHCexplorer.h
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#ifndef _moSimpleHCexplorer_h
|
||||
#define _moSimpleHCexplorer_h
|
||||
|
||||
#include <explorer/moNeighborhoodExplorer.h>
|
||||
|
||||
template< class NH >
|
||||
class moSimpleHCexplorer : public moNeighborhoodExplorer<NH>
|
||||
{
|
||||
public:
|
||||
typedef NH Neighborhood ;
|
||||
typedef typename Neighborhood::EOT EOT ;
|
||||
typedef typename Neighborhood::Neighbor Neighbor ;
|
||||
|
||||
// empty constructor
|
||||
moSimpleHCexplorer(Neighborhood & __neighborhood) : neighborhood(__neighborhood) {
|
||||
isAccept = false;
|
||||
}
|
||||
|
||||
virtual void initParam (EOT & solution) { } ;
|
||||
|
||||
virtual void updateParam (EOT & solution) { } ;
|
||||
|
||||
virtual void operator() (EOT & solution) {
|
||||
|
||||
//est qu'on peut initializer
|
||||
|
||||
if(neighborhood.hasNeighbor(solution)){
|
||||
neighborhood.init(solution, current);
|
||||
|
||||
current.eval(solution);
|
||||
|
||||
best = current;
|
||||
|
||||
while (neighborhood.cont(solution)) {
|
||||
neighborhood.next(solution, current);
|
||||
|
||||
current.eval(solution);
|
||||
|
||||
if (current.betterThan(best)) {
|
||||
|
||||
best = current;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
isAccept=false;
|
||||
}
|
||||
};
|
||||
|
||||
virtual bool isContinue(EOT & solution) {
|
||||
return isAccept ;
|
||||
};
|
||||
|
||||
virtual void move(EOT & solution) {
|
||||
|
||||
best.move(solution);
|
||||
|
||||
solution.fitness(best.fitness());
|
||||
};
|
||||
|
||||
virtual bool accept(EOT & solution) {
|
||||
if(neighborhood.hasNeighbor(solution)){
|
||||
isAccept = (solution.fitness() < best.fitness()) ;
|
||||
}
|
||||
return isAccept;
|
||||
};
|
||||
|
||||
private:
|
||||
Neighborhood & neighborhood;
|
||||
|
||||
// attention il faut que le constructeur vide existe
|
||||
Neighbor best ;
|
||||
|
||||
Neighbor current ;
|
||||
|
||||
// true if the move is accepted
|
||||
bool isAccept ;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
57
branches/newMo/src/move/moMove.h
Normal file
57
branches/newMo/src/move/moMove.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
<moMove.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
(C) OPAC Team, LIFL, 2002-2008
|
||||
|
||||
Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _moMove_h
|
||||
#define _moMove_h
|
||||
|
||||
#include <eoFunctor.h>
|
||||
|
||||
//! Definition of a move.
|
||||
|
||||
/*!
|
||||
A move transforms a solution to another close solution.
|
||||
It describes how a solution can be modified to another one.
|
||||
*/
|
||||
template < class EOT >
|
||||
class moMove:public eoUF < EOT &, void >
|
||||
{
|
||||
public:
|
||||
|
||||
//! Alias for the type
|
||||
typedef EOT EOType;
|
||||
};
|
||||
|
||||
#endif
|
||||
52
branches/newMo/src/move/moMoveIncrEval.h
Normal file
52
branches/newMo/src/move/moMoveIncrEval.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
<moMoveIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
(C) OPAC Team, LIFL, 2002-2008
|
||||
|
||||
Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#ifndef _moMoveIncrEval_h
|
||||
#define _moMoveIncrEval_h
|
||||
|
||||
#include <eoFunctor.h>
|
||||
|
||||
//! (generally) Efficient evaluation function based a move and a solution.
|
||||
|
||||
/*!
|
||||
From a move and a solution, it computes
|
||||
a new fitness that could be associated to
|
||||
the solution if this one is updated.
|
||||
*/
|
||||
template < class M, class Objective = typename M::EOType::Fitness>
|
||||
class moMoveIncrEval:public eoBF < const M &, const typename M::EOType &, Objective >
|
||||
{};
|
||||
|
||||
#endif
|
||||
31
branches/newMo/src/mo.h → branches/newMo/src/move/moMoveInit.h
Executable file → Normal file
31
branches/newMo/src/mo.h → branches/newMo/src/move/moMoveInit.h
Executable file → Normal file
|
|
@ -1,21 +1,21 @@
|
|||
/*
|
||||
<mo.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
(C) OPAC Team, LIFL, 2002-2007
|
||||
|
||||
<moMoveInit.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
(C) OPAC Team, LIFL, 2002-2008
|
||||
|
||||
Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
|
||||
|
||||
|
||||
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,
|
||||
|
|
@ -28,14 +28,23 @@
|
|||
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
|
||||
*/
|
||||
|
||||
#ifndef _mo_h
|
||||
#define _mo_h
|
||||
#ifndef _moMoveInit_h
|
||||
#define _moMoveInit_h
|
||||
|
||||
#include <algo/moAlgo.h>
|
||||
#include <eoFunctor.h>
|
||||
|
||||
//! Move (moMove) initializer
|
||||
/*!
|
||||
Class which allows to initiase a move.
|
||||
Only a description... An object that herits from this class needs to be designed to be used.
|
||||
*/
|
||||
template < class M >
|
||||
class moMoveInit:public eoBF < M &, const typename M::EOType &, void >
|
||||
{};
|
||||
|
||||
#endif
|
||||
50
branches/newMo/src/move/moNextMove.h
Normal file
50
branches/newMo/src/move/moNextMove.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
<moNextMove.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
(C) OPAC Team, LIFL, 2002-2008
|
||||
|
||||
Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#ifndef _moNextMove_h
|
||||
#define _moNextMove_h
|
||||
|
||||
#include <eoFunctor.h>
|
||||
|
||||
//! Class which allows to generate a new move (moMove).
|
||||
/*!
|
||||
Useful for the explorer (for moTS or moHC).
|
||||
Does nothing... An object that herits from this class needs to be designed for being used.
|
||||
*/
|
||||
template < class M >
|
||||
class moNextMove:public eoBF < M &, const typename M::EOType &, bool >
|
||||
{};
|
||||
|
||||
#endif
|
||||
107
branches/newMo/src/neighborhood/moBitNeighbor.h
Normal file
107
branches/newMo/src/neighborhood/moBitNeighbor.h
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#ifndef _bitNeighbor_h
|
||||
#define _bitNeighbor_h
|
||||
|
||||
#include <ga/eoBit.h>
|
||||
#include <neighborhood/moNeighbor.h>
|
||||
|
||||
/*
|
||||
contener of the neighbor information
|
||||
*/
|
||||
template< class Fitness >
|
||||
class moBitNeighbor : public moNeighbor< eoBit<Fitness> , Fitness>
|
||||
{
|
||||
public:
|
||||
typedef eoBit<Fitness> EOType ;
|
||||
|
||||
using moNeighbor< eoBit<Fitness> , Fitness>::fitness;
|
||||
|
||||
// describe the neighbor
|
||||
unsigned bit ;
|
||||
|
||||
// empty constructor needed
|
||||
moBitNeighbor() : moNeighbor<eoBit<Fitness> , Fitness>() { } ;
|
||||
|
||||
// copy constructor
|
||||
moBitNeighbor(const moBitNeighbor & n) : moNeighbor<eoBit<Fitness> , Fitness>(n) {
|
||||
this->bit = n.bit ;
|
||||
} ;
|
||||
|
||||
moBitNeighbor(unsigned b) : moNeighbor<eoBit<Fitness> , Fitness>() , bit(b) { } ;
|
||||
|
||||
/*
|
||||
* operator of assignment
|
||||
*/
|
||||
virtual moBitNeighbor<Fitness> & operator=(const moBitNeighbor<Fitness> & source) {
|
||||
moNeighbor<EOType, Fitness>::operator=(source);
|
||||
|
||||
this->bit = source.bit ;
|
||||
|
||||
return *this ;
|
||||
}
|
||||
|
||||
/*
|
||||
move the solution
|
||||
*/
|
||||
virtual void move(EOType & solution) {
|
||||
solution[bit] = solution[bit]?false:true ;
|
||||
}
|
||||
|
||||
// by default: if the fitness of the current solution is stricly higher than the other neighbor
|
||||
virtual bool betterThan(const moNeighbor<EOType, Fitness> & __neighbor) {
|
||||
return (this->fitness() > __neighbor.fitness()) ;
|
||||
};
|
||||
|
||||
/** Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moBitNeighbor"; }
|
||||
|
||||
/**
|
||||
* Read object.\ \
|
||||
* Calls base class, just in case that one had something to do.
|
||||
* The read and print methods should be compatible and have the same format.
|
||||
* In principle, format is "plain": they just print a number
|
||||
* @param _is a std::istream.
|
||||
* @throw runtime_std::exception If a valid object can't be read.
|
||||
*/
|
||||
virtual void readFrom(std::istream& _is) {
|
||||
std::string fitness_str;
|
||||
int pos = _is.tellg();
|
||||
_is >> fitness_str;
|
||||
|
||||
if (fitness_str == "INVALID")
|
||||
{
|
||||
throw std::runtime_error("invalid fitness");
|
||||
}
|
||||
else
|
||||
{
|
||||
Fitness repFit ;
|
||||
_is.seekg(pos); // rewind
|
||||
_is >> repFit;
|
||||
_is >> bit;
|
||||
|
||||
fitness(repFit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
virtual void printOn(std::ostream& _os) const {
|
||||
_os << fitness() << ' ' << bit << ' ' ;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
60
branches/newMo/src/neighborhood/moBitNeighborhood.h
Normal file
60
branches/newMo/src/neighborhood/moBitNeighborhood.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef _bitNeighborhood_h
|
||||
#define _bitNeighborhood_h
|
||||
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
|
||||
template< class N >
|
||||
class moBitNeighborhood : public moNeighborhood<N>
|
||||
{
|
||||
public:
|
||||
typedef N Neighbor ;
|
||||
typedef typename Neighbor::EOType EOT ;
|
||||
|
||||
moBitNeighborhood() : moNeighborhood<Neighbor>() { }
|
||||
|
||||
virtual bool hasNeighbor(EOT & solution) {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
initialisation of the neighborhood
|
||||
*/
|
||||
virtual void init(EOT & solution, Neighbor & _neighbor) {
|
||||
currentBit = 0 ;
|
||||
|
||||
_neighbor.bit = currentBit ;
|
||||
}
|
||||
|
||||
/*
|
||||
Give the next neighbor
|
||||
*/
|
||||
virtual void next(EOT & solution, Neighbor & neighbor) {
|
||||
currentBit++ ;
|
||||
|
||||
neighbor.bit = currentBit ;
|
||||
}
|
||||
|
||||
/*
|
||||
if false, there is no neighbor left to explore
|
||||
*/
|
||||
virtual bool cont(EOT & solution) {
|
||||
return (currentBit < solution.size()) ;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned currentBit;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
41
branches/newMo/src/neighborhood/moEmptyNeighbor.h
Normal file
41
branches/newMo/src/neighborhood/moEmptyNeighbor.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef _emptyNeighbor_h
|
||||
#define _emptyNeighbor_h
|
||||
|
||||
#include <neighborhood/moNeighbor.h>
|
||||
|
||||
/*
|
||||
contener of the neighbor information
|
||||
*/
|
||||
template< class EOT , class Fitness >
|
||||
class moEmptyNeighbor : public moNeighbor<EOT,Fitness>
|
||||
{
|
||||
public:
|
||||
typedef EOT EOType ;
|
||||
|
||||
// empty constructor
|
||||
moEmptyNeighbor() : moNeighbor<EOType, Fitness>() { } ;
|
||||
|
||||
/*
|
||||
make the evaluation of the current neighbor and update the information on this neighbor
|
||||
*/
|
||||
virtual void eval(EOT & solution) { }
|
||||
|
||||
/*
|
||||
move the solution
|
||||
*/
|
||||
virtual void move(EOT & solution) { }
|
||||
|
||||
// true if the this is better than the neighbor __neighbor
|
||||
virtual bool betterThan(moNeighbor<EOT,Fitness> & __neighbor) { return true; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
64
branches/newMo/src/neighborhood/moFullEvalBitNeighbor.h
Normal file
64
branches/newMo/src/neighborhood/moFullEvalBitNeighbor.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef _fullEvalBitNeighbor_h
|
||||
#define _fullEvalBitNeighbor_h
|
||||
|
||||
#include <neighborhood/moBitNeighbor.h>
|
||||
#include <ga.h>
|
||||
|
||||
/*
|
||||
contener of the neighbor information
|
||||
*/
|
||||
template< class Fitness >
|
||||
class moFullEvalBitNeighbor : public moBitNeighbor<Fitness>
|
||||
{
|
||||
public:
|
||||
typedef eoBit<Fitness> EOType ;
|
||||
|
||||
using moBitNeighbor<Fitness>::bit ;
|
||||
|
||||
// empty constructor needed
|
||||
moFullEvalBitNeighbor() : moBitNeighbor<Fitness>() { } ;
|
||||
|
||||
moFullEvalBitNeighbor(unsigned b) : moBitNeighbor<Fitness>(bit) { } ;
|
||||
|
||||
/*
|
||||
make the evaluation of the current neighbor and update the information on this neighbor
|
||||
*/
|
||||
virtual void eval(EOType & solution) {
|
||||
Fitness fit = solution.fitness();
|
||||
|
||||
solution[bit] = solution[bit]?false:true ;
|
||||
|
||||
(*fullEval)(solution);
|
||||
|
||||
fitness(solution.fitness());
|
||||
|
||||
solution[bit] = solution[bit]?false:true ;
|
||||
|
||||
solution.fitness(fit);
|
||||
};
|
||||
|
||||
static void setFullEvalFunc(eoEvalFunc<EOType> & eval) {
|
||||
fullEval = & eval ;
|
||||
}
|
||||
|
||||
static eoEvalFunc<EOType> * fullEval ;
|
||||
|
||||
/** Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moFullEvalBitNeighbor"; }
|
||||
};
|
||||
|
||||
template<class Fitness>
|
||||
eoEvalFunc< eoBit<Fitness> > * moFullEvalBitNeighbor<Fitness>::fullEval = NULL ;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
46
branches/newMo/src/neighborhood/moFullEvalNeighbor.h
Normal file
46
branches/newMo/src/neighborhood/moFullEvalNeighbor.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef _fullEvalNeighbor_h
|
||||
#define _fullEvalNeighbor_h
|
||||
|
||||
/*
|
||||
neighbor with full evaluation
|
||||
*/
|
||||
template< class EOT , class Fitness >
|
||||
class moFullEvalNeighbor : moNeighbor<EOT, Fitness>
|
||||
{
|
||||
public:
|
||||
// empty constructor
|
||||
moFullEvalNeighbor(eoEvalFunc<EOT> & _eval) : fulleval(_eval) { } ;
|
||||
|
||||
/*
|
||||
make the evaluation of the current neighbor and update the information on this neighbor
|
||||
*/
|
||||
virtual void eval(EOT & solution) {
|
||||
Fitness fit = solution.fitness();
|
||||
|
||||
move(solution);
|
||||
|
||||
fulleval(solution);
|
||||
|
||||
moveBack(solution);
|
||||
|
||||
fitness = solution.fitness();
|
||||
|
||||
solution.fitness(fit);
|
||||
};
|
||||
|
||||
virtual moveBack(EOT & solution) ;
|
||||
|
||||
private:
|
||||
eoEvalFunc<EOT> & fulleval ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
108
branches/newMo/src/neighborhood/moMoveNeighbor.h
Normal file
108
branches/newMo/src/neighborhood/moMoveNeighbor.h
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#ifndef _moMoveNeighbor_h
|
||||
#define _moMoveNeighbor_h
|
||||
|
||||
#include <eo>
|
||||
|
||||
#include <neighborhood/moNeighbor.h>
|
||||
#include <move/moMoveIncrEval.h>
|
||||
#include <move/moMove.h>
|
||||
|
||||
|
||||
/*
|
||||
contener of the neighbor informations
|
||||
*/
|
||||
template< class M , class Fitness >
|
||||
class moMoveNeighbor : public moNeighbor <typename M::EOType, Fitness>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename M::EOType EOT;
|
||||
|
||||
// empty constructor
|
||||
moMoveNeighbor() {_move=new M();};
|
||||
|
||||
~moMoveNeighbor() {delete _move;};
|
||||
|
||||
// copy constructeur
|
||||
moMoveNeighbor(const moMoveNeighbor<M, Fitness> & _n) {
|
||||
moNeighbor<EOT, Fitness>::operator=(_n);
|
||||
(*_move) = *(_n._move);
|
||||
}
|
||||
|
||||
// assignment operator
|
||||
virtual moMoveNeighbor<M, Fitness> & operator=(const moMoveNeighbor<M, Fitness> & _n) {
|
||||
moNeighbor <EOT, Fitness>::operator=(_n);
|
||||
(*_move) = *(_n._move);
|
||||
|
||||
std::cout << moNeighbor<EOT, Fitness>::fitness() << " , " << _n.fitness() << std::endl;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
/*
|
||||
* make the evaluation of the current neighbor and update the information on this neighbor
|
||||
* the evaluation could be increamental
|
||||
*/
|
||||
virtual void eval(EOT & solution){
|
||||
fitness((*_incrEval)(*_move, solution));
|
||||
}
|
||||
|
||||
/*
|
||||
* move the solution
|
||||
*/
|
||||
virtual void move(EOT & solution){
|
||||
(*_move)(solution);
|
||||
}
|
||||
|
||||
/** Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moMoveNeighbor"; }
|
||||
|
||||
static void setIncrEval(moMoveIncrEval<M, Fitness>& increm) {
|
||||
_incrEval = & increm ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read object.\ \
|
||||
* Calls base class, just in case that one had something to do.
|
||||
* The read and print methods should be compatible and have the same format.
|
||||
* In principle, format is "plain": they just print a number
|
||||
* @param _is a std::istream.
|
||||
* @throw runtime_std::exception If a valid object can't be read.
|
||||
*/
|
||||
/* virtual void readFrom(std::istream& _is) {
|
||||
std::string fitness_str;
|
||||
int pos = _is.tellg();
|
||||
_is >> fitness_str;
|
||||
|
||||
if (fitness_str == "INVALID")
|
||||
{
|
||||
throw std::runtime_error("invalid fitness");
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.seekg(pos); // rewind
|
||||
_is >> repFitness;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
/*virtual void printOn(std::ostream& _os) const {
|
||||
_os << repFitness << ' ' ;
|
||||
}*/
|
||||
|
||||
M* _move;
|
||||
|
||||
private:
|
||||
|
||||
static moMoveIncrEval<M, Fitness>* _incrEval;
|
||||
|
||||
};
|
||||
|
||||
template< class M , class Fitness >
|
||||
moMoveIncrEval<M, Fitness> * moMoveNeighbor<M, Fitness>::_incrEval = NULL;
|
||||
#endif
|
||||
59
branches/newMo/src/neighborhood/moMoveNeighborhood.h
Normal file
59
branches/newMo/src/neighborhood/moMoveNeighborhood.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#ifndef _moMoveNeighborhood_h
|
||||
#define _moMoveNeighborhood_h
|
||||
|
||||
#include <neighborhood/moMoveNeighbor.h>
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
|
||||
#include <move/moMoveInit.h>
|
||||
#include <move/moNextMove.h>
|
||||
|
||||
template< class M, class Fitness >
|
||||
class moMoveNeighborhood : public moNeighborhood <moMoveNeighbor<M, Fitness> >
|
||||
{
|
||||
public:
|
||||
|
||||
typedef moMoveNeighbor<M, Fitness> Neighbor;
|
||||
typedef typename M::EOType EOT;
|
||||
|
||||
moMoveNeighborhood(moMoveInit<M>& i, moNextMove<M>& n):_init(i), _next(n), isContinue(true) {}
|
||||
|
||||
virtual bool hasNeighbor(EOT & solution){
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
initialisation of the neighborhood
|
||||
*/
|
||||
virtual void init(EOT & solution, Neighbor & current){
|
||||
_init(*(current._move), solution);
|
||||
isContinue=true;
|
||||
}
|
||||
|
||||
/*
|
||||
Give the next neighbor
|
||||
*/
|
||||
virtual void next(EOT & solution, Neighbor & current){
|
||||
isContinue=_next(*(current._move), solution);
|
||||
}
|
||||
|
||||
/*
|
||||
if false, there is no neighbor left to explore
|
||||
*/
|
||||
virtual bool cont(EOT & solution){
|
||||
return isContinue;
|
||||
}
|
||||
|
||||
/** Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moMoveNeighborhood"; }
|
||||
|
||||
private:
|
||||
moMoveInit<M>& _init;
|
||||
moNextMove<M>& _next;
|
||||
bool isContinue;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
135
branches/newMo/src/neighborhood/moNeighbor.h
Normal file
135
branches/newMo/src/neighborhood/moNeighbor.h
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
#ifndef _moNeighbor_h
|
||||
#define _moNeighbor_h
|
||||
|
||||
#include <eo>
|
||||
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
|
||||
/*
|
||||
contener of the neighbor informations
|
||||
*/
|
||||
template< class EOT , class Fitness >
|
||||
class moNeighbor : public eoObject, public eoPersistent
|
||||
{
|
||||
public:
|
||||
typedef EOT EOType ;
|
||||
|
||||
// empty constructor
|
||||
moNeighbor() { } ;
|
||||
|
||||
// copy constructeur
|
||||
moNeighbor(const moNeighbor<EOType, Fitness> & _n) {
|
||||
repFitness = _n.fitness();
|
||||
}
|
||||
|
||||
// assignment operator
|
||||
virtual moNeighbor<EOType, Fitness> & operator=(const moNeighbor<EOType, Fitness> & _n) {
|
||||
repFitness = _n.fitness();
|
||||
|
||||
return *this ;
|
||||
}
|
||||
|
||||
/*
|
||||
* make the evaluation of the current neighbor and update the information on this neighbor
|
||||
* the evaluation could be increamental
|
||||
*/
|
||||
virtual void eval(EOT & solution) = 0 ;
|
||||
|
||||
/*
|
||||
* move the solution
|
||||
*/
|
||||
virtual void move(EOT & solution) = 0 ;
|
||||
|
||||
// true if the this is better than the neighbor __neighbor
|
||||
// virtual bool betterThan(const moNeighbor<EOT,Fitness> & __neighbor) = 0 ;
|
||||
virtual bool betterThan(const moNeighbor<EOT,Fitness> & __neighbor) {
|
||||
return (*neighborComparator)(*this, __neighbor) ;
|
||||
} ;
|
||||
|
||||
/// Return fitness value.
|
||||
const Fitness& fitness() const {
|
||||
return repFitness;
|
||||
}
|
||||
|
||||
/// Get fitness as reference, useful when fitness is set in a multi-stage way, e.g., MOFitness gets performance information, is subsequently ranked
|
||||
Fitness& fitnessReference() {
|
||||
return repFitness;
|
||||
}
|
||||
|
||||
/** Set fitness. At the same time, validates it.
|
||||
* @param _fitness New fitness value.
|
||||
*/
|
||||
void fitness(const Fitness& _fitness)
|
||||
{
|
||||
repFitness = _fitness;
|
||||
}
|
||||
|
||||
/** Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moNeighbor"; }
|
||||
|
||||
/**
|
||||
* Read object.\ \
|
||||
* Calls base class, just in case that one had something to do.
|
||||
* The read and print methods should be compatible and have the same format.
|
||||
* In principle, format is "plain": they just print a number
|
||||
* @param _is a std::istream.
|
||||
* @throw runtime_std::exception If a valid object can't be read.
|
||||
*/
|
||||
virtual void readFrom(std::istream& _is) {
|
||||
std::string fitness_str;
|
||||
int pos = _is.tellg();
|
||||
_is >> fitness_str;
|
||||
|
||||
if (fitness_str == "INVALID")
|
||||
{
|
||||
throw std::runtime_error("invalid fitness");
|
||||
}
|
||||
else
|
||||
{
|
||||
_is.seekg(pos); // rewind
|
||||
_is >> repFitness;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
virtual void printOn(std::ostream& _os) const {
|
||||
_os << repFitness << ' ' ;
|
||||
}
|
||||
|
||||
static void setNeighborComparator(const moNeighborComparator< moNeighbor<EOType, Fitness> > & comparator) {
|
||||
neighborComparator = & comparator ;
|
||||
}
|
||||
|
||||
static const moNeighborComparator< moNeighbor<EOType, Fitness> > & getNeighborComparator() {
|
||||
return *neighborComparator ;
|
||||
}
|
||||
|
||||
private:
|
||||
// minimal information on the neighbor : fitness
|
||||
Fitness repFitness ;
|
||||
|
||||
// the comparator of neighbors
|
||||
static moNeighborComparator<moNeighbor<EOType, Fitness> > * neighborComparator ;
|
||||
|
||||
};
|
||||
|
||||
// static default comparor
|
||||
template<class EOT, class Fitness>
|
||||
moNeighborComparator<moNeighbor<EOT, Fitness> > * moNeighbor<EOT, Fitness>::neighborComparator = new moNeighborComparator<moNeighbor<EOT, Fitness> >();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
46
branches/newMo/src/neighborhood/moNeighborhood.h
Normal file
46
branches/newMo/src/neighborhood/moNeighborhood.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef _moNeighborhood_h
|
||||
#define _moNeighborhood_h
|
||||
|
||||
template< class Neigh >
|
||||
class moNeighborhood : public eoObject
|
||||
{
|
||||
public:
|
||||
typedef Neigh Neighbor;
|
||||
typedef typename Neighbor::EOType EOT;
|
||||
|
||||
moNeighborhood() { }
|
||||
|
||||
virtual bool hasNeighbor(EOT & solution) = 0 ;
|
||||
|
||||
/*
|
||||
initialisation of the neighborhood
|
||||
*/
|
||||
virtual void init(EOT & solution, Neighbor & current) = 0 ;
|
||||
|
||||
/*
|
||||
Give the next neighbor
|
||||
*/
|
||||
virtual void next(EOT & solution, Neighbor & current) = 0 ;
|
||||
|
||||
/*
|
||||
if false, there is no neighbor left to explore
|
||||
*/
|
||||
virtual bool cont(EOT & solution) = 0 ;
|
||||
|
||||
/** Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moNeighborhood"; }
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
|
|
@ -1,10 +1,7 @@
|
|||
/*
|
||||
/*
|
||||
<mo>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
(C) OPAC Team, LIFL, 2002-2008
|
||||
|
||||
Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
|
||||
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
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
|
||||
|
|
@ -33,9 +30,10 @@
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef __mo
|
||||
#define __mo
|
||||
|
||||
#include "mo.h"
|
||||
#ifndef __newmo
|
||||
#define __newmo
|
||||
|
||||
#include "newmo.h"
|
||||
|
||||
#endif
|
||||
61
branches/newMo/src/newmo.h
Executable file
61
branches/newMo/src/newmo.h
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
<mo.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
#ifndef _newmo_h
|
||||
#define _newmo_h
|
||||
|
||||
#include <algo/moLocalSearch.h>
|
||||
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
|
||||
#include <continuator/moContinuator.h>
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
|
||||
#include <explorer/moNeighborhoodExplorer.h>
|
||||
#include <explorer/moSimpleHCexplorer.h>
|
||||
|
||||
#include <neighborhood/moBitNeighbor.h>
|
||||
#include <neighborhood/moBitNeighborhood.h>
|
||||
#include <neighborhood/moEmptyNeighbor.h>
|
||||
#include <neighborhood/moFullEvalBitNeighbor.h>
|
||||
#include <neighborhood/moFullEvalNeighbor.h>
|
||||
#include <neighborhood/moMoveNeighbor.h>
|
||||
#include <neighborhood/moMoveNeighborhood.h>
|
||||
#include <neighborhood/moNeighbor.h>
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
|
||||
#include <move/moMove.h>
|
||||
#include <move/moMoveIncrEval.h>
|
||||
#include <move/moMoveInit.h>
|
||||
#include <move/moNextMove.h>
|
||||
|
||||
#endif
|
||||
1
branches/newMo/tutorial/CMakeLists.txt
Normal file
1
branches/newMo/tutorial/CMakeLists.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
ADD_SUBDIRECTORY(oneMax)
|
||||
1
branches/newMo/tutorial/oneMax/CMakeLists.txt
Normal file
1
branches/newMo/tutorial/oneMax/CMakeLists.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
ADD_SUBDIRECTORY(application)
|
||||
11
branches/newMo/tutorial/oneMax/application/CMakeLists.txt
Normal file
11
branches/newMo/tutorial/oneMax/application/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
INCLUDE_DIRECTORIES(${PARADISEO_EO_SRC_DIR}/src
|
||||
${NEWMO_SRC_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src)
|
||||
|
||||
LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib)
|
||||
|
||||
ADD_EXECUTABLE(testSimpleHC testSimpleHC.cpp)
|
||||
ADD_EXECUTABLE(testWithMove testWithMove.cpp)
|
||||
|
||||
TARGET_LINK_LIBRARIES(testSimpleHC eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testWithMove eoutils ga eo)
|
||||
203
branches/newMo/tutorial/oneMax/application/testSimpleHC.cpp
Normal file
203
branches/newMo/tutorial/oneMax/application/testSimpleHC.cpp
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testSimpleHC.cpp
|
||||
*
|
||||
* SV - 12/01/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;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moEmptyNeighbor.h>
|
||||
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
|
||||
// local search algorithm
|
||||
#include <algo/moLocalSearch.h>
|
||||
|
||||
// the simple HC explorer
|
||||
#include <explorer/moSimpleHCexplorer.h>
|
||||
|
||||
// explore the neighborhood of a bit string in order
|
||||
#include <neighborhood/moBitNeighborhood.h>
|
||||
|
||||
#include <neighborhood/moFullEvalBitNeighbor.h>
|
||||
|
||||
#include <oneMaxBitNeighbor.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoBit<unsigned> Indi;
|
||||
//typedef OneMaxBitNeighbor<unsigned> Neighbor ; // incremental evaluation
|
||||
typedef moFullEvalBitNeighbor<unsigned> Neighbor ; // full evaluation
|
||||
typedef moBitNeighborhood<Neighbor> Neighborhood ;
|
||||
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
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();
|
||||
|
||||
string fileOut("out.dat");
|
||||
eoValueParam<string> fileStatParam(fileOut.c_str(), "out", "A file to export results", 'o');
|
||||
parser.processParam( fileStatParam, "Persistence" );
|
||||
fileOut = fileStatParam.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 aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// no need if incremental evaluation with OneMaxBitNeighbor
|
||||
Neighbor::setFullEvalFunc(eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Neighborhood neighborhood;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorator solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHCexplorer<Neighborhood> explorer(neighborhood);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;
|
||||
|
||||
moLocalSearch< moSimpleHCexplorer<Neighborhood>, moTrueContinuator<Neighborhood> > localSearch(explorer, continuator);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << 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;
|
||||
}
|
||||
214
branches/newMo/tutorial/oneMax/application/testWithMove.cpp
Normal file
214
branches/newMo/tutorial/oneMax/application/testWithMove.cpp
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testSimpleHC.cpp
|
||||
*
|
||||
* SV - 12/01/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;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
|
||||
//#include <eoInt.h>
|
||||
//#include <moEmptyNeighbor.h>
|
||||
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
|
||||
// local search algorithm
|
||||
#include <algo/moLocalSearch.h>
|
||||
|
||||
// the simple HC explorer
|
||||
#include <explorer/moSimpleHCexplorer.h>
|
||||
|
||||
// explore the neighborhood of a bit string in order
|
||||
#include <neighborhood/moMoveNeighborhood.h>
|
||||
|
||||
//#include <moFullEvalBitNeighbor.h>
|
||||
|
||||
#include <neighborhood/moMoveNeighbor.h>
|
||||
|
||||
#include <bitMove.h>
|
||||
#include <bitMove_init.h>
|
||||
#include <bitMoveIncrEval.h>
|
||||
#include <bitMove_next.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoBit<unsigned> Indi;
|
||||
//typedef OneMaxBitNeighbor<unsigned> Neighbor ; // incremental evaluation
|
||||
typedef moMoveNeighbor<BitMove<Indi>, unsigned> Neighbor ; // full evaluation
|
||||
typedef moMoveNeighborhood<BitMove<Indi>, unsigned> Neighborhood ;
|
||||
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
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();
|
||||
|
||||
string fileOut("out.dat");
|
||||
eoValueParam<string> fileStatParam(fileOut.c_str(), "out", "A file to export results", 'o');
|
||||
parser.processParam( fileStatParam, "Persistence" );
|
||||
fileOut = fileStatParam.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 aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
OneMaxIncrEval<Indi> incrEval;
|
||||
Neighbor::setIncrEval(incrEval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// no need if incremental evaluation with OneMaxBitNeighbor
|
||||
// Neighbor::setFullEvalFunc(eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
BitMove_init<Indi> init;
|
||||
BitMove_next<Indi> next;
|
||||
|
||||
|
||||
Neighborhood neighborhood(init, next);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorator solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHCexplorer<Neighborhood> explorer(neighborhood);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;
|
||||
|
||||
moLocalSearch< moSimpleHCexplorer<Neighborhood>, moTrueContinuator<Neighborhood> > localSearch(explorer, continuator);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << 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;
|
||||
}
|
||||
34
branches/newMo/tutorial/oneMax/src/bitMove.h
Normal file
34
branches/newMo/tutorial/oneMax/src/bitMove.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
// "bitMove.h"
|
||||
|
||||
#ifndef __bitMove
|
||||
#define __bitMove
|
||||
|
||||
#include <utility>
|
||||
#include <move/moMove.h>
|
||||
|
||||
template <class EOT>
|
||||
class BitMove : public moMove <EOT> {
|
||||
|
||||
public :
|
||||
|
||||
typedef EOT EOType;
|
||||
|
||||
unsigned bit;
|
||||
|
||||
BitMove() {
|
||||
bit = 0;
|
||||
}
|
||||
|
||||
BitMove(unsigned _bit) : bit(_bit) { }
|
||||
|
||||
|
||||
void operator () (EOT & chrom)
|
||||
{
|
||||
chrom[bit] = !chrom[bit];
|
||||
};
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
27
branches/newMo/tutorial/oneMax/src/bitMoveIncrEval.h
Normal file
27
branches/newMo/tutorial/oneMax/src/bitMoveIncrEval.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
// "incrEval_funcNK.h"
|
||||
|
||||
#ifndef __incr_eval_funcNK_h
|
||||
#define __incr_eval_funcNK_h
|
||||
|
||||
#include <move/moMoveIncrEval.h>
|
||||
#include "bitMove.h"
|
||||
|
||||
template <class EOT>
|
||||
class OneMaxIncrEval : public moMoveIncrEval < BitMove<EOT> > {
|
||||
|
||||
public :
|
||||
OneMaxIncrEval(){ };
|
||||
|
||||
typename EOT::Fitness operator () (const BitMove<EOT> & move, const EOT & chrom) {
|
||||
if(chrom[move.bit]==0){
|
||||
return chrom.fitness()+1;
|
||||
}
|
||||
else{
|
||||
return chrom.fitness()-1;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
21
branches/newMo/tutorial/oneMax/src/bitMove_init.h
Normal file
21
branches/newMo/tutorial/oneMax/src/bitMove_init.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
// "bitMove_init.h"
|
||||
#ifndef __bitMove_init
|
||||
#define __bitMove_init
|
||||
|
||||
#include <move/moMoveInit.h>
|
||||
#include "bitMove.h"
|
||||
|
||||
template <class EOT>
|
||||
class BitMove_init : public moMoveInit < BitMove<EOT> > {
|
||||
|
||||
public :
|
||||
|
||||
void operator () (BitMove<EOT> & __move, const EOT & genome) {
|
||||
__move.bit = 0 ;
|
||||
};
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
33
branches/newMo/tutorial/oneMax/src/bitMove_next.h
Normal file
33
branches/newMo/tutorial/oneMax/src/bitMove_next.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
// "bitMove_next.h"
|
||||
|
||||
#ifndef __bitMove_next_h
|
||||
#define __bitMove_next_h
|
||||
|
||||
#include <move/moNextMove.h>
|
||||
#include "bitMove.h"
|
||||
|
||||
template <class EOT>
|
||||
class BitMove_next : public moNextMove < BitMove<EOT> > {
|
||||
|
||||
public:
|
||||
BitMove_next()
|
||||
{
|
||||
};
|
||||
|
||||
bool operator () (BitMove<EOT> & __move, const EOT & genome) {
|
||||
|
||||
if (__move.bit >= (genome.size() - 1)){
|
||||
return false ;
|
||||
}
|
||||
else {
|
||||
__move.bit++;
|
||||
return true ;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
33
branches/newMo/tutorial/oneMax/src/funcOneMax.h
Normal file
33
branches/newMo/tutorial/oneMax/src/funcOneMax.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// funcOneMax.h
|
||||
// 25/11/2009 : copy from FuncU.h
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __FuncOneMax
|
||||
#define __FuncOneMax
|
||||
|
||||
template< class EOT >
|
||||
class FuncOneMax : public eoEvalFunc<EOT>
|
||||
{
|
||||
private:
|
||||
unsigned N;
|
||||
|
||||
public:
|
||||
FuncOneMax(unsigned n) : N(n) {};
|
||||
|
||||
~FuncOneMax(void) {} ;
|
||||
|
||||
void operator() (EOT & genome) {
|
||||
unsigned sum = 0;
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
sum += genome[i];
|
||||
|
||||
genome.fitness(sum);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
38
branches/newMo/tutorial/oneMax/src/oneMaxBitNeighbor.h
Normal file
38
branches/newMo/tutorial/oneMax/src/oneMaxBitNeighbor.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef _oneMaxBitNeighbor_h
|
||||
#define _oneMaxBitNeighbor_h
|
||||
|
||||
#include <neighborhood/moBitNeighbor.h>
|
||||
#include <ga.h>
|
||||
|
||||
/*
|
||||
contener of the neighbor information
|
||||
*/
|
||||
template< class Fitness >
|
||||
class OneMaxBitNeighbor : public moBitNeighbor<Fitness>
|
||||
{
|
||||
public:
|
||||
typedef eoBit<Fitness> EOType ;
|
||||
|
||||
using moBitNeighbor<Fitness>::bit ;
|
||||
|
||||
/*
|
||||
* incremental evaluation of the solution for the oneMax problem
|
||||
*/
|
||||
virtual void eval(EOType & solution) {
|
||||
if (solution[bit] == 0)
|
||||
fitness(solution.fitness() + 1);
|
||||
else
|
||||
fitness(solution.fitness() - 1);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
Loading…
Add table
Add a link
Reference in a new issue