moved utilities and contribution in branchez

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2183 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2011-03-11 13:58:48 +00:00
commit 8280cf082b
1346 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,70 @@
######################################################################################
### 0) Include the install configuration file where are defined the main variables
######################################################################################
INCLUDE(${CMAKE_SOURCE_DIR}/install.cmake)
######################################################################################
######################################################################################
### 1) Set your application properties
######################################################################################
# Define your project name
PROJECT(tsp)
######################################################################################
######################################################################################
### 2) Include the sources
######################################################################################
INCLUDE_DIRECTORIES(${PARADISEO_EO_SRC_DIR}/src)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
######################################################################################
######################################################################################
### 3) Specify where CMake can find the libraries
######################################################################################
LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib)
######################################################################################
######################################################################################
### 4) Define your target: just an executable here
######################################################################################
ADD_EXECUTABLE(tsp tsp.cpp)
ADD_DEPENDENCIES(tsp ltsp)
######################################################################################
######################################################################################
### 5) Link the librairies for your executable
######################################################################################
TARGET_LINK_LIBRARIES(tsp eo eoutils ltsp)
######################################################################################
######################################################################################
### 6) Subdirs
######################################################################################
SUBDIRS(src)
######################################################################################

View file

@ -0,0 +1,105 @@
==========================================================================================
INFORMATION
==========================================================================================
PARADISEO (PARallel and DIStributed Evolving Objects) is a white-box object-oriented
framework dedicated to the flexible design of metaheursitics. This package contains
many convenient classes to solve the tsp problem with ParadisEO-EO.
An example using a genetic algorithm is also provided.
==========================================================================================
INSTRUCTIONS
==========================================================================================
To install the package, simply follow these steps:
* Edit the "install.cmake" file and replace "myDirectory" by the absolute path to ParadisEO
=> Example:
SET(PARADISEO_DIR "myDirectory" CACHE PATH "ParadisEO directory" FORCE)
replaced by:
SET(PARADISEO_DIR "/opt/paradiseo-ix86-1.0" CACHE PATH "ParadisEO directory" FORCE)
* Go in the "build" directory
* Run (in a terminal/console): cmake .. -G"<generator type>"
(Several generators exist: see http://paradiseo.gforge.inria.fr/index.php?n=Paradiseo.CmakeGenerators)
* Compile using the appropriate tool (run "make" if you choose the "Unix Makefiles" generator)
==========================================================================================
RELEASE
==========================================================================================
The current release of the tsp package is 1.0.
==========================================================================================
LINKS
==========================================================================================
You can find the package at:
http://paradiseo.gforge.inria.fr/index.php?n=Contributions.TSPEO
For any new submission, please visit:
http://paradiseo.gforge.inria.fr/index.php?n=Contributions.Submission
==========================================================================================
BUGS
==========================================================================================
You can find the ParadisEO's bug tracker at:
http://gforge.inria.fr/tracker/?atid=663&group_id=145&func=browse
==========================================================================================
CONTACT
==========================================================================================
For any question or for help, please write us at: paradiseo-help@lists.gforge.inria.fr.
==========================================================================================
DEPENDENCIES
==========================================================================================
ParadisEO uses EO, a templates-based, ANSI-C++ compliant evolutionary computation library.
It contains classes for almost any kind of evolutionary computation you might come up to - at
least for the ones we could think of.
EO Website:
http://eodev.sourceforge.net/.
EO is distributed under the GNU Lesser General Public License:
http://www.gnu.org/copyleft/lesser.html
==========================================================================================
LICENSE
==========================================================================================
ParadisEO 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.

View file

@ -0,0 +1,60 @@
NAME: berlin52
TYPE: TSP
COMMENT: 52 locations in Berlin (Groetschel)
DIMENSION: 52
EDGE_WEIGHT_TYPE: EUC_2D
NODE_COORD_SECTION
1 565.0 575.0
2 25.0 185.0
3 345.0 750.0
4 945.0 685.0
5 845.0 655.0
6 880.0 660.0
7 25.0 230.0
8 525.0 1000.0
9 580.0 1175.0
10 650.0 1130.0
11 1605.0 620.0
12 1220.0 580.0
13 1465.0 200.0
14 1530.0 5.0
15 845.0 680.0
16 725.0 370.0
17 145.0 665.0
18 415.0 635.0
19 510.0 875.0
20 560.0 365.0
21 300.0 465.0
22 520.0 585.0
23 480.0 415.0
24 835.0 625.0
25 975.0 580.0
26 1215.0 245.0
27 1320.0 315.0
28 1250.0 400.0
29 660.0 180.0
30 410.0 250.0
31 420.0 555.0
32 575.0 665.0
33 1150.0 1160.0
34 700.0 580.0
35 685.0 595.0
36 685.0 610.0
37 770.0 610.0
38 795.0 645.0
39 720.0 635.0
40 760.0 650.0
41 475.0 960.0
42 95.0 260.0
43 875.0 920.0
44 700.0 500.0
45 555.0 815.0
46 830.0 485.0
47 1170.0 65.0
48 830.0 610.0
49 605.0 625.0
50 595.0 360.0
51 1340.0 725.0
52 1740.0 245.0
EOF

View file

@ -0,0 +1,108 @@
NAME: eil101
TYPE: TSP
COMMENT: 101-city problem (Christofides/Eilon)
DIMENSION: 101
EDGE_WEIGHT_TYPE: EUC_2D
NODE_COORD_SECTION
1 41 49
2 35 17
3 55 45
4 55 20
5 15 30
6 25 30
7 20 50
8 10 43
9 55 60
10 30 60
11 20 65
12 50 35
13 30 25
14 15 10
15 30 5
16 10 20
17 5 30
18 20 40
19 15 60
20 45 65
21 45 20
22 45 10
23 55 5
24 65 35
25 65 20
26 45 30
27 35 40
28 41 37
29 64 42
30 40 60
31 31 52
32 35 69
33 53 52
34 65 55
35 63 65
36 2 60
37 20 20
38 5 5
39 60 12
40 40 25
41 42 7
42 24 12
43 23 3
44 11 14
45 6 38
46 2 48
47 8 56
48 13 52
49 6 68
50 47 47
51 49 58
52 27 43
53 37 31
54 57 29
55 63 23
56 53 12
57 32 12
58 36 26
59 21 24
60 17 34
61 12 24
62 24 58
63 27 69
64 15 77
65 62 77
66 49 73
67 67 5
68 56 39
69 37 47
70 37 56
71 57 68
72 47 16
73 44 17
74 46 13
75 49 11
76 49 42
77 53 43
78 61 52
79 57 48
80 56 37
81 55 54
82 15 47
83 14 37
84 11 31
85 16 22
86 4 18
87 28 18
88 26 52
89 26 35
90 31 67
91 15 19
92 22 22
93 18 24
94 26 27
95 25 24
96 22 27
97 25 21
98 19 21
99 20 26
100 18 18
101 35 35
EOF

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,93 @@
All the instances in this directory come from the TSPLIB database. All the TSPLIB instances can be downloaded at this address:
http://www.iwr.uni-heidelberg.de/groups/comopt/software/TSPLIB95/tsp/
The accepted format is:
NAME: instance_name
TYPE: TSP
COMMENT: comments about the instance
DIMENSION: number of towns.
EDGE_WEIGHT_TYPE: EUC_2D
NODE_COORD_SECTION
1 565.0 575.0
2 25.0 185.0
3 345.0 750.0
.
.
.
.
.
.
EOF
Compatibility bugs with some TSPLIB instances (soon corrected):
==> some instances have a space after a section title, for example "NAME :" instead of "NAME:".
==> several instances have the "COMMENT:" section before the "TYPE:" section.
==> several section are not yet implemented ("DISPLAY_DATA_TYPE:", ...).
Already corrected bugs:
==> some instances have several lines with the keyword "COMMENTS:"
For instance, the Berlin52 instance:
NAME: berlin52
TYPE: TSP
COMMENT: 52 locations in Berlin (Groetschel)
DIMENSION: 52
EDGE_WEIGHT_TYPE: EUC_2D
NODE_COORD_SECTION
1 565.0 575.0
2 25.0 185.0
3 345.0 750.0
4 945.0 685.0
5 845.0 655.0
6 880.0 660.0
7 25.0 230.0
8 525.0 1000.0
9 580.0 1175.0
10 650.0 1130.0
11 1605.0 620.0
12 1220.0 580.0
13 1465.0 200.0
14 1530.0 5.0
15 845.0 680.0
16 725.0 370.0
17 145.0 665.0
18 415.0 635.0
19 510.0 875.0
20 560.0 365.0
21 300.0 465.0
22 520.0 585.0
23 480.0 415.0
24 835.0 625.0
25 975.0 580.0
26 1215.0 245.0
27 1320.0 315.0
28 1250.0 400.0
29 660.0 180.0
30 410.0 250.0
31 420.0 555.0
32 575.0 665.0
33 1150.0 1160.0
34 700.0 580.0
35 685.0 595.0
36 685.0 610.0
37 770.0 610.0
38 795.0 645.0
39 720.0 635.0
40 760.0 650.0
41 475.0 960.0
42 95.0 260.0
43 875.0 920.0
44 700.0 500.0
45 555.0 815.0
46 830.0 485.0
47 1170.0 65.0
48 830.0 610.0
49 605.0 625.0
50 595.0 360.0
51 1340.0 725.0
52 1740.0 245.0
EOF

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,50 @@
#########################################################################################################
# 1) ParadisEO install: SIMPLE Configuration
#########################################################################################################
# Here, just specify PARADISEO_DIR : the directory where ParadisEO has been installed
SET(PARADISEO_DIR "myDirectory" 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)
SET(PARADISEO_MO_SRC_DIR "${PARADISEO_DIR}/paradiseo-mo" CACHE PATH "ParadisEO-MO source directory" FORCE)
SET(PARADISEO_MO_BIN_DIR "${PARADISEO_DIR}/paradiseo-mo/build" CACHE PATH "ParadisEO-MO binary directory" FORCE)
SET(PARADISEO_MOEO_SRC_DIR "${PARADISEO_DIR}/paradiseo-moeo" CACHE PATH "ParadisEO-MOEO source directory" FORCE)
SET(PARADISEO_MOEO_BIN_DIR "${PARADISEO_DIR}/paradiseo-moeo/build" CACHE PATH "ParadisEO-MOEO binary directory" FORCE)
SET(PARADISEO_PEO_SRC_DIR "${PARADISEO_DIR}/paradiseo-peo" CACHE PATH "ParadisEO-PEO source directory" FORCE)
SET(PARADISEO_PEO_BIN_DIR "${PARADISEO_DIR}/paradiseo-peo/build" CACHE PATH "ParadisEO-PEO binary directory" FORCE)
#########################################################################################################
######################################################################################
### 3) OPTIONNAL: Windows advanced config - especially for Microsoft Visual Studio 8
######################################################################################
IF(CMAKE_CXX_COMPILER MATCHES cl)
IF(NOT WITH_SHARED_LIBS)
IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /Gy")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE")
ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005")
ENDIF(NOT WITH_SHARED_LIBS)
ENDIF(CMAKE_CXX_COMPILER MATCHES cl)
######################################################################################

View file

@ -0,0 +1,16 @@
###### General ######
# --help=0 # -h : Prints this message
# --stopOnUnknownParam=1 # Stop if unkown param entered
###### Configuration ######
# --instancePath=benchs/berlin52.tsp # Path to the instance.
# --seed=1203082112 # Seed for rand.
# --popSize=100 # Size of the population.
# --maxIter=1000 # Maximum number of iterations.
# --crossRate=1 # Probability of crossover.
# --mutRate=0.01 # Probability of mutation.
# --nbSelPar=100 # Number of selected parents.
# --elitismRate=1 # Percentage of the best individuals kept.
# --tournRate=0.7 # Percentage of the individuals used during the tournament.
# --crossType=Partial # Crossover to use, it can be 'Partial', 'Order' or 'Edge'.

View file

@ -0,0 +1,61 @@
######################################################################################
### 0) Copy the "benchs" directory in the build directory
######################################################################################
ADD_CUSTOM_TARGET(install DEPENDS ${CMAKE_SOURCE_DIR}/benchs)
ADD_CUSTOM_COMMAND(
TARGET install
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy_directory
${CMAKE_SOURCE_DIR}/benchs
${CMAKE_BINARY_DIR}/benchs)
##########################################################################################
######################################################################################
### 1) Include the sources
######################################################################################
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
######################################################################################
######################################################################################
### 2) Define your target(s): just the tsp lib here
######################################################################################
SET(TSP_LIB_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
SET(LIBRARY_OUTPUT_PATH ${TSP_LIB_OUTPUT_PATH})
SET (TSP_SOURCES
city_swap.h
city_swap.cpp
edge_xover.h
edge_xover.cpp
graph.h
graph.cpp
mix.h
order_xover.h
order_xover.cpp
part_route_eval.h
part_route_eval.cpp
partial_mapped_xover.h
partial_mapped_xover.cpp
route.h
route_eval.h
route_eval.cpp
route_init.h
route_init.cpp
route_valid.h
route_valid.cpp)
ADD_LIBRARY(ltsp STATIC ${TSP_SOURCES})
######################################################################################

View file

@ -0,0 +1,50 @@
/*
* <city_swap.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include <utils/eoRNG.h>
#include "city_swap.h"
bool CitySwap :: operator () (Route & __route)
{
std :: swap (__route [rng.random (__route.size ())],
__route [rng.random (__route.size ())]) ;
__route.invalidate () ;
return true ;
}

View file

@ -0,0 +1,55 @@
/*
* <city_swap.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef city_swap_h
#define city_swap_h
#include <eoOp.h>
#include "route.h"
/** Its swaps two vertices
randomly choosen */
class CitySwap : public eoMonOp <Route>
{
public :
bool operator () (Route & __route) ;
} ;
#endif

View file

@ -0,0 +1,169 @@
/*
* <edge_xover.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include <assert.h>
#include <utils/eoRNG.h>
#include "edge_xover.h"
#include "route_valid.h"
#define MAXINT 1000000
void
EdgeXover :: build_map (const Route & __par1, const Route & __par2)
{
unsigned int len = __par1.size () ;
/* Initialization */
_map.clear () ;
_map.resize (len) ;
for (unsigned int i = 0 ; i < len ; i ++)
{
_map [__par1 [i]].insert (__par1 [(i + 1) % len]) ;
_map [__par2 [i]].insert (__par2 [(i + 1) % len]) ;
_map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ;
_map [__par2 [i]].insert (__par2 [(i - 1 + len) % len]) ;
}
visited.clear () ;
visited.resize (len, false) ;
}
void
EdgeXover :: remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned int> > & __map)
{
std :: set <unsigned int> & neigh = __map [__vertex] ;
for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
{
__map [* it].erase (__vertex) ;
}
}
void
EdgeXover :: add_vertex (unsigned int __vertex, Route & __child)
{
visited [__vertex] = true ;
__child.push_back (__vertex) ;
remove_entry (__vertex, _map) ; /* Removing entries */
}
void
EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
{
build_map (__par1, __par2) ;
unsigned int len = __par1.size () ;
/* Go ! */
__child.clear () ;
unsigned int cur_vertex = rng.random (len) ;
add_vertex (cur_vertex, __child) ;
for (unsigned int i = 1 ; i < len ; i ++)
{
unsigned int len_min_entry = MAXINT ;
std :: set <unsigned int> & neigh = _map [cur_vertex] ;
for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
{
unsigned int l = _map [* it].size () ;
if (len_min_entry > l)
{
len_min_entry = l ;
}
}
std :: vector <unsigned int> cand ; /* Candidates */
for (std :: set <unsigned> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
{
unsigned int l = _map [* it].size () ;
if (len_min_entry == l)
{
cand.push_back (* it) ;
}
}
if (! cand.size ())
{
/* Oh no ! Implicit mutation */
for (unsigned int j = 0 ; j < len ; j ++)
{
if (! visited [j])
{
cand.push_back (j) ;
}
}
}
cur_vertex = cand [rng.random (cand.size ())] ;
add_vertex (cur_vertex, __child) ;
}
}
bool
EdgeXover :: operator () (Route & __route1, Route & __route2)
{
// Init. copy
Route par [2] ;
par [0] = __route1 ;
par [1] = __route2 ;
cross (par [0], par [1], __route1) ;
cross (par [1], par [0], __route2) ;
assert (valid (__route1)) ;
assert (valid (__route2)) ;
__route1.invalidate () ;
__route2.invalidate () ;
return true ;
}

View file

@ -0,0 +1,72 @@
/*
* <edge_xover.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef edge_xover_h
#define edge_xover_h
#include <vector>
#include <set>
#include <eoOp.h>
#include "route.h"
/** Edge Crossover */
class EdgeXover : public eoQuadOp <Route>
{
public :
bool operator () (Route & __route1, Route & __route2) ;
private :
void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */
void remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned> > & __map) ;
/* Updating the map of entries */
void build_map (const Route & __par1, const Route & __par2) ;
void add_vertex (unsigned int __vertex, Route & __child) ;
std :: vector <std :: set <unsigned int> > _map ; /* The handled map */
std :: vector <bool> visited ; /* Vertices that are already visited */
} ;
#endif

View file

@ -0,0 +1,207 @@
/*
* <graph.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include "graph.h"
using std::cout;
using std::endl;
namespace Graph
{
static std :: vector <std :: pair <double, double> > vectCoord ; // Coordinates
static std :: vector <std :: vector <unsigned int> > dist ; // Distances Mat.
unsigned size ()
{
return dist.size () ;
}
void computeDistances ()
{
// Dim.
unsigned int numCities = vectCoord.size () ;
dist.resize (numCities) ;
for (unsigned int i = 0 ; i < dist.size () ; i ++)
{
dist [i].resize (numCities) ;
}
// Computations.
for (unsigned int i = 0 ; i < dist.size () ; i ++)
{
for (unsigned int j = i + 1 ; j < dist.size () ; j ++)
{
double distX = (double)(vectCoord [i].first - vectCoord [j].first) ;
double distY = (double)(vectCoord [i].second - vectCoord [j].second) ;
dist [i] [j] = dist [j] [i] = (unsigned int) (sqrt ((float) (distX * distX + distY * distY)) + 0.5) ;
}
}
}
void load (const char * _fileName)
{
unsigned int i, dimension;
std::string string_read, buffer;
std :: ifstream file (_fileName) ;
cout << endl << "\tLoading [" << _fileName << "]" << endl << endl;
if( file.is_open() )
{
// Read NAME:
file >> string_read;
if (string_read.compare("NAME:")!=0)
{
cout << "ERROR: \'NAME:\' espected, \'" << string_read << "\' found" << endl;
exit(EXIT_FAILURE);
}
// Read instance name
file >> string_read;
cout << "\t\tInstance Name = " << string_read << endl;
// Read TYPE:
file >> string_read;
if (string_read.compare("TYPE:")!=0)
{
cout << "ERROR: \'TYPE:\' espected, \'" << string_read << "\' found" << endl;
exit(EXIT_FAILURE);
}
// Read instance type;
file >> string_read;
cout << "\t\tInstance type = " << string_read << endl;
if (string_read.compare("TSP")!=0)
{
cout << "ERROR: only TSP type instance can be loaded" << endl;
exit(EXIT_FAILURE);
}
// Read COMMENT:
file >> string_read;
if (string_read.compare("COMMENT:")!=0)
{
cout << "ERROR: \'COMMENT:\' espected, \'" << string_read << "\' found" << endl;
exit(EXIT_FAILURE);
}
// Read comments
cout << "\t\tInstance comments = ";
file >> string_read;
buffer = string_read+"_first";
while((string_read.compare("DIMENSION:")!=0) && (string_read.compare(buffer)!=0))
{
if(string_read.compare("COMMENT:")!=0)
{
cout << string_read << " ";
}
else
{
cout << endl << "\t ";
}
buffer = string_read;
file >> string_read;
}
cout << endl;
// Read dimension;
file >> dimension ;
cout << "\t\tInstance dimension = " << dimension << endl;
vectCoord.resize (dimension) ;
// Read EDGE_WEIGHT_TYPE
file >> string_read;
if (string_read.compare("EDGE_WEIGHT_TYPE:")!=0)
{
cout << "ERROR: \'EDGE_WEIGHT_TYPE:\' espected, \'" << string_read << "\' found" << endl;
exit(EXIT_FAILURE);
}
// Read edge weight type
file >> string_read;
cout << "\t\tInstance edge weight type = " << string_read << endl;
if (string_read.compare("EUC_2D")!=0)
{
cout << "ERROR: only EUC_2D edge weight type instance can be loaded" << endl;
exit(EXIT_FAILURE);
}
// Read NODE_COORD_SECTION
file >> string_read;
if (string_read.compare("NODE_COORD_SECTION")!=0)
{
cout << "ERROR: \'NODE_COORD_SECTION\' espected, \'" << string_read << "\' found" << endl;
exit(EXIT_FAILURE);
}
// Read coordonates.
for(i=0;i<dimension;i++)
{
// Read index
file >> string_read;
//Read Coordinate
file >> vectCoord [i].first >> vectCoord [i].second ;
}
// Read EOF
file >> string_read;
if(string_read.compare("EOF")!=0)
{
cout << "ERROR: \'EOF\' espected, \'" << string_read << "\' found" << endl;
exit(EXIT_FAILURE);
}
cout << endl;
file.close () ;
computeDistances () ;
}
else
{
cout << _fileName << " does not exist !!!" << endl ;
exit(EXIT_FAILURE) ;
}
}
float distance (unsigned int _from, unsigned int _to)
{
return (float)(dist [_from] [_to]) ;
}
}

View file

@ -0,0 +1,60 @@
/*
* <graph.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef graph_h
#define graph_h
#include <string>
#include <vector>
#include <utility>
#include <fstream>
#include <iostream>
#include <math.h>
namespace Graph
{
void load (const char * _file_name) ;
/* Loading cities
(expressed by their coordinates)
from the given file name */
float distance (unsigned int _from, unsigned int _to) ;
unsigned int size () ; // How many cities ?
}
#endif

View file

@ -0,0 +1,50 @@
/*
* <mix.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef mix_h
#define mix_h
#include <utils/eoRNG.h>
template <class T> void mix (std :: vector <T> & __vect)
{
for (unsigned int i = 0 ; i < __vect.size () ; i ++)
{
std :: swap (__vect [i], __vect [rng.random (__vect.size ())]) ;
}
}
#endif

View file

@ -0,0 +1,119 @@
/*
* <order_xover.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include <assert.h>
#include <vector>
#include <utils/eoRNG.h>
#include "order_xover.h"
#include "route_valid.h"
void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
{
unsigned int cut = rng.random (__par1.size ()) ;
/* To store vertices that have
already been crossed */
std::vector<bool> v;
v.resize(__par1.size());
for (unsigned int i = 0 ; i < __par1.size () ; i ++)
{
v [i] = false ;
}
/* Copy of the left partial
route of the first parent */
for (unsigned int i = 0 ; i < cut ; i ++)
{
__child [i] = __par1 [i] ;
v [__par1 [i]] = true ;
}
/* Searching the vertex of the second path, that ended
the previous first one */
unsigned int from = 0 ;
for (unsigned int i = 0 ; i < __par2.size () ; i ++)
{
if (__par2 [i] == __child [cut - 1])
{
from = i ;
break ;
}
}
/* Selecting a direction
Left or Right */
char direct = rng.flip () ? 1 : -1 ;
/* Copy of the left vertices from
the second parent path */
unsigned int l = cut ;
for (unsigned int i = 0 ; i < __par2.size () ; i ++)
{
unsigned int bidule /* :-) */ = (direct * i + from + __par2.size ()) % __par2.size () ;
if (! v [__par2 [bidule]])
{
__child [l ++] = __par2 [bidule] ;
v [__par2 [bidule]] = true ;
}
}
v.clear();
}
bool OrderXover :: operator () (Route & __route1, Route & __route2)
{
// Init. copy
Route par [2] ;
par [0] = __route1 ;
par [1] = __route2 ;
cross (par [0], par [1], __route1) ;
cross (par [1], par [0], __route2) ;
assert (valid (__route1)) ;
assert (valid (__route2)) ;
__route1.invalidate () ;
__route2.invalidate () ;
return true ;
}

View file

@ -0,0 +1,57 @@
/*
* <order_xover.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef order_xover_h
#define order_xover_h
#include <eoOp.h>
#include "route.h"
/** Order Crossover */
class OrderXover : public eoQuadOp <Route>
{
public :
bool operator () (Route & __route1, Route & __route2) ;
private :
void cross (const Route & __par1, const Route & __par2, Route & __child) ;
} ;
#endif

View file

@ -0,0 +1,53 @@
/*
* <part_route_eval.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include "part_route_eval.h"
#include "graph.h"
PartRouteEval :: PartRouteEval (float __from, float __to) : from (__from), to (__to)
{}
void PartRouteEval :: operator () (Route & __route)
{
float len = 0 ;
for (unsigned int i = (unsigned int) (__route.size () * from) ; i < (unsigned int ) (__route.size () * to) ; i ++)
{
len += Graph :: distance (__route [i], __route [(i + 1) % Graph :: size ()]) ;
}
__route.fitness (len) ;
}

View file

@ -0,0 +1,62 @@
/*
* <part_route_eval.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef part_route_eval_h
#define part_route_eval_h
#include <eoEvalFunc.h>
#include "route.h"
/** Route Evaluator */
class PartRouteEval : public eoEvalFunc <Route>
{
public :
/** Constructor */
PartRouteEval (float __from, float __to) ;
void operator () (Route & __route) ;
private :
float from, to ;
} ;
#endif

View file

@ -0,0 +1,118 @@
/*
* <partial_mapped_xover.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include <assert.h>
#include <vector>
#include <utils/eoRNG.h>
#include "partial_mapped_xover.h"
#include "route_valid.h"
#include "mix.h"
void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2)
{
std::vector<unsigned int> v; // Number of times a cities are visited ...
v.resize(__route.size ());
for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
v [i] = 0 ;
}
for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
v [__route [i]] ++ ;
}
std :: vector <unsigned int> vert ;
for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
if (! v [i])
{
vert.push_back (i) ;
}
}
mix (vert) ;
for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
if (i < __cut1 || i >= __cut2)
{
if (v [__route [i]] > 1)
{
__route [i] = vert.back () ;
vert.pop_back () ;
}
}
}
v.clear();
}
bool PartialMappedXover :: operator () (Route & __route1, Route & __route2)
{
unsigned int cut1 = rng.random (__route1.size ()), cut2 = rng.random (__route2.size ()) ;
if (cut2 < cut1)
{
std :: swap (cut1, cut2) ;
}
// Between the cuts
for (unsigned int i = cut1 ; i < cut2 ; i ++)
{
std :: swap (__route1 [i], __route2 [i]) ;
}
// Outside the cuts
repair (__route1, cut1, cut2) ;
repair (__route2, cut1, cut2) ;
// Debug
assert (valid (__route1)) ;
assert (valid (__route2)) ;
__route1.invalidate () ;
__route2.invalidate () ;
return true ;
}

View file

@ -0,0 +1,57 @@
/*
* <partial_mapped_xover.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef partial_mapped_xover_h
#define partial_mapped_xover_h
#include <eoOp.h>
#include "route.h"
/** Partial Mapped Crossover */
class PartialMappedXover : public eoQuadOp <Route>
{
public :
bool operator () (Route & __route1, Route & __route2) ;
private :
void repair (Route & __route, unsigned __cut1, unsigned __cut2) ;
} ;
#endif

View file

@ -0,0 +1,48 @@
/*
* <route.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef route_h
#define route_h
#include <eoVector.h>
#include <eoScalarFitness.h>
// A float that has to be minimized.
typedef eoScalarFitness< float, std::greater<float> > tspFitness ;
typedef eoVector <tspFitness, unsigned int> Route ; // [Fitness (length), Gene (city)]
#endif

View file

@ -0,0 +1,51 @@
/*
* <route_eval.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include "route_eval.h"
#include "graph.h"
void RouteEval :: operator () (Route & __route)
{
float len = 0.0 ;
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
{
len += Graph :: distance (__route [i], __route [(i + 1) % Graph :: size ()]) ;
}
__route.fitness (len) ;
}

View file

@ -0,0 +1,55 @@
/*
* <route_eval.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef route_eval_h
#define route_eval_h
#include <eoEvalFunc.h>
#include "route.h"
/** Route Evaluator */
class RouteEval : public eoEvalFunc <Route>
{
public :
void operator () (Route & __route) ;
} ;
#endif

View file

@ -0,0 +1,63 @@
/*
* <route_init.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include <utils/eoRNG.h>
#include "route_init.h"
#include "graph.h"
void RouteInit :: operator () (Route & __route)
{
// Init.
__route.clear () ;
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
{
__route.push_back (i) ;
}
// Swap. cities
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
{
//unsigned int j = rng.random (Graph :: size ()) ;
unsigned int j = (unsigned int) (Graph :: size () * (rand () / (RAND_MAX + 1.0))) ;
unsigned int city = __route [i] ;
__route [i] = __route [j] ;
__route [j] = city ;
}
}

View file

@ -0,0 +1,53 @@
/*
* <route_init.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef route_init_h
#define route_init_h
#include <eoInit.h>
#include "route.h"
class RouteInit : public eoInit <Route>
{
public :
void operator () (Route & __route) ;
} ;
#endif

View file

@ -0,0 +1,68 @@
/*
* <route_valid.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include "route_valid.h"
#include <vector>
bool valid (Route & __route)
{
std::vector<unsigned int> t;
t.resize(__route.size());
for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
t [i] = 0 ;
}
for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
t [__route [i]] ++ ;
}
for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
if (t [i] != 1)
{
t.clear();
return false ;
}
}
t.clear();
return true ; // OK.
}

View file

@ -0,0 +1,44 @@
/*
* <route_valid.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Jean-Charles Boisson
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#ifndef route_valid_h
#define route_valid_h
#include "route.h"
bool valid (Route & __route) ;
#endif

View file

@ -0,0 +1,41 @@
/*
* <tsp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* 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 __tsp
#define __tsp
#include "tsp.h"
#endif

View file

@ -0,0 +1,52 @@
/*
* <tsp.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* 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 __tsp_h
#define __tsp_h
#include "city_swap.h"
#include "edge_xover.h"
#include "graph.h"
#include "mix.h"
#include "order_xover.h"
#include "partial_mapped_xover.h"
#include "part_route_eval.h"
#include "route_eval.h"
#include "route.h"
#include "route_init.h"
#include "route_valid.h"
#endif

View file

@ -0,0 +1,160 @@
/*
* <tsp.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Sébastien Cahon, Thomas Legrand
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
#include <eo>
#include <tsp>
void manage_configuration_file(eoParser & _parser);
int
main (int _argc, char* _argv [])
{
std::string instancePath, crossoverType;
unsigned int seed, populationSize, maxIterations, selectedParentNumber;
double crossoverRate, mutationRate, elitismRate, tournamentRate;
eoParser parser(_argc, _argv);
manage_configuration_file(parser);
seed=atoi( (parser.getParamWithLongName("seed")->getValue()).c_str() );
instancePath=parser.getParamWithLongName("instancePath")->getValue();
populationSize=atoi( (parser.getParamWithLongName("popSize")->getValue()).c_str() );
maxIterations=atoi( (parser.getParamWithLongName("maxIter")->getValue()).c_str() );
crossoverRate=atof( (parser.getParamWithLongName("crossRate")->getValue()).c_str() );
mutationRate=atof( (parser.getParamWithLongName("mutRate")->getValue()).c_str() );
selectedParentNumber=atoi( (parser.getParamWithLongName("nbSelPar")->getValue()).c_str() );
elitismRate=atof( (parser.getParamWithLongName("elitismRate")->getValue()).c_str() );
tournamentRate=atof( (parser.getParamWithLongName("tournRate")->getValue()).c_str() );
crossoverType=parser.getParamWithLongName("crossType")->getValue();
srand (seed);
Graph::load(instancePath.c_str());
RouteInit init ;
RouteEval full_eval ;
eoPop <Route> pop (populationSize, init) ;
apply <Route> (full_eval, pop) ;
std :: cout << "[From] " << pop.best_element () << std :: endl ;
eoGenContinue <Route> continu (maxIterations) ;
eoStochTournamentSelect <Route> select_one ;
eoSelectNumber <Route> select (select_one, selectedParentNumber) ;
eoQuadOp <Route>*crossover;
if(crossoverType.compare("Partial")==0)
{
crossover=new PartialMappedXover();
}
else if (crossoverType.compare("Order")==0)
{
crossover=new OrderXover();
}
else if (crossoverType.compare("Edge")==0)
{
crossover=new EdgeXover();
}
else
{
throw std::runtime_error("[tsp.cpp]: the crossover type '"+crossoverType+"' is not correct.");
}
CitySwap mutation ;
eoSGATransform <Route> transform (*crossover, crossoverRate, mutation, mutationRate) ;
eoElitism <Route> merge (elitismRate) ;
eoStochTournamentTruncate <Route> reduce (tournamentRate) ;
eoEasyEA <Route> ea (continu, full_eval, select, transform, merge, reduce) ;
ea (pop) ;
std :: cout << "[To] " << pop.best_element () << std :: endl ;
delete(crossover);
return EXIT_SUCCESS;
}
void
manage_configuration_file(eoParser & _parser)
{
std::ofstream os;
_parser.getORcreateParam(std::string("benchs/berlin52.tsp"), "instancePath", "Path to the instance.",
0, "Configuration", false);
_parser.getORcreateParam((unsigned int)time(0), "seed", "Seed for rand.", 0, "Configuration", false);
_parser.getORcreateParam((unsigned int)100, "popSize", "Size of the population.", 0, "Configuration", false);
_parser.getORcreateParam((unsigned int)1000, "maxIter", "Maximum number of iterations.", 0, "Configuration", false);
_parser.getORcreateParam((double)1.0, "crossRate", "Probability of crossover.", 0, "Configuration", false);
_parser.getORcreateParam((double)0.01, "mutRate", "Probability of mutation.", 0, "Configuration", false);
_parser.getORcreateParam((unsigned int)100, "nbSelPar", "Number of selected parents.", 0, "Configuration", false);
_parser.getORcreateParam((double)1.0, "elitismRate", "Percentage of the best individuals kept.", 0, "Configuration", false);
_parser.getORcreateParam((double)0.7, "tournRate", "Percentage of the individuals used during the tournament.",
0, "Configuration", false);
_parser.getORcreateParam(std::string("Partial"), "crossType", "Crossover to use, it can be 'Partial', 'Order' or 'Edge'.",
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("[tsp.cpp]: the file current_param cannot be created.");
}
os <<_parser;
os.close();
}