added practices to version control
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1002 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
71d4fd59ee
commit
22c6962aa2
72 changed files with 25134 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,93 @@
|
|||
\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:
|
||||
|
||||
\smallskip
|
||||
\noindent
|
||||
\texttt{>> Loading [../tsp/benchs/berlin52.tsp]}\\
|
||||
\texttt{[From] -26461 52 39 12 29 44 2 26 13 40 7 35 14 28 25 41 6 51 10 50 45 19 0 38 15}\\
|
||||
\texttt{33 42 21 18 32 37 9 5 20 34 43 16 30 1 23 22 4 27 36 4946 47 48 11 17 8 31 24 3}\\
|
||||
\texttt{STOP in eoGenContinue: Reached maximum number of generations [1000/1000]}\\
|
||||
\texttt{[To] -13068 52 45 24 28 22 19 21 30 17 31 36 46 25 13 12 26 27 51 10 14 37 23 4 15 49}\\
|
||||
\texttt{20 2 8 42 50 11 47 39 38 35 34 44 18 40 9 7 32 3 5 33 16 41 6 1 29 0 48
|
||||
43} \\
|
||||
|
||||
\medskip
|
||||
|
||||
The printed-out results show for the initial best solution and the final one~:
|
||||
\\ \hspace*{1cm}-the length of the route
|
||||
\\ \hspace*{1cm}-the number of cities
|
||||
\\ \hspace*{1cm}-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