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:
parent
6c3383d718
commit
8280cf082b
1346 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src/utils)
|
||||
INCLUDE_DIRECTORIES(${MO_SRC_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/tsp/src)
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${CMAKE_BINARY_DIR}/tsp/src)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your target(s): just an executable here
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(gen_algo gen_algo.cpp)
|
||||
|
||||
ADD_DEPENDENCIES(gen_algo tsp)
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 4) Link the librairies for your target(s)
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(gen_algo tsp eo eoutils)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
// "gen_algo.cpp"
|
||||
|
||||
#include <eoEasyEA.h>
|
||||
#include <eoGenContinue.h>
|
||||
#include <eoStochTournamentSelect.h>
|
||||
#include <eoSGATransform.h>
|
||||
#include <eoSelectNumber.h>
|
||||
|
||||
#include "graph.h"
|
||||
#include "route.h"
|
||||
#include "route_init.h"
|
||||
#include "route_eval.h"
|
||||
#include "order_xover.h"
|
||||
#include "partial_mapped_xover.h"
|
||||
#include "city_swap.h"
|
||||
|
||||
int main (int __argc, char * __argv []) {
|
||||
|
||||
if (__argc != 2) {
|
||||
|
||||
std :: cerr << "Usage : ./gen_algo [instance]" << std :: endl ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
Graph :: load (__argv [1]) ; // Instance
|
||||
|
||||
RouteInit init ; // Sol. Random Init.
|
||||
|
||||
RouteEval full_eval ; // Full Evaluator
|
||||
|
||||
eoPop <Route> pop (100, init) ; // Population
|
||||
apply <Route> (full_eval, pop) ;
|
||||
|
||||
std :: cout << "[From] " << pop.best_element () << std :: endl ;
|
||||
|
||||
eoGenContinue <Route> cont (1000) ; /* Continuator (A fixed number of
|
||||
1000 iterations */
|
||||
|
||||
eoStochTournamentSelect <Route> select_one ; // Selector
|
||||
|
||||
eoSelectNumber <Route> select (select_one, 100) ;
|
||||
|
||||
// OrderXover cross ; // Order Crossover
|
||||
PartialMappedXover cross ;
|
||||
|
||||
CitySwap mut ; // City Swap Mutator
|
||||
|
||||
eoSGATransform <Route> transform (cross, 1, mut, 0.01) ;
|
||||
|
||||
eoElitism <Route> merge (1) ; // Use of Elistism
|
||||
|
||||
eoStochTournamentTruncate <Route> reduce (0.7) ; // Stoch. Replacement
|
||||
|
||||
eoEasyEA <Route> ea (cont, full_eval, select, transform, merge, reduce) ;
|
||||
|
||||
ea (pop) ;
|
||||
|
||||
std :: cout << "[To] " << pop.best_element () << std :: endl ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
Binary file not shown.
|
|
@ -0,0 +1,98 @@
|
|||
\documentclass[a4paper]{article}
|
||||
|
||||
\usepackage[english]{babel}
|
||||
\usepackage{epsf}
|
||||
\usepackage{amssymb}
|
||||
\usepackage{here}
|
||||
\usepackage{comment}
|
||||
\usepackage{graphicx}
|
||||
|
||||
\topmargin -2.5cm
|
||||
\textheight 25,5cm
|
||||
\textwidth 16cm
|
||||
\oddsidemargin 0cm
|
||||
\evensidemargin 0cm
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
||||
\textbf{ParadisEO Practices} {\copyright Franck Seynhaeve,
|
||||
Jean-Charles Boisson, Thomas Legrand} \Large{\textbf{\\\\
|
||||
Lesson 5: Implement a genetic algorithm using ParadisEO}}
|
||||
|
||||
\normalsize
|
||||
|
||||
\vspace{-0,3cm}
|
||||
|
||||
\section{Example}
|
||||
|
||||
The archive {\tt paradiseo\_practices\_0208.tgz} installed
|
||||
on your computer contains a genetic algorithm implemented using ParadisEO-EO~
|
||||
(see {\tt gen\_algo} in the {\bf build/lesson5} directory).
|
||||
|
||||
\medskip
|
||||
To run it, please go in {\bf build/lesson5} and start the program {\tt gen\_algo} by giving
|
||||
one of the TSP instances located in {\bf tsp/benchs}.
|
||||
|
||||
\medskip
|
||||
When entering {\tt ./gen\_algo ../../tsp/benchs/berlin52.tsp}, you should end up with the
|
||||
following outputs:
|
||||
|
||||
\texttt{>> Loading [../../tsp/benchs/eil101.tsp]}\\
|
||||
\texttt{[From] -3176 101 5 72 27 77 20 82 23 14 91 17 60 50 43 99 18 34 69}\\
|
||||
\texttt{76 22 38 25 88 36 40 7 55 74 42 67 53 11 62 61 92 58 93 19 70 33 32}\\
|
||||
\texttt{86 48 47 4 97 73 95 79 85 66 65 24 13 89 8 26 96 56 28 39 80 37 49}\\
|
||||
\texttt{78 12 1 98 46 31 57 10 30 90 71 75 81 16 45 29 41 100 51 21 52 59 15}\\
|
||||
\texttt{64 44 94 54 9 6 3 0 87 63 2 84 83 35 68 STOP in eoGenContinue:}\\
|
||||
\texttt{Reached maximum number of generations [1000/1000]}\\
|
||||
\texttt{[To] -1564 101 60}\\
|
||||
\texttt{17 81 59 5 94 43 42 14 40 13 15 82 45 46 35 51 26 100 74 38 24 22 21}\\
|
||||
\texttt{54 23 66 86 99 44 87 64 34 57 25 32 75 80 29 79 67 53 3 1 58 95 97}\\
|
||||
\texttt{90 85 37 83 16 92 91 36 41 96 93 52 56 12 33 77 70 30 88 39 20 72 71}\\
|
||||
\texttt{ 31 62 89 61 49 2 8 18 6 10 9 0 68 78 28 27 76 11 73 55 50 65 19 69}\\
|
||||
\texttt{48 63 47 7 4 98 84}\\
|
||||
|
||||
|
||||
\medskip
|
||||
|
||||
The printed-out results show for the initial best solution and the final one~:
|
||||
\\ \hspace*{0.5cm}-the length of the route
|
||||
\\ \hspace*{0.5cm}-the number of cities
|
||||
\\ \hspace*{0.5cm}-the route itself (notice that the city index starts from 0).
|
||||
|
||||
|
||||
\section{Study the genetic algorithm dedicated components}
|
||||
|
||||
Study the {\tt gen\_algo.cpp} file located in the {\bf lesson5} directory
|
||||
using~:
|
||||
\begin{itemize}
|
||||
\item[$\bullet$] the ParadisEO-EO API documentation available at~:
|
||||
|
||||
\hspace{1cm}http$\,:$//eodev.sourceforge.net/eo/doc/html/index.html
|
||||
|
||||
\item[$\bullet$] the source files located in the {\bf tsp/src/} directory
|
||||
\end{itemize}
|
||||
|
||||
|
||||
\section{Customize the GA}
|
||||
|
||||
Make a backup (copy) of the cpp file {\tt gen\_algo.cpp}. You can now modify the
|
||||
original {\tt gen\_algo.cpp} and use the existing makefiles to compile it.
|
||||
|
||||
Edit and modify the {\tt gen\_algo.cpp} file~:
|
||||
\begin{itemize}
|
||||
\item[$\bullet$] Try to tune a few parameters of the GA
|
||||
(selection criteria, stopping criteria ...).
|
||||
\item[$\bullet$] Then, try to change the initialization of the population
|
||||
by applying one of the local searches on each individual.
|
||||
\end{itemize}
|
||||
|
||||
\smallskip
|
||||
To compile {\tt gen\_algo.cpp},you should use the
|
||||
command {\tt make} from {\bf build/lesson5}.
|
||||
|
||||
\medskip
|
||||
Finally, test your modifications on several TSP instances ({\tt berlin52},
|
||||
{\tt eil101} ...) and compare the results you get.
|
||||
|
||||
\end{document}
|
||||
Loading…
Add table
Add a link
Reference in a new issue