diff --git a/trunk/paradiseo-peo/tutorial/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/CMakeLists.txt new file mode 100644 index 000000000..236970dc6 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/CMakeLists.txt @@ -0,0 +1,16 @@ +# +##################################################################################### +### 1) Definitions (required for tsp target) +###################################################################################### + +SET(TSP_EXAMPLE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/examples/tsp CACHE PATH "TSP example directory") + +###################################################################################### + +###################################################################################### +### 2) Where must cmake go now ? +###################################################################################### + +SUBDIRS(examples Lesson1 Lesson2) + +###################################################################################### \ No newline at end of file diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/Lesson1/CMakeLists.txt new file mode 100644 index 000000000..9a44d71bd --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson1/CMakeLists.txt @@ -0,0 +1,16 @@ + +###################################################################################### +### 0) Need lesson1 directory +###################################################################################### + +SET(TUTORIAL_LESSON1_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + +###################################################################################### + +###################################################################################### +### 1) Where must cmake go now ? +###################################################################################### + +SUBDIRS(src) + +###################################################################################### \ No newline at end of file diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/lesson.param b/trunk/paradiseo-peo/tutorial/Lesson1/lesson.param new file mode 100644 index 000000000..5f7a15258 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson1/lesson.param @@ -0,0 +1,11 @@ +## miscallenous parameters + +--debug=false + +## deployment schema + +--schema=../schema.xml + +## parameters + +--inst=../../examples/tsp/benchs/eil101.tsp \ No newline at end of file diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/schema.xml b/trunk/paradiseo-peo/tutorial/Lesson1/schema.xml new file mode 100644 index 000000000..3edea1488 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson1/schema.xml @@ -0,0 +1,18 @@ + + + + + + + + + 1 + + + + + + + + + diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/src/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/Lesson1/src/CMakeLists.txt new file mode 100644 index 000000000..7c72d1b92 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson1/src/CMakeLists.txt @@ -0,0 +1,75 @@ + +###################################################################################### +### 0) Set the compiler +###################################################################################### + +SET (CMAKE_CXX_COMPILER mpicxx) + +###################################################################################### + + +###################################################################################### +### 1) Include the sources +###################################################################################### + +INCLUDE_DIRECTORIES(${EO_SRC_DIR}) +INCLUDE_DIRECTORIES(${MO_SRC_DIR}) +INCLUDE_DIRECTORIES(${PEO_SRC_DIR}) +INCLUDE_DIRECTORIES(${TSP_EXAMPLE_DIR}/src) + +###################################################################################### + + +###################################################################################### +### 2) Specify where CMake can find the libraries (mandatory: before 3) ) +###################################################################################### + +LINK_DIRECTORIES( ${EO_SRC_DIR} + ${EO_SRC_DIR}/utils + ${PEO_DIR}/build + ${TSP_EXAMPLE_DIR}/build) + +###################################################################################### + + +###################################################################################### +### 3) Define your target(s): just an executable here +###################################################################################### + +# no matter what is the OS, hopefully +ADD_EXECUTABLE(tspExample main.cpp) + +ADD_DEPENDENCIES(tspExample tsp) +ADD_DEPENDENCIES(tspExample peo) +ADD_DEPENDENCIES(tspExample rmc_mpi) + +SET(EXECUTABLE_OUTPUT_PATH ${TUTORIAL_LESSON1_DIR}/build) +###################################################################################### + + +###################################################################################### +### 4) Optionnal: define your target(s)'s version: no effect for windows +###################################################################################### + +SET(LESSON1_VERSION "1.0.beta") +SET_TARGET_PROPERTIES(tspExample PROPERTIES VERSION "${LESSON1_VERSION}") +###################################################################################### + + +###################################################################################### +### 5) Link the librairies +###################################################################################### + +TARGET_LINK_LIBRARIES(tspExample ${XML2_LIBS}) # define in CMakeLists.txt at PEO root dir +TARGET_LINK_LIBRARIES(tspExample tsp) +TARGET_LINK_LIBRARIES(tspExample peo) +TARGET_LINK_LIBRARIES(tspExample rmc_mpi) +TARGET_LINK_LIBRARIES(tspExample eo) +TARGET_LINK_LIBRARIES(tspExample eoutils) + +###################################################################################### + + + + + diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/src/doclsn.h b/trunk/paradiseo-peo/tutorial/Lesson1/src/doclsn.h new file mode 100644 index 000000000..544edc583 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson1/src/doclsn.h @@ -0,0 +1,498 @@ +//! \mainpage Creating a simple ParadisEO-PEO Evolutionary Algorithm +//! +//! \section structure Introduction +//! +//! One of the first steps in designing an evolutionary algorithm using the ParadisEO-PEO framework +//! consists in having a clear overview of the implemented algorithm. A brief pseudo-code description is offered +//! bellow - the entire source code for the ParadisEO-PEO evolutionary algorithm is defined in the peoEA.h +//! header file. The main elements to be considered when building an evolutionary algorithm are the transformation +//! operators, i.e. crossover and mutation, the evaluation function, the continuation criterion and the selection +//! and replacement strategy. +//! +//! +//! +//! +//! +//! +//! +//! +//!
do {    
         select( population, offsprings );   // select the offsprings from the current population
         transform( offsprings );   // crossover and mutation operators are applied on the selected offsprings
         evaluate( offsprings );   // evaluation step of the resulting offsprings
         replace( population, offsprings );   // replace the individuals in the current population whith individuals from the offspring population, according to a specified replacement strategy
} while ( eaCheckpointContinue( population ) );   // checkpoint operators are applied on the current population
+//! +//! The peoEA class offers an elementary evolutionary algorithm implementation. The peoEA class has the underlying structure +//! for including parallel evaluation and parallel transformation operators, migration operators etc. Although there is +//! no restriction on using the algorithms provided by the EO framework, no parallelism is provided - the EO implementation is exclusively sequential. +//!
+//! +//! \section requirements Requirements +//! +//! You should have already installed the ParadisEO-PEO package - this requires several additional packages which should be already +//! included in the provided archive. The installation script has to be launched in order to configure and compile all the required +//! components. At the end of the installation phase you should end up having a directory tree resembling the following: +//! +//!
     ... +//!
     paradiseo-mo +//!
     paradiseo-moeo +//!
     paradiseo-peo +//!
            docs +//!
            examples +//!
                   lesson1 +//!
                   lesson2 +//!
                   ... +//!
                   shared +//!
                   ... +//!
            src +//!
            ... +//!
     ... +//!
+//!
+//! +//! The source-code for this tutorial may be found in the paradiseo-peo/examples/lesson1 directory, in the main.cpp file. +//! We strongly encourage creating a backup copy of the file if you consider modifying the source code. For a complete reference on the +//! TSP-related classes and definitions please refer to the files under the paradiseo-peo/examples/shared. After the installation +//! phase you should end up having an tspExample executable file in the paradiseo-peo/examples/lesson1 directory. +//! We will discuss testing and launching aspects later in the tutorial. +//! +//! You are supposed to be familiar with working in C/C++ (with an extensive use of templates) and you should have at least an introductory +//! background in working with the EO framework. +//! +//!
+//! NOTE: All the presented examples have as case study the Traveling Salesman Problem (TSP). All the presented tutorials rely +//! on a common shared source code defining transformation operators, +//! evaluation functions, etc. for the TSP problem. For a complete understanding of the presented tutorials please take your time for +//! consulting and for studying the additional underlying defined classes. +//!

+//! +//! \section problemDef Problem Definition and Representation +//! +//! As we are not directly concerned with the Traveling Salesman Problem, and to some extent out of scope, no in depth details are offered +//! for the TSP. The problem requires finding the shortest path connecting a given set of cities, while visiting each of +//! the specified cities only once and returning to the startpoint city. The problem is known to be NP-complete, i.e. no polynomial +//! time algorithm exists for solving the problem in exact manner. +//! +//! The construction of a ParadisEO-PEO evolutionary algorithm requires following a few simple steps - please take your time to study the signature +//! of the peoEA constructor: +//! +//! +//! +//! +//!
+//!      peoEA( +//!
            eoContinue< EOT >& __cont, +//!
            peoPopEval< EOT >& __pop_eval, +//!
            eoSelect< EOT >& __select, +//!
            peoTransform< EOT >& __trans, +//!
            eoReplacement< EOT >& __replace +//!
     ); +//!
+//! \image html peoEA.png +//!
+//! +//! A few remarks have to be made: while most of the parameters are passed as EO-specific types, the evaluation and the transformation objects have to be +//! derived from the ParadisEO-PEO peoPopEval and peoTransform classes. Derived classes like the peoParaPopEval and peoParaSGATransform classes allow +//! for parallel evaluation of the population and parallel transformation operators, respectively. Wrappers are provided thus allowing to make use +//! of the EO classes. +//! +//! In the followings, the main required elements for building an evolutionary algorithm are enumerated. For complete details regarding the +//! implementation aspects of each of the components, please refer to the common shared source code. +//! Each of the bellow referred header files may be found in the pardiseo-peo/examples/shared directory. +//! +//!
    +//!
  1. representation - the first decision to be taken concerns the representation of the individuals. You may create your +//! own representation or you may use/derive one of the predefined classes of the EO framework.
    +//! +//! For our case study, the TSP, each city is defined as a Node in the node.h header file - in fact an unsigned value defined +//! as typedef unsigned Node. Moreover, each individual (of the evolutionary algorithm) is represented as a Route object, a vector of Node objects, in +//! the route.h header file - typedef eoVector< int, Node > Route. The definition of the Route object implies two +//! elements: (1) a route is a vector of nodes, and (2) the fitness is an integer value (please refer to the eoVector +//! definition in the EO framework). +//! +//! In addition you should also take a look in the route_init.h header file which includes the RouteInit class, defined for +//! initializing in random manner Route objects. +//!
  2. +//!
  3. evaluation function - having a representation model, an evaluation object has to be defined, implementing a specific +//! fitness function. The designed class has to be derived (directly or indirectly) from the peoPopEval class - you have the choice of +//! using peoSeqPopEval or peoParaPopEval for sequential and parallel evaluation, respectively. These classes act as wrappers requiring +//! the specification of an EO evaluation object derived from the eoEvalFunc class - please refer to their respective documentation.
    +//! +//! The fitness function for our TSP case study is implemented in the route_eval.h header file. The class is derived from the eoEvalFunc +//! EO class, being defined as class RouteEval : public eoEvalFunc< Route >. +//!
  4. +//!
  5. transformation operators - in order to assure the evolution of the initial population, transformation operators have to be defined. +//! Depending on your problem, you may specify quadruple operators (two input individuals, two output resulting individuals), i.e. crossover operators, +//! binary operators (one input individual and one output resulting individual), i.e. mutation operators, or combination of both types. As for the +//! evaluation function, the signature of the peoEA constructor requires specifying a peoTransform derived object as transformation operator. +//! +//! The transform operators, crossover and mutation, for the herein presented example are defined in the order_xover.h and the city_swap.h +//! header files, respectively. +//!
  6. +//!
  7. continuation criterion - the evolutionary algorithm evolves in an iterative manner; a continuation criterion has to be specified. +//! One of the most common and simplest options considers a maximum number of generations. It is your choice whether to use +//! a predefined EO class for specifying the continuation criterion or using a custom defined class. In the later case you have to +//! make sure that your class derives the eoContinue class.
    +//!
  8. +//!
  9. selection strategy - at each iteration a set of individuals are selected for applying the transform operators, in order +//! to obtain the offspring population. As the specified parameter has to be derived from the eoSelect it is your option of whether using +//! the EO provided selection strategies or implementing your own, as long as it inherits the eoSelect class. +//! +//! For our example we chose to use the eoRankingSelect strategy, provided in the EO framework. +//!
  10. +//!
  11. replacement strategy - once the offspring population is obtained, the offsprings have to be integrated back into the initial +//! population, according to a given strategy. For custom defined strategies you have to inherit the eoReplacement EO class. We chose to +//! use an eoPlusReplacement as strategy (please review the EO documentation for details on the different strategies available). +//!
  12. +//!
+//!
+//! +//! \section example A simple example for constructing a peoEA object +//! +//! The source code for this example may be found in the main.cpp file, under the paradiseo-peo/examples/lesson1 directory. Please make sure you +//! At this point you have two options: (a) you can just follow the example without touching the main.cpp or, (b) you can start from scratch, +//! following the presented steps, in which case you are required make a backup copy of the main.cpp file and replace the original file with an +//! empty one. +//! +//!
    +//!
  1. include the necessary header files - as we will be using Route objects, we have to include the files +//! which define the Route type, the initializing functor and the evaluation functions. Furthermore, in order to make use of +//! transform operators, we require having the headers which define the crossover and the mutation operators. +//! All these files may be found in the shared directory that we mentioned in the beginning. At this point you +//! should have something like the following:
    +//! +//!
    +//!		##include "route.h"
    +//!		##include "route_init.h"
    +//!		##include "route_eval.h"
    +//!		
    +//!		##include "order_xover.h"
    +//!		##include "city_swap.h"
    +//!		
    +//! In addition we require having the paradiseo header file, in order to use the ParadisEO-PEO features, and a header specific +//! for our problem, dealing with processing command-line parameters - the param.h header file. The complete picture at this point +//! with all the required header files is as follows:
    +//! +//!
    +//!		##include "route.h"
    +//!		##include "route_init.h"
    +//!		##include "route_eval.h"
    +//!		
    +//!		##include "order_xover.h"
    +//!		##include "city_swap.h"
    +//!
    +//!		##include "param.h"
    +//!
    +//!		##include <paradiseo>
    +//!		
    +//! NOTE: the paradiseo header file is in fact a "super-header" - it includes all the esential ParadisEO-PEO header files. +//! It is at at your choice if you want use the paradiseo header file or to explicitly include different header files, +//! like the peoEA.h header file, for example. +//! +//!
  2. +//!
  3. define problem specific parameters - in our case we have to specify how many individuals we want to have in our population, the number +//! of generations for the evolutionary algorithm to iterate and the probabilities associated with the crossover and mutation operators.
    +//! +//!
    +//!		##include "route.h"
    +//!		##include "route_init.h"
    +//!		##include "route_eval.h"
    +//!		
    +//!		##include "order_xover.h"
    +//!		##include "city_swap.h"
    +//!
    +//!		##include "param.h"
    +//!
    +//!		##include <paradiseo>
    +//!
    +//!
    +//!		##define POP_SIZE 10
    +//!		##define NUM_GEN 100
    +//!		##define CROSS_RATE 1.0
    +//!		##define MUT_RATE 0.01
    +//!		
    +//!
  4. +//!
  5. construct the skeleton of a simple ParadisEO-PEO program - the main function including the code for initializing the ParadisEO-PEO +//! environment, for loading problem data and for shutting down the ParadisEO-PEO environment. From this point on we will make +//! abstraction of the previous part referring only to the main function.
    +//! +//!
    +//!		...
    +//!		
    +//!		int main( int __argc, char** __argv ) {
    +//!		
    +//!			// initializing the ParadisEO-PEO environment
    +//!			peo :: init( __argc, __argv );
    +//!		
    +//!			// processing the command line specified parameters
    +//!			loadParameters( __argc, __argv );
    +//!		
    +//!
    +//!			// EVOLUTIONARY ALGORITHM TO BE DEFINED
    +//!
    +//!		
    +//!			peo :: run( );
    +//!			peo :: finalize( );
    +//!			// shutting down the ParadisEO-PEO environment
    +//!		
    +//!			return 0;
    +//!		}
    +//!		
    +//!
  6. +//!
  7. initialization functors, evaluation function and transform operators - basically we only need to create instances for each of the +//! enumerated objects, to be passed later as parameters for higher-level components of the evolutionary algorithm.
    +//! +//!
    +//!		RouteInit route_init;	// random init object - creates random Route objects
    +//!		RouteEval full_eval;	// evaluator object - offers a fitness value for a specified Route object
    +//!
    +//!		OrderXover crossover;	// crossover operator - creates two offsprings out of two specified parents
    +//!		CitySwap mutation;	// mutation operator - randomly mutates one gene for a specified individual
    +//!		
    +//!
  8. +//!
  9. construct the components of the evolutionary algorithm - each of the components that has to be passed as parameter to the +//! peoEA constructor has to be defined along with the associated parameters. Except for the requirement to provide the +//! appropriate objects (for example, a peoPopEval derived object must be specified for the evaluation functor), there is no strict +//! path to follow. It is your option what elements to mix, depending on your problem - we aimed for simplicity in our example. +//! +//! +//!
    +//!		eoPop< Route > population( POP_SIZE, route_init );	// initial population for the algorithm having POP_SIZE individuals
    +//!		peoSeqPopEval< Route > eaPopEval( full_eval );		// evaluator object - to be applied at each iteration on the entire population
    +//!		
    +//! +//!
    +//!		eoGenContinue< Route > eaCont( NUM_GEN );		// continuation criterion - the algorithm will iterate for NUM_GEN generations
    +//!		eoCheckPoint< Route > eaCheckpointContinue( eaCont );	// checkpoint object - verify at each iteration if the continuation criterion is met
    +//!		
    +//! +//!
    +//!		eoRankingSelect< Route > selectionStrategy;		// selection strategy - applied at each iteration for selecting parent individuals
    +//!		eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE ); // selection object - POP_SIZE individuals are selected at each iteration
    +//!		
    +//! +//!
    +//!		// transform operator - includes the crossover and the mutation operators with a specified associated rate
    +//!		eoSGATransform< Route > transform( crossover, CROSS_RATE, mutation, MUT_RATE );
    +//!		peoSeqTransform< Route > eaTransform( transform );	// ParadisEO transform operator (please remark the peo prefix) - wraps an e EO transform object
    +//!		
    +//! +//!
    +//!		eoPlusReplacement< Route > eaReplace;			// replacement strategy - for replacing the initial population with offspring individuals
    +//!		
    +//!
  10. +//!
  11. evolutionary algorithm - having defined all the previous components, we are ready for instanciating an evolutionary algorithm. +//! In the end we have to associate a population with the algorithm, which will serve as the initial population, to be iteratively evolved. +//! +//!
    +//!		peoEA< Route > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace );
    +//!
    +//!		eaAlg( population );	// specifying the initial population for the algorithm, to be iteratively evolved
    +//!		
    +//!
  12. +//!
+//! +//! If you have not missed any of the enumerated points, your program should be like the following: +//! +//!
+//! ##include "route.h"
+//! ##include "route_init.h"
+//! ##include "route_eval.h"
+//! 
+//! ##include "order_xover.h"
+//! ##include "city_swap.h"
+//! 
+//! ##include "param.h"
+//! 
+//! ##include 
+//! 
+//! 
+//! ##define POP_SIZE 10
+//! ##define NUM_GEN 100
+//! ##define CROSS_RATE 1.0
+//! ##define MUT_RATE 0.01
+//! 
+//! 
+//! int main( int __argc, char** __argv ) {
+//! 
+//! 	// initializing the ParadisEO-PEO environment
+//! 	peo :: init( __argc, __argv );
+//! 
+//! 
+//! 	// processing the command line specified parameters
+//! 	loadParameters( __argc, __argv );
+//! 
+//! 
+//! 	// init, eval operators, EA operators -------------------------------------------------------------------------------------------------------------
+//! 
+//! 	RouteInit route_init;	// random init object - creates random Route objects
+//! 	RouteEval full_eval;	// evaluator object - offers a fitness value for a specified Route object
+//! 
+//! 	OrderXover crossover;	// crossover operator - creates two offsprings out of two specified parents
+//! 	CitySwap mutation;	// mutation operator - randomly mutates one gene for a specified individual
+//! 	// ------------------------------------------------------------------------------------------------------------------------------------------------
+//! 
+//! 
+//! 	// evolutionary algorithm components --------------------------------------------------------------------------------------------------------------
+//! 
+//! 	eoPop< Route > population( POP_SIZE, route_init );	// initial population for the algorithm having POP_SIZE individuals
+//! 	peoSeqPopEval< Route > eaPopEval( full_eval );		// evaluator object - to be applied at each iteration on the entire population
+//! 
+//! 	eoGenContinue< Route > eaCont( NUM_GEN );		// continuation criterion - the algorithm will iterate for NUM_GEN generations
+//! 	eoCheckPoint< Route > eaCheckpointContinue( eaCont );	// checkpoint object - verify at each iteration if the continuation criterion is met
+//! 
+//! 	eoRankingSelect< Route > selectionStrategy;		// selection strategy - applied at each iteration for selecting parent individuals
+//! 	eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE ); // selection object - POP_SIZE individuals are selected at each iteration
+//! 
+//! 	// transform operator - includes the crossover and the mutation operators with a specified associated rate
+//! 	eoSGATransform< Route > transform( crossover, CROSS_RATE, mutation, MUT_RATE );
+//! 	peoSeqTransform< Route > eaTransform( transform );	// ParadisEO transform operator (please remark the peo prefix) - wraps an e EO transform object
+//! 
+//! 	eoPlusReplacement< Route > eaReplace;			// replacement strategy - for replacing the initial population with offspring individuals
+//! 	// ------------------------------------------------------------------------------------------------------------------------------------------------
+//! 
+//! 
+//! 	// ParadisEO-PEO evolutionary algorithm -----------------------------------------------------------------------------------------------------------
+//! 
+//! 	peoEA< Route > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace );
+//! 	
+//! 	eaAlg( population );	// specifying the initial population for the algorithm, to be iteratively evolved
+//! 	// ------------------------------------------------------------------------------------------------------------------------------------------------
+//! 
+//! 
+//! 	peo :: run( );
+//! 	peo :: finalize( );
+//! 	// shutting down the ParadisEO-PEO environment
+//! 
+//! 	return 0;
+//! }
+//! 
+//! +//! +//! \section testing Compilation and Execution +//! +//! First, please make sure that you followed all the previous steps in defining the evolutionary algorithm. Your file should be called main.cpp - please +//! make sure you do not rename the file (we will be using a pre-built makefile, thus you are required not to change the file names). Please make sure you +//! are in the paradiseo-peo/examples/lesson1 directory - you should open a console and you should change your current directory to the one of Lesson1. +//! +//! Compilation: being in the paradiseo-peo/examples/lesson1 directory, you have to type make. As a result the main.cpp file +//! will be compiled and you should obtain an executable file called tspExample. If you have errors, please verify any of the followings: +//! +//! +//! +//! NOTE: in order to successfully compile your program you should already have installed an MPI distribution in your system. +//! +//! Execution: the execution of a ParadisEO-PEO program requires having already created an environment for launching MPI programs. For MPICH-2, +//! for example, this requires starting a ring of daemons. The implementation that we provided as an example is sequential and includes no parallelism - we +//! will see in the end how to include also parallelism. Executing a parallel program requires specifying a mapping of resources, in order to assing different +//! algorithms to different machines, define worker machines etc. This mapping is defined by an XML file called schema.xml, which, for our case, has +//! the following structure: +//! +//!
+//!	
+//!	
+//!	
+//!		
+//!			
+//!			
+//!			
+//!			
+//!			1
+//!			
+//!			
+//!			
+//!			
+//!			
+//!			
+//!		
+//!	
+//! 
+//! +//! Not going into details, the XML file presented above describes a mapping which includes four nodes, the first one having the role of scheduler, +//! the second one being the node on which the evolutionary algorithm is actually executed and the third and the fourth ones being slave nodes. Overall +//! the mapping says that we will be launching four processes, out of which only one will be executing the evolutionary algorithm. The other node entries +//! in the XML file have no real functionality as we have no parallelism in our program - the entries were created for you convenience, in order to provide +//! a smooth transition to creating a parallel program. +//! +//! Launching the program may be different, depending on your MPI distribution - for MPICH-2, in a console, in the paradiseo-peo/examples/lesson1 +//! directory you have to type the following command: +//! +//! mpiexec -n 4 ./tspExample @lesson.param +//! +//! NOTE: the "-n 4" indicates the number of processes to be launched. The last argument, "@lesson.param", indicates a file which specifies different +//! application specific parameters (the mapping file to be used, for example, whether to use logging or not, etc). +//! +//! The result of your execution should be similar to the following: +//!
+//! 	Loading '../data/eil101.tsp'.
+//! 	NAME: eil101.
+//! 	COMMENT: 101-city problem (Christofides/Eilon).
+//! 	TYPE: TSP.
+//! 	DIMENSION: 101.
+//! 	EDGE_WEIGHT_TYPE: EUC_2D.
+//! 	Loading '../data/eil101.tsp'.
+//! 	NAME: eil101.
+//! 	COMMENT: 101-city problem (Christofides/Eilon).
+//! 	EOF.
+//! 	TYPE: TSP.
+//! 	DIMENSION: 101.
+//! 	EDGE_WEIGHT_TYPE: EUC_2D.
+//! 	EOF.
+//! 	Loading '../data/eil101.tsp'.
+//! 	NAME: eil101.
+//! 	COMMENT: 101-city problem (Christofides/Eilon).
+//! 	TYPE: TSP.
+//! 	DIMENSION: 101.
+//! 	EDGE_WEIGHT_TYPE: EUC_2D.
+//! 	EOF.
+//! 	Loading '../data/eil101.tsp'.
+//! 	NAME: eil101.
+//! 	COMMENT: 101-city problem (Christofides/Eilon).
+//! 	TYPE: TSP.
+//! 	DIMENSION: 101.
+//! 	EDGE_WEIGHT_TYPE: EUC_2D.
+//! 	EOF.
+//! 	STOP in eoGenContinue: Reached maximum number of generations [100/100]
+//!	
+//! +//! +//! \section paraIntro Introducing parallelism +//! +//! Creating parallel programs with ParadisEO-PEO represents an easy task once you have the basic structure for your program. For experimentation, +//! in the main.cpp file, replace the line +//!
+//!	peoSeqPopEval< Route > eaPopEval( full_eval );
+//! 
+//! with +//!
+//!	peoParaPopEval< Route > eaPopEval( full_eval );
+//! 
+//! The second line only tells that we would like to evaluate individuals in parallel - this is very interesting if you have a time consuming fitness +//! evaluation function. If you take another look on the schema.xml XML file you will see the last two nodes being marked as slaves (the "num_workers" +//! attribute - these nodes will be used for computing the fitness of the individuals. +//! +//! At this point you only have to recompile your program and to launch it again - as we are not using a time consuming fitness fitness function, the +//! effects might not be visible - you may increase the number of individuals to experiment. diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/src/main.cpp b/trunk/paradiseo-peo/tutorial/Lesson1/src/main.cpp new file mode 100644 index 000000000..0658fa813 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson1/src/main.cpp @@ -0,0 +1,79 @@ +// "main.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "route.h" +#include "route_init.h" +#include "route_eval.h" + +#include "order_xover.h" +#include "city_swap.h" + +#include "param.h" + +#include + + +#define POP_SIZE 10 +#define NUM_GEN 100 +#define CROSS_RATE 1.0 +#define MUT_RATE 0.01 + + +int main( int __argc, char** __argv ) { + + // initializing the ParadisEO-PEO environment + peo :: init( __argc, __argv ); + + + // processing the command line specified parameters + loadParameters( __argc, __argv ); + + + // init, eval operators, EA operators ------------------------------------------------------------------------------------------------------------- + + RouteInit route_init; // random init object - creates random Route objects + RouteEval full_eval; // evaluator object - offers a fitness value for a specified Route object + + OrderXover crossover; // crossover operator - creates two offsprings out of two specified parents + CitySwap mutation; // mutation operator - randomly mutates one gene for a specified individual + // ------------------------------------------------------------------------------------------------------------------------------------------------ + + + // evolutionary algorithm components -------------------------------------------------------------------------------------------------------------- + + eoPop< Route > population( POP_SIZE, route_init ); // initial population for the algorithm having POP_SIZE individuals + peoSeqPopEval< Route > eaPopEval( full_eval ); // evaluator object - to be applied at each iteration on the entire population + + eoGenContinue< Route > eaCont( NUM_GEN ); // continuation criterion - the algorithm will iterate for NUM_GEN generations + eoCheckPoint< Route > eaCheckpointContinue( eaCont ); // checkpoint object - verify at each iteration if the continuation criterion is met + + eoRankingSelect< Route > selectionStrategy; // selection strategy - applied at each iteration for selecting parent individuals + eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE ); // selection object - POP_SIZE individuals are selected at each iteration + + // transform operator - includes the crossover and the mutation operators with a specified associated rate + eoSGATransform< Route > transform( crossover, CROSS_RATE, mutation, MUT_RATE ); + peoSeqTransform< Route > eaTransform( transform ); // ParadisEO transform operator (please remark the peo prefix) - wraps an e EO transform object + + eoPlusReplacement< Route > eaReplace; // replacement strategy - for replacing the initial population with offspring individuals + // ------------------------------------------------------------------------------------------------------------------------------------------------ + + + // ParadisEO-PEO evolutionary algorithm ----------------------------------------------------------------------------------------------------------- + + peoEA< Route > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace ); + + eaAlg( population ); // specifying the initial population for the algorithm, to be iteratively evolved + // ------------------------------------------------------------------------------------------------------------------------------------------------ + + + peo :: run( ); + peo :: finalize( ); + // shutting down the ParadisEO-PEO environment + + return 0; +} diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/src/paradiseo-peo-lsn.doxyfile b/trunk/paradiseo-peo/tutorial/Lesson1/src/paradiseo-peo-lsn.doxyfile new file mode 100644 index 000000000..9f9d15d8f --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson1/src/paradiseo-peo-lsn.doxyfile @@ -0,0 +1,241 @@ +# Doxyfile 1.4.7 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = "ParadisEO-PEO Lesson1" +PROJECT_NUMBER = 0.1 +OUTPUT_DIRECTORY = ../../docs/html/lesson1 +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = YES +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +BUILTIN_STL_SUPPORT = NO +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = NO +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = NO +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = YES +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = . +FILE_PATTERNS = *.cpp \ + *.h \ + NEWS \ + README +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = ../../docs/images +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 3 +IGNORE_PREFIX = peo +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = YES +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = YES +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = ../../../paradiseo-mo/docs/eo.doxytag=../../../../../paradiseo-mo/docs/html \ + ../../../paradiseo-mo/docs/mo.doxytag=../../../../../paradiseo-mo/docs/html \ + ../../docs/paradiseo-peo.doxytag=../../ \ + ../shared/paradiseo-peo-lsn-shared.doxytag=../../lsnshared/html +GENERATE_TAGFILE = ../../docs/paradiseo-peo-lsn.doxytag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = YES diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/Lesson2/CMakeLists.txt new file mode 100644 index 000000000..8081e9458 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson2/CMakeLists.txt @@ -0,0 +1,16 @@ + +###################################################################################### +### 0) Need lesson1 directory +###################################################################################### + +SET(TUTORIAL_LESSON2_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + +###################################################################################### + +###################################################################################### +### 1) Where must cmake go now ? +###################################################################################### + +SUBDIRS(src) + +###################################################################################### \ No newline at end of file diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/lesson.param b/trunk/paradiseo-peo/tutorial/Lesson2/lesson.param new file mode 100644 index 000000000..f8fc07057 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson2/lesson.param @@ -0,0 +1,12 @@ +## miscallenous parameters + +--debug=false + +## deployment schema + +--schema=../schema.xml + +## parameters + +--inst=../../examples/tsp/benchs/eil101.tsp + diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/schema.xml b/trunk/paradiseo-peo/tutorial/Lesson2/schema.xml new file mode 100644 index 000000000..3edea1488 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson2/schema.xml @@ -0,0 +1,18 @@ + + + + + + + + + 1 + + + + + + + + + diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/src/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/Lesson2/src/CMakeLists.txt new file mode 100644 index 000000000..4f6169735 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson2/src/CMakeLists.txt @@ -0,0 +1,75 @@ + +###################################################################################### +### 0) Set the compiler +###################################################################################### + +SET (CMAKE_CXX_COMPILER mpicxx) + +###################################################################################### + + +###################################################################################### +### 1) Include the sources +###################################################################################### + +INCLUDE_DIRECTORIES(${EO_SRC_DIR}) +INCLUDE_DIRECTORIES(${MO_SRC_DIR}) +INCLUDE_DIRECTORIES(${PEO_SRC_DIR}) +INCLUDE_DIRECTORIES(${TSP_EXAMPLE_DIR}/src) + +###################################################################################### + + +###################################################################################### +### 2) Specify where CMake can find the libraries (mandatory: before 3) ) +###################################################################################### + +LINK_DIRECTORIES( ${EO_SRC_DIR} + ${EO_SRC_DIR}/utils + ${PEO_DIR}/build + ${TSP_EXAMPLE_DIR}/build) + +###################################################################################### + + +###################################################################################### +### 3) Define your target(s): just an executable here +###################################################################################### + +# no matter what is the OS, hopefully +ADD_EXECUTABLE(tspExample main.cpp) + +ADD_DEPENDENCIES(tspExample tsp) +ADD_DEPENDENCIES(tspExample peo) +ADD_DEPENDENCIES(tspExample rmc_mpi) + +SET(EXECUTABLE_OUTPUT_PATH ${TUTORIAL_LESSON2_DIR}/build) +###################################################################################### + + +###################################################################################### +### 4) Optionnal: define your target(s)'s version: no effect for windows +###################################################################################### + +SET(LESSON2_VERSION "1.0.beta") +SET_TARGET_PROPERTIES(tspExample PROPERTIES VERSION "${LESSON2_VERSION}") +###################################################################################### + + +###################################################################################### +### 5) Link the librairies +###################################################################################### + +TARGET_LINK_LIBRARIES(tspExample ${XML2_LIBS}) # define in CMakeLists.txt at PEO root dir +TARGET_LINK_LIBRARIES(tspExample tsp) +TARGET_LINK_LIBRARIES(tspExample peo) +TARGET_LINK_LIBRARIES(tspExample rmc_mpi) +TARGET_LINK_LIBRARIES(tspExample eo) +TARGET_LINK_LIBRARIES(tspExample eoutils) + +###################################################################################### + + + + + diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/src/main.cpp b/trunk/paradiseo-peo/tutorial/Lesson2/src/main.cpp new file mode 100644 index 000000000..9b2c43538 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson2/src/main.cpp @@ -0,0 +1,162 @@ +// "main_ga.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "param.h" +#include "route_init.h" +#include "route_eval.h" + +#include "order_xover.h" +#include "edge_xover.h" +#include "partial_mapped_xover.h" +#include "city_swap.h" +#include "part_route_eval.h" +#include "merge_route_eval.h" +#include "two_opt_init.h" +#include "two_opt_next.h" +#include "two_opt_incr_eval.h" + +#include + +#define POP_SIZE 10 +#define NUM_GEN 100 +#define CROSS_RATE 1.0 +#define MUT_RATE 0.01 +#define NUM_PART_EVALS 2 + +#define MIG_FREQ 10 +#define MIG_SIZE 10 +#define HYBRID_SIZE 3 + +int main (int __argc, char * * __argv) { + + peo :: init (__argc, __argv); + + loadParameters (__argc, __argv); /* Processing some parameters relative to the tackled + problem (TSP) */ + + RouteInit route_init; /* Its builds random routes */ + RouteEval full_eval; /* Full route evaluator */ + + MergeRouteEval merge_eval; + + std :: vector *> part_eval; + for (unsigned i = 1 ; i <= NUM_PART_EVALS ; i ++) + part_eval.push_back (new PartRouteEval ((float) (i - 1) / NUM_PART_EVALS, (float) i / NUM_PART_EVALS)); + + OrderXover order_cross; /* Recombination */ + PartialMappedXover pm_cross; + EdgeXover edge_cross; + CitySwap city_swap_mut; /* Mutation */ + + RingTopology topo; + + /** The first EA **/ + + eoPop ox_pop (POP_SIZE, route_init); /* Population */ + + eoGenContinue ox_cont (NUM_GEN); /* A fixed number of iterations */ + eoCheckPoint ox_checkpoint (ox_cont); /* Checkpoint */ + peoParaPopEval ox_pop_eval (part_eval, merge_eval); + eoStochTournamentSelect ox_select_one; + eoSelectNumber ox_select (ox_select_one, POP_SIZE); + eoSGATransform ox_transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE); + peoSeqTransform ox_para_transform (ox_transform); + eoEPReplacement ox_replace (2); + + /* The migration policy */ + eoPeriodicContinue ox_mig_cont (MIG_FREQ); /* Migration occurs periodically */ + eoRandomSelect ox_mig_select_one; /* Emigrants are randomly selected */ + eoSelectNumber ox_mig_select (ox_mig_select_one, MIG_SIZE); + eoPlusReplacement ox_mig_replace; /* Immigrants replace the worse individuals */ + + peoAsyncIslandMig ox_mig (ox_mig_cont, ox_mig_select, ox_mig_replace, topo, ox_pop, ox_pop); + //peoSyncIslandMig ox_mig (MIG_FREQ, ox_mig_select, ox_mig_replace, topo, ox_pop, ox_pop); + + ox_checkpoint.add (ox_mig); + + peoEA ox_ea (ox_checkpoint, ox_pop_eval, ox_select, ox_para_transform, ox_replace); + ox_mig.setOwner (ox_ea); + + ox_ea (ox_pop); /* Application to the given population */ + + /** The second EA **/ + + eoPop pmx_pop (POP_SIZE, route_init); /* Population */ + + eoGenContinue pmx_cont (NUM_GEN); /* A fixed number of iterations */ + eoCheckPoint pmx_checkpoint (pmx_cont); /* Checkpoint */ + peoSeqPopEval pmx_pop_eval (full_eval); + eoRankingSelect pmx_select_one; + eoSelectNumber pmx_select (pmx_select_one, POP_SIZE); + eoSGATransform pmx_transform (pm_cross, CROSS_RATE, city_swap_mut, MUT_RATE); + peoSeqTransform pmx_para_transform (pmx_transform); + eoPlusReplacement pmx_replace; + + /* The migration policy */ + eoPeriodicContinue pmx_mig_cont (MIG_FREQ); /* Migration occurs periodically */ + eoRandomSelect pmx_mig_select_one; /* Emigrants are randomly selected */ + eoSelectNumber pmx_mig_select (pmx_mig_select_one, MIG_SIZE); + eoPlusReplacement pmx_mig_replace; /* Immigrants replace the worse individuals */ + peoAsyncIslandMig pmx_mig (pmx_mig_cont, pmx_mig_select, pmx_mig_replace, topo, pmx_pop, pmx_pop); + //peoSyncIslandMig pmx_mig (MIG_FREQ, pmx_mig_select, pmx_mig_replace, topo, pmx_pop, pmx_pop); + pmx_checkpoint.add (pmx_mig); + + /* Hybridization with a Local Search */ + TwoOptInit pmx_two_opt_init; + TwoOptNext pmx_two_opt_next; + TwoOptIncrEval pmx_two_opt_incr_eval; + moBestImprSelect pmx_two_opt_move_select; + moHC hc (pmx_two_opt_init, pmx_two_opt_next, pmx_two_opt_incr_eval, pmx_two_opt_move_select, full_eval); + + eoPeriodicContinue pmx_ls_cont (MIG_FREQ); /* Hybridization occurs periodically */ + eoRandomSelect pmx_ls_select_one; /* ? */ + eoSelectNumber pmx_ls_select (pmx_ls_select_one, HYBRID_SIZE); + eoPlusReplacement pmx_ls_replace; + + peoSyncMultiStart pmx_ls (pmx_ls_cont, pmx_ls_select, pmx_ls_replace, hc, pmx_pop); + pmx_checkpoint.add (pmx_ls); + + peoEA pmx_ea (pmx_checkpoint, pmx_pop_eval, pmx_select, pmx_para_transform, pmx_replace); + pmx_mig.setOwner (pmx_ea); + pmx_ls.setOwner (pmx_ea); + + pmx_ea (pmx_pop); /* Application to the given population */ + + /** The third EA **/ + + eoPop edge_pop (POP_SIZE, route_init); /* Population */ + + eoGenContinue edge_cont (NUM_GEN); /* A fixed number of iterations */ + eoCheckPoint edge_checkpoint (edge_cont); /* Checkpoint */ + peoSeqPopEval edge_pop_eval (full_eval); + eoRankingSelect edge_select_one; + eoSelectNumber edge_select (edge_select_one, POP_SIZE); + peoParaSGATransform edge_para_transform (edge_cross, CROSS_RATE, city_swap_mut, MUT_RATE); + eoPlusReplacement edge_replace; + + /* The migration policy */ + eoPeriodicContinue edge_mig_cont (MIG_FREQ); /* Migration occurs periodically */ + eoRandomSelect edge_mig_select_one; /* Emigrants are randomly selected */ + eoSelectNumber edge_mig_select (edge_mig_select_one, MIG_SIZE); + eoPlusReplacement edge_mig_replace; /* Immigrants replace the worse individuals */ + peoAsyncIslandMig edge_mig (edge_mig_cont, edge_mig_select, edge_mig_replace, topo, edge_pop, edge_pop); + //peoSyncIslandMig edge_mig (MIG_FREQ, edge_mig_select, edge_mig_replace, topo, edge_pop, edge_pop); + edge_checkpoint.add (edge_mig); + + peoEA edge_ea (edge_checkpoint, edge_pop_eval, edge_select, edge_para_transform, edge_replace); + + edge_mig.setOwner (edge_ea); + + edge_ea (edge_pop); /* Application to the given population */ + + peo :: run (); + + peo :: finalize (); /* Termination */ + + return 0; +} diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/src/paradiseo-peo-lsn.doxyfile b/trunk/paradiseo-peo/tutorial/Lesson2/src/paradiseo-peo-lsn.doxyfile new file mode 100644 index 000000000..2fe39e4c8 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson2/src/paradiseo-peo-lsn.doxyfile @@ -0,0 +1,241 @@ +# Doxyfile 1.4.7 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = "ParadisEO-PEO Lesson2" +PROJECT_NUMBER = 0.1 +OUTPUT_DIRECTORY = ../../docs/html/lesson2 +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = YES +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +BUILTIN_STL_SUPPORT = NO +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = NO +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = NO +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = YES +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = . +FILE_PATTERNS = *.cpp \ + *.h \ + NEWS \ + README +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = ../../docs/images +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 3 +IGNORE_PREFIX = peo +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = YES +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = YES +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = ../../../paradiseo-mo/docs/eo.doxytag=../../../../../paradiseo-mo/docs/html \ + ../../../paradiseo-mo/docs/mo.doxytag=../../../../../paradiseo-mo/docs/html \ + ../../docs/paradiseo-peo.doxytag=../../ \ + ../shared/paradiseo-peo-lsn-shared.doxytag=../../lsnshared/html +GENERATE_TAGFILE = ../../docs/paradiseo-peo-lsn.doxytag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = YES diff --git a/trunk/paradiseo-peo/tutorial/examples/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/examples/CMakeLists.txt new file mode 100644 index 000000000..4e14e7c71 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/CMakeLists.txt @@ -0,0 +1,9 @@ + + +###################################################################################### +### 1) Where must cmake go now ? +###################################################################################### + +SUBDIRS(tsp) + +###################################################################################### \ No newline at end of file diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/examples/tsp/CMakeLists.txt new file mode 100644 index 000000000..24589a249 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/CMakeLists.txt @@ -0,0 +1,9 @@ + + +###################################################################################### +### 1) Where must cmake go now ? +###################################################################################### + +SUBDIRS(src) + +###################################################################################### \ No newline at end of file diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/benchs/eil101.opt.tour b/trunk/paradiseo-peo/tutorial/examples/tsp/benchs/eil101.opt.tour new file mode 100644 index 000000000..1d3fece5a --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/benchs/eil101.opt.tour @@ -0,0 +1,108 @@ +NAME : eil101.opt.tour +COMMENT : Optimum tour for eil101.tsp (Length 629) +TYPE : TOUR +DIMENSION : 101 +TOUR_SECTION +1 +69 +27 +101 +53 +28 +26 +12 +80 +68 +29 +24 +54 +55 +25 +4 +39 +67 +23 +56 +75 +41 +22 +74 +72 +73 +21 +40 +58 +13 +94 +95 +97 +87 +2 +57 +15 +43 +42 +14 +44 +38 +86 +16 +61 +85 +91 +100 +98 +37 +92 +59 +93 +99 +96 +6 +89 +52 +18 +83 +60 +5 +84 +17 +45 +8 +46 +47 +36 +49 +64 +63 +90 +32 +10 +62 +11 +19 +48 +82 +7 +88 +31 +70 +30 +20 +66 +71 +65 +35 +34 +78 +81 +9 +51 +33 +79 +3 +77 +76 +50 +-1 +EOF diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/benchs/eil101.tsp b/trunk/paradiseo-peo/tutorial/examples/tsp/benchs/eil101.tsp new file mode 100644 index 000000000..9672f849e --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/benchs/eil101.tsp @@ -0,0 +1,108 @@ +NAME : eil101 +COMMENT : 101-city problem (Christofides/Eilon) +TYPE : TSP +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 diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/examples/tsp/src/CMakeLists.txt new file mode 100644 index 000000000..bc298199e --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/CMakeLists.txt @@ -0,0 +1,66 @@ + +###################################################################################### +### 1) Include the sources +###################################################################################### + +INCLUDE_DIRECTORIES(${EO_SRC_DIR}) +INCLUDE_DIRECTORIES(${MO_SRC_DIR}) +INCLUDE_DIRECTORIES(${PEO_SRC_DIR}) + +###################################################################################### + + +###################################################################################### +### 2) Define your target(s): just the tsp lib here +###################################################################################### + +SET(TSP_LIB_OUTPUT_PATH ${TSP_EXAMPLE_DIR}/build) +SET(LIBRARY_OUTPUT_PATH ${TSP_LIB_OUTPUT_PATH}) + +SET (TSP_SOURCES data.h + data.cpp + opt_route.h + opt_route.cpp + param.h + param.cpp + node.h + node.cpp + route.h + route.cpp + route_init.h + route_init.cpp + route_eval.h + route_eval.cpp + two_opt.h + two_opt.cpp + two_opt_init.h + two_opt_init.cpp + two_opt_incr_eval.h + two_opt_incr_eval.cpp + two_opt_next.h + two_opt_next.cpp + order_xover.h + order_xover.cpp + partial_mapped_xover.h + partial_mapped_xover.cpp + edge_xover.h + edge_xover.cpp + city_swap.h + city_swap.cpp + part_route_eval.h + part_route_eval.cpp + merge_route_eval.h + merge_route_eval.cpp) + +ADD_LIBRARY(tsp STATIC ${TSP_SOURCES}) +###################################################################################### + + +###################################################################################### +### 3) Optionnal: define your lib's version +###################################################################################### + +SET(TSP_VERSION "1.0.beta") +SET_TARGET_PROPERTIES(tsp PROPERTIES VERSION "${TSP_VERSION}") +###################################################################################### + diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/city_swap.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/city_swap.cpp new file mode 100644 index 000000000..cf5afae8a --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/city_swap.cpp @@ -0,0 +1,21 @@ +// "city_swap.cpp" + +// (c) OPAC Team, LIFL, 2002 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include + +#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 ; +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/city_swap.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/city_swap.h new file mode 100644 index 000000000..cd7a6aaaf --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/city_swap.h @@ -0,0 +1,26 @@ +// "city_swap.h" + +// (c) OPAC Team, LIFL, 2002 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef city_swap_h +#define city_swap_h + +#include + +#include "route.h" + +/** Its swaps two vertices + randomly choosen */ +class CitySwap : public eoMonOp { + +public : + + bool operator () (Route & __route) ; + +} ; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/data.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/data.cpp new file mode 100644 index 000000000..415c30aa1 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/data.cpp @@ -0,0 +1,98 @@ +// "data.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include +#include +#include +#include + +#include + +#include "data.h" +#include "node.h" + +#define MAX_TRASH_LENGTH 1000 +#define MAX_FIELD_LENGTH 1000 +#define MAX_LINE_LENGTH 1000 + +static void getNextField (FILE * __f, char * __buff) { + + char trash [MAX_TRASH_LENGTH]; + + fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */ + fscanf (__f, "%[^:\n]", __buff); /* Reading the field */ + fgetc (__f); +} + +static void getLine (FILE * __f, char * __buff) { + + char trash [MAX_TRASH_LENGTH]; + + fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */ + fscanf (__f, "%[^\n]", __buff); /* Reading the line */ +} + +void loadData (const char * __filename) { + + FILE * f = fopen (__filename, "r"); + + if (f) { + + printf ("Loading '%s'.\n", __filename); + + char field [MAX_FIELD_LENGTH]; + + getNextField (f, field); /* Name */ + assert (strstr (field, "NAME")); + getNextField (f, field); + printf ("NAME: %s.\n", field); + + getNextField (f, field); /* Comment */ + assert (strstr (field, "COMMENT")); + getLine (f, field); + printf ("COMMENT: %s.\n", field); + + getNextField (f, field); /* Type */ + assert (strstr (field, "TYPE")); + getNextField (f, field); + printf ("TYPE: %s.\n", field); + + getNextField (f, field); /* Dimension */ + assert (strstr (field, "DIMENSION")); + getNextField (f, field); + printf ("DIMENSION: %s.\n", field); + numNodes = atoi (field); + + getNextField (f, field); /* Edge weight type */ + assert (strstr (field, "EDGE_WEIGHT_TYPE")); + getNextField (f, field); + printf ("EDGE_WEIGHT_TYPE: %s.\n", field); + + getNextField (f, field); /* Node coord section */ + assert (strstr (field, "NODE_COORD_SECTION")); + loadNodes (f); + + getNextField (f, field); /* End of file */ + assert (strstr (field, "EOF")); + printf ("EOF.\n"); + } + else { + + fprintf (stderr, "Can't open '%s'.\n", __filename); + exit (1); + } +} + +void loadData (eoParser & __parser) { + + /* Getting the path of the instance */ + + eoValueParam param ("", "inst", "Path of the instance") ; + __parser.processParam (param) ; + loadData (param.value ().c_str ()); +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/data.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/data.h new file mode 100644 index 000000000..c00c6edfb --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/data.h @@ -0,0 +1,18 @@ +// "data.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __data_h +#define __data_h + +#include + +extern void loadData (const char * __filename); + +extern void loadData (eoParser & __parser); + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/display.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/display.cpp new file mode 100644 index 000000000..0fbaad4b2 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/display.cpp @@ -0,0 +1,117 @@ +// "display.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include +#include + +#include + +#include "display.h" +#include "node.h" +#include "opt_route.h" + +#define BORDER 20 +#define RATIO 0.5 + +#define screen_width 1024 +#define screen_height 768 + +static const char * filename; + +/* Computed coordinates */ +static unsigned * X_new_coord, * Y_new_coord ; + +/* this variable will contain the handle to the returned graphics context. */ +static GC gc; + +/* this variable will contain the pointer to the Display structure */ +static Display* disp; + +/* this variable will store the ID of the newly created window. */ +static Window win; + +static int screen; + +/* Create a new backing pixmap of the appropriate size */ + + /* Best tour */ + /* + gdk_gc_set_line_attributes (gc, 2, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER) ; + + gdk_gc_set_foreground (gc, & color_green) ; + + for (int i = 0 ; i < (int) numNodes ; i ++) { + + gdk_draw_line (pixmap, gc, + X_new_coord [opt_route [i]], + Y_new_coord [opt_route [i]], + X_new_coord [opt_route [(i + 1) % numNodes]], + Y_new_coord [opt_route [(i + 1) % numNodes]]); + + }*/ + +void openMainWindow (const char * __filename) { + + filename = __filename; + + /* Map */ + int map_width = (int) (X_max - X_min); + int map_height = (int) (Y_max - Y_min); + int map_side = std :: max (map_width, map_height); + + /* Calculate the window's width and height. */ + int win_width = (int) (screen_width * RATIO * map_width / map_side); + int win_height = (int) (screen_height * RATIO * map_height / map_side); + + /* Computing the coordinates */ + X_new_coord = new unsigned [numNodes]; + Y_new_coord = new unsigned [numNodes]; + + for (unsigned i = 0; i < numNodes; i ++) { + X_new_coord [i] = (unsigned) (win_width * (1.0 - (X_coord [i] - X_min) / map_width) + BORDER); + Y_new_coord [i] = (unsigned) (win_height * (1.0 - (Y_coord [i] - Y_min) / map_height) + BORDER); + } + + /* Initialisation */ + XGCValues val ; + + disp = XOpenDisplay (NULL) ; + screen = DefaultScreen (disp) ; + win = XCreateSimpleWindow (disp, RootWindow (disp, screen), 0, 0, win_width + 2 * BORDER, win_height + 2 * BORDER, 2, BlackPixel (disp, screen), WhitePixel (disp, screen)) ; + val.foreground = BlackPixel(disp, screen) ; + val.background = WhitePixel(disp, screen) ; + gc = XCreateGC (disp, win, GCForeground | GCBackground, & val) ; + + XMapWindow (disp, win) ; + XFlush (disp) ; + + while (true) { + XClearWindow (disp, win) ; + + /* Vertices as circles */ + for (unsigned i = 1 ; i < numNodes ; i ++) + XDrawArc (disp, win, gc, X_new_coord [i] - 1, Y_new_coord [i] - 1, 3, 3, 0, 364 * 64) ; + + /* New tour */ + std :: ifstream f (filename); + if (f) { + Route route; + f >> route; + f.close (); + + for (int i = 0; i < (int) numNodes; i ++) + XDrawLine (disp, win, gc, + X_new_coord [route [i]], + Y_new_coord [route [i]], + X_new_coord [route [(i + 1) % numNodes]], + Y_new_coord [route [(i + 1) % numNodes]]); + } + XFlush (disp) ; + sleep (1) ; + } +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/display.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/display.h new file mode 100644 index 000000000..f534943d6 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/display.h @@ -0,0 +1,16 @@ +// "display.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __display_h +#define __display_h + +#include "route.h" + +extern void openMainWindow (const char * __filename); + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/display_best_route.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/display_best_route.cpp new file mode 100644 index 000000000..14b1ba0a3 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/display_best_route.cpp @@ -0,0 +1,22 @@ +// "display_best_route.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "display_best_route.h" +#include "display.h" + +DisplayBestRoute :: DisplayBestRoute (eoPop & __pop + ) : pop (__pop) { + + +} + +void DisplayBestRoute :: operator () () { + + displayRoute (pop.best_element ()); +} + diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/display_best_route.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/display_best_route.h new file mode 100644 index 000000000..5571c35be --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/display_best_route.h @@ -0,0 +1,32 @@ +// "display_best_route.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __display_best_route_h +#define __display_best_route_h + +#include + +#include + +#include "route.h" + +class DisplayBestRoute : public eoUpdater { + +public : + + DisplayBestRoute (eoPop & __pop); + + void operator () (); + +private : + + eoPop & pop; + +}; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/edge_xover.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/edge_xover.cpp new file mode 100644 index 000000000..441262e26 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/edge_xover.cpp @@ -0,0 +1,118 @@ +// "edge_xover.cpp" + +// (c) OPAC Team, LIFL, 2003 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include +#include + +#include + +#include "edge_xover.h" + +void EdgeXover :: build_map (const Route & __par1, const Route & __par2) { + + unsigned len = __par1.size () ; + + /* Initialization */ + _map.clear () ; + _map.resize (len) ; + + for (unsigned 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 __vertex, std :: vector > & __map) { + + std :: set & neigh = __map [__vertex] ; + + for (std :: set :: iterator it = neigh.begin () ; + it != neigh.end () ; + it ++) + __map [* it].erase (__vertex) ; + +} + +void EdgeXover :: add_vertex (unsigned __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 len = __par1.size () ; + + /* Go ! */ + __child.clear () ; + + unsigned cur_vertex = rng.random (len) ; + + add_vertex (cur_vertex, __child) ; + + for (unsigned i = 1 ; i < len ; i ++) { + + unsigned len_min_entry = MAXINT ; + + std :: set & neigh = _map [cur_vertex] ; + + for (std :: set :: iterator it = neigh.begin () ; + it != neigh.end () ; + it ++) { + unsigned l = _map [* it].size () ; + if (len_min_entry > l) + len_min_entry = l ; + } + + std :: vector cand ; /* Candidates */ + + for (std :: set :: iterator it = neigh.begin () ; + it != neigh.end () ; + it ++) { + unsigned l = _map [* it].size () ; + if (len_min_entry == l) + cand.push_back (* it) ; + } + + if (! cand.size ()) { + + /* Oh no ! Implicit mutation */ + for (unsigned 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) ; + + __route1.invalidate () ; + __route2.invalidate () ; + + return true ; +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/edge_xover.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/edge_xover.h new file mode 100644 index 000000000..e8bb1f063 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/edge_xover.h @@ -0,0 +1,43 @@ +// "edge_xover.h" + +// (c) OPAC Team, LIFL, 2003 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef edge_xover_h +#define edge_xover_h + +#include +#include + +#include + +#include "route.h" + +/** Edge Crossover */ +class EdgeXover : public eoQuadOp { + +public : + + bool operator () (Route & __route1, Route & __route2) ; + +private : + + void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */ + + void remove_entry (unsigned __vertex, std :: vector > & __map) ; + /* Updating the map of entries */ + + void build_map (const Route & __par1, const Route & __par2) ; + + void add_vertex (unsigned __vertex, Route & __child) ; + + std :: vector > _map ; /* The handled map */ + + std :: vector visited ; /* Vertices that are already visited */ + +} ; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/merge_route_eval.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/merge_route_eval.cpp new file mode 100644 index 000000000..1c0d66870 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/merge_route_eval.cpp @@ -0,0 +1,17 @@ +// "merge_route_eval.cpp" + +// (c) OPAC Team, LIFL, 2005 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "merge_route_eval.h" + +void MergeRouteEval :: operator () (Route & __route, const int & __part_fit) { + + int len = __route.fitness (); + len += __part_fit; + __route.fitness (len); +} + diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/merge_route_eval.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/merge_route_eval.h new file mode 100644 index 000000000..dd4a9534d --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/merge_route_eval.h @@ -0,0 +1,24 @@ +// "merge_route_eval.h" + +// (c) OPAC Team, LIFL, 2005 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __merge_route_eval_h +#define __merge_route_eval_h + +#include + +#include "route.h" + +class MergeRouteEval : public peoAggEvalFunc { + +public : + + void operator () (Route & __route, const int & __part_fit) ; + +}; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/mix.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/mix.h new file mode 100644 index 000000000..ce5d9bf9e --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/mix.h @@ -0,0 +1,25 @@ + + +/* + file: 'mix.h' + author: S. CAHON + mail: paradiseo-help@lists.gforge.inria.fr + date: dec. 2005 +*/ + +#ifndef __mix_h +#define __mix_h + +#include + +#include + +template void mix (std :: vector & __v) { + + unsigned len = __v.size () ; + + for (unsigned i = 0 ; i < len ; i ++) + std :: swap (__v [i], __v [rng.random (len)]) ; +} + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/node.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/node.cpp new file mode 100644 index 000000000..cf0c0f523 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/node.cpp @@ -0,0 +1,77 @@ +// "node.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include +#include + +#include "node.h" + +unsigned numNodes; /* Number of nodes */ + +//static unsigned * * dist; /* Square matrix of distances */ + +double * X_coord, * Y_coord; + +double X_min = MAXDOUBLE, X_max = MINDOUBLE, Y_min = MAXDOUBLE, Y_max = MINDOUBLE; + +void loadNodes (FILE * __f) { + + /* Coord */ + + X_coord = new double [numNodes]; + + Y_coord = new double [numNodes]; + + unsigned num; + + for (unsigned i = 0; i < numNodes; i ++) { + + fscanf (__f, "%u%lf%lf", & num, X_coord + i, Y_coord + i); + + if (X_coord [i] < X_min) + X_min = X_coord [i]; + if (X_coord [i] > X_max) + X_max = X_coord [i]; + if (Y_coord [i] < Y_min) + Y_min = Y_coord [i]; + if (Y_coord [i] > Y_max) + Y_max = Y_coord [i]; + } + + /* Allocation */ + /* + dist = new unsigned * [numNodes]; + + for (unsigned i = 0; i < numNodes; i ++) + dist [i] = new unsigned [numNodes]; + */ + /* Computation of the distances */ + + /* + for (unsigned i = 0; i < numNodes; i ++) { + + dist [i] [i] = 0; + + for (unsigned j = 0; j < numNodes; j ++) { + + double dx = X_coord [i] - X_coord [j], dy = Y_coord [i] - Y_coord [j]; + + dist [i] [j] = dist [j] [i] = (unsigned) (sqrt (dx * dx + dy * dy) + 0.5) ; + } + }*/ +} + +unsigned distance (Node __from, Node __to) { + + // return dist [__from] [__to]; + + double dx = X_coord [__from] - X_coord [__to], dy = Y_coord [__from] - Y_coord [__to]; + + return (unsigned) (sqrt (dx * dx + dy * dy) + 0.5) ; +} + diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/node.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/node.h new file mode 100644 index 000000000..fe735361a --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/node.h @@ -0,0 +1,26 @@ +// "node.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __node_h +#define __node_h + +#include + +typedef unsigned Node; + +extern double X_min, X_max, Y_min, Y_max; + +extern double * X_coord, * Y_coord; + +extern unsigned numNodes; /* Number of nodes */ + +extern void loadNodes (FILE * __f); + +extern unsigned distance (Node __from, Node __to); + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/opt_route.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/opt_route.cpp new file mode 100644 index 000000000..2ee739358 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/opt_route.cpp @@ -0,0 +1,107 @@ +// "opt_route.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "opt_route.h" + +#define MAX_TRASH_LENGTH 1000 +#define MAX_FIELD_LENGTH 1000 +#define MAX_LINE_LENGTH 1000 + +static void getNextField (FILE * __f, char * __buff) { + + char trash [MAX_TRASH_LENGTH]; + + fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */ + fscanf (__f, "%[^:\n]", __buff); /* Reading the field */ + fgetc (__f); +} + +static void getLine (FILE * __f, char * __buff) { + + char trash [MAX_TRASH_LENGTH]; + + fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */ + fscanf (__f, "%[^\n]", __buff); /* Reading the line */ +} + +static void loadBestRoute (FILE * __f) { + + opt_route.clear (); + + for (unsigned i = 0; i < numNodes; i ++) { + Node node; + fscanf (__f, "%u", & node); + opt_route.push_back (node - 1); + } + int d; /* -1 ! */ + fscanf (__f, "%d", & d); +} + +void loadOptimumRoute (const char * __filename) { + + FILE * f = fopen (__filename, "r"); + + if (f) { + + printf ("Loading '%s'.\n", __filename); + + char field [MAX_FIELD_LENGTH]; + + getNextField (f, field); /* Name */ + assert (strstr (field, "NAME")); + getNextField (f, field); + //printf ("NAME: %s.\n", field); + + getNextField (f, field); /* Comment */ + assert (strstr (field, "COMMENT")); + getLine (f, field); + // printf ("COMMENT: %s.\n", field); + + getNextField (f, field); /* Type */ + assert (strstr (field, "TYPE")); + getNextField (f, field); + //printf ("TYPE: %s.\n", field); + + getNextField (f, field); /* Dimension */ + assert (strstr (field, "DIMENSION")); + getNextField (f, field); + // printf ("DIMENSION: %s.\n", field); + numNodes = atoi (field); + + getNextField (f, field); /* Tour section */ + assert (strstr (field, "TOUR_SECTION")); + loadBestRoute (f); + + getNextField (f, field); /* End of file */ + assert (strstr (field, "EOF")); + //printf ("EOF.\n"); + + printf ("The length of the best route is %u.\n", length (opt_route)); + } + else { + + fprintf (stderr, "Can't open '%s'.\n", __filename); + exit (1); + } +} + +void loadOptimumRoute (eoParser & __parser) { + + /* Getting the path of the instance */ + + eoValueParam param ("", "optimumTour", "Optimum tour") ; + __parser.processParam (param) ; + if (strlen (param.value ().c_str ())) + loadOptimumRoute (param.value ().c_str ()); + else + opt_route.fitness (0); +} + +Route opt_route; /* Optimum route */ + + diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/opt_route.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/opt_route.h new file mode 100644 index 000000000..52df469de --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/opt_route.h @@ -0,0 +1,23 @@ +// "opt_route.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __opt_route_h +#define __opt_route_h + +#include +#include + +#include "route.h" + +extern void loadOptimumRoute (const char * __filename); + +extern void loadOptimumRoute (eoParser & __parser); + +extern Route opt_route; /* Optimum route */ + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/order_xover.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/order_xover.cpp new file mode 100644 index 000000000..5f8b3ba65 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/order_xover.cpp @@ -0,0 +1,64 @@ +// "order_xover.cpp" + +// (c) OPAC Team, LIFL, 2002 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include + +#include + +#include "order_xover.h" + +void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child) { + + unsigned cut2 = 1 + rng.random (numNodes) ; + unsigned cut1 = rng.random (cut2); + unsigned l = 0; + + /* To store vertices that have already been crossed */ + std :: vector v (numNodes, false); + + /* Copy of the left partial route of the first parent */ + for (unsigned i = cut1 ; i < cut2 ; i ++) { + __child [l ++] = __par1 [i] ; + v [__par1 [i]] = true ; + } + + /* Searching the vertex of the second path, that ended the previous first one */ + unsigned from = 0 ; + for (unsigned i = 0; i < numNodes; i ++) + if (__par2 [i] == __child [cut2 - 1]) { + from = i ; + break ; + } + + /* Selecting a direction (Left or Right) */ + char direct = rng.flip () ? 1 : -1 ; + + for (unsigned i = 0; i < numNodes + 1; i ++) { + unsigned bidule = (direct * i + from + numNodes) % numNodes; + if (! v [__par2 [bidule]]) { + __child [l ++] = __par2 [bidule] ; + v [__par2 [bidule]] = true ; + } + } +} + +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) ; + + __route1.invalidate () ; + __route2.invalidate () ; + + return true ; +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/order_xover.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/order_xover.h new file mode 100644 index 000000000..9fc1907d8 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/order_xover.h @@ -0,0 +1,28 @@ +// "order_xover.h" + +// (c) OPAC Team, LIFL, 2003 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef order_xover_h +#define order_xover_h + +#include + +#include "route.h" + +/** Order Crossover */ +class OrderXover : public eoQuadOp { + +public : + + bool operator () (Route & __route1, Route & __route2) ; + +private : + + void cross (const Route & __par1, const Route & __par2, Route & __child) ; +} ; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/paradiseo-peo-lsn-shared.doxyfile b/trunk/paradiseo-peo/tutorial/examples/tsp/src/paradiseo-peo-lsn-shared.doxyfile new file mode 100644 index 000000000..bd1a827a9 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/paradiseo-peo-lsn-shared.doxyfile @@ -0,0 +1,240 @@ +# Doxyfile 1.4.7 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = "ParadisEO-PEO - Lessons" +PROJECT_NUMBER = 0.1 +OUTPUT_DIRECTORY = ../../docs/html/lsnshared +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = YES +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +BUILTIN_STL_SUPPORT = NO +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = NO +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = NO +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = YES +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = . +FILE_PATTERNS = *.cpp \ + *.h \ + NEWS \ + README +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 3 +IGNORE_PREFIX = peo +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = YES +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = YES +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = ../../../paradiseo-mo/docs/eo.doxytag=../../../../paradiseo-mo/docs/html \ + ../../../paradiseo-mo/docs/mo.doxytag=../../../../paradiseo-mo/docs/html \ + ../../docs/paradiseo-peo.doxytag=../../ +GENERATE_TAGFILE = ../../docs/paradiseo-peo-lsn-shared.doxytag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = YES diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/param.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/param.cpp new file mode 100644 index 000000000..ba41c71d3 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/param.cpp @@ -0,0 +1,23 @@ +// "param.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include + +#include "data.h" +#include "opt_route.h" + +void loadParameters (int __argc, char * * __argv) { + + eoParser parser (__argc, __argv); + + loadData (parser); + + loadOptimumRoute (parser); +} + + diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/param.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/param.h new file mode 100644 index 000000000..ee21bf4d8 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/param.h @@ -0,0 +1,14 @@ +// "param.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __param_h +#define __param_h + +extern void loadParameters (int __argc, char * * __argv); + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/part_route_eval.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/part_route_eval.cpp new file mode 100644 index 000000000..e2d362230 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/part_route_eval.cpp @@ -0,0 +1,30 @@ +// "part_route_eval.cpp" + +// (c) OPAC Team, LIFL, 2003 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "part_route_eval.h" +#include "node.h" + +PartRouteEval :: PartRouteEval (float __from, + float __to + ) : from (__from), + to (__to) { + +} + +void PartRouteEval :: operator () (Route & __route) { + + + unsigned len = 0 ; + + for (unsigned i = (unsigned) (__route.size () * from) ; + i < (unsigned) (__route.size () * to) ; + i ++) + len += distance (__route [i], __route [(i + 1) % numNodes]) ; + + __route.fitness (- (int) len) ; +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/part_route_eval.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/part_route_eval.h new file mode 100644 index 000000000..891737760 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/part_route_eval.h @@ -0,0 +1,33 @@ +// "part_route_eval.h" + +// (c) OPAC Team, LIFL, 2005 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __part_route_eval_h +#define __part_route_eval_h + +#include + +#include "route.h" + +/** Route Evaluator */ +class PartRouteEval : public eoEvalFunc { + +public : + + /** Constructor */ + PartRouteEval (float __from, float __to) ; + + void operator () (Route & __route) ; + +private : + + float from, to ; + +} ; + + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/partial_mapped_xover.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/partial_mapped_xover.cpp new file mode 100644 index 000000000..1ad819a2d --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/partial_mapped_xover.cpp @@ -0,0 +1,61 @@ +// "partial_mapped_xover.cpp" + +// (c) OPAC Team, LIFL, 2003 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include + +#include + +#include "partial_mapped_xover.h" +#include "mix.h" + +void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2) { + + unsigned v [__route.size ()] ; // Number of times a cities are visited ... + + for (unsigned i = 0 ; i < __route.size () ; i ++) + v [i] = 0 ; + + for (unsigned i = 0 ; i < __route.size () ; i ++) + v [__route [i]] ++ ; + + std :: vector vert ; + + for (unsigned i = 0 ; i < __route.size () ; i ++) + if (! v [i]) + vert.push_back (i) ; + + mix (vert) ; + + for (unsigned i = 0 ; i < __route.size () ; i ++) + if (i < __cut1 || i >= __cut2) + if (v [__route [i]] > 1) { + __route [i] = vert.back () ; + vert.pop_back () ; + } +} + +bool PartialMappedXover :: operator () (Route & __route1, Route & __route2) { + + unsigned cut1 = rng.random (__route1.size ()), cut2 = rng.random (__route2.size ()) ; + + if (cut2 < cut1) + std :: swap (cut1, cut2) ; + + // Between the cuts + for (unsigned i = cut1 ; i < cut2 ; i ++) + std :: swap (__route1 [i], __route2 [i]) ; + + // Outside the cuts + repair (__route1, cut1, cut2) ; + repair (__route2, cut1, cut2) ; + + __route1.invalidate () ; + __route2.invalidate () ; + + return true ; +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/partial_mapped_xover.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/partial_mapped_xover.h new file mode 100644 index 000000000..0c08531be --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/partial_mapped_xover.h @@ -0,0 +1,28 @@ +// "partial_mapped_xover.h" + +// (c) OPAC Team, LIFL, 2003 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef partial_mapped_xover_h +#define partial_mapped_xover_h + +#include + +#include "route.h" + +/** Partial Mapped Crossover */ +class PartialMappedXover : public eoQuadOp { + +public : + + bool operator () (Route & __route1, Route & __route2) ; + +private : + + void repair (Route & __route, unsigned __cut1, unsigned __cut2) ; +} ; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/route.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route.cpp new file mode 100644 index 000000000..eea64ab51 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route.cpp @@ -0,0 +1,21 @@ +// "route.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "route.h" + +unsigned length (const Route & __route) { + + unsigned len = 0 ; + + for (unsigned i = 0; i < numNodes; i ++) + len += distance (__route [i], __route [(i + 1) % numNodes]) ; + + return len; +} + + diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/route.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route.h new file mode 100644 index 000000000..0ba026675 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route.h @@ -0,0 +1,20 @@ +// "route.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __route_h +#define __route_h + +#include + +#include "node.h" + +typedef eoVector Route; + +unsigned length (const Route & __route); + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_eval.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_eval.cpp new file mode 100644 index 000000000..0fed8d481 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_eval.cpp @@ -0,0 +1,14 @@ +// "route_eval.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "route_eval.h" + +void RouteEval :: operator () (Route & __route) { + + __route.fitness (- (int) length (__route)); +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_eval.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_eval.h new file mode 100644 index 000000000..295f9a39b --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_eval.h @@ -0,0 +1,23 @@ +// "route_eval.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __route_eval_h +#define __route_eval_h + +#include + +#include "route.h" + +class RouteEval : public eoEvalFunc { + +public : + + void operator () (Route & __route) ; +} ; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_init.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_init.cpp new file mode 100644 index 000000000..93733f210 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_init.cpp @@ -0,0 +1,23 @@ +// "route_init.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include + +#include "route_init.h" +#include "node.h" + +void RouteInit :: operator () (Route & __route) { + + __route.clear (); + + for (unsigned i = 0 ; i < numNodes ; i ++) + __route.push_back (i); + + for (unsigned i = 0 ; i < numNodes ; i ++) + std :: swap (__route [i], __route [rng.random (numNodes)]); +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_init.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_init.h new file mode 100644 index 000000000..937b38265 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/route_init.h @@ -0,0 +1,23 @@ +// "route_init.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __route_init_h +#define __route_init_h + +#include + +#include "route.h" + +class RouteInit : public eoInit { + +public : + + void operator () (Route & __route); +} ; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt.cpp new file mode 100644 index 000000000..8852ff910 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt.cpp @@ -0,0 +1,20 @@ +// "two_opt.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "two_opt.h" + +void TwoOpt :: operator () (Route & __route) { + + unsigned i = 0; + + while ((2 * i) < (second - first)) { + + std :: swap (__route [first + i], __route [second - i]); + i ++; + } +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt.h new file mode 100644 index 000000000..0989f5e6e --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt.h @@ -0,0 +1,25 @@ +// "two_opt.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __two_opt_h +#define __two_opt_h + +#include +#include + +#include "route.h" + +class TwoOpt : public moMove , public std :: pair { + +public : + + void operator () (Route & __route); + +} ; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_incr_eval.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_incr_eval.cpp new file mode 100644 index 000000000..b3985f66e --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_incr_eval.cpp @@ -0,0 +1,24 @@ +// "TwoOptIncrEval.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "two_opt_incr_eval.h" +#include "node.h" + +int TwoOptIncrEval :: operator () (const TwoOpt & __move, const Route & __route) { + + /* From */ + Node v1 = __route [__move.first], v1_left = __route [(__move.first - 1 + numNodes) % numNodes]; + + /* To */ + Node v2 = __route [__move.second], v2_right = __route [(__move.second + 1) % numNodes]; + + if (v1 == v2 || v2_right == v1) + return __route.fitness (); + else + return __route.fitness () - distance (v1_left, v2) - distance (v1, v2_right) + distance (v1_left, v1) + distance (v2, v2_right); +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_incr_eval.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_incr_eval.h new file mode 100644 index 000000000..5f88496ed --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_incr_eval.h @@ -0,0 +1,23 @@ +// "TwoOptIncrEval.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __two_opt_incr_eval_h +#define __two_opt_incr_eval_h + +#include +#include "two_opt.h" + +class TwoOptIncrEval : public moMoveIncrEval { + +public : + + int operator () (const TwoOpt & __move, const Route & __route) ; + +} ; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_init.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_init.cpp new file mode 100644 index 000000000..e19abc467 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_init.cpp @@ -0,0 +1,14 @@ +// "two_opt_init.cpp" + +// (c) OPAC Team, LIFL, 2003 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "two_opt_init.h" + +void TwoOptInit :: operator () (TwoOpt & __move, const Route & __route) { + + __move.first = __move.second = 0; +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_init.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_init.h new file mode 100644 index 000000000..9b4dd0bad --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_init.h @@ -0,0 +1,24 @@ +// "two_opt_init.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __two_opt_init_h +#define __two_opt_init_h + +#include + +#include "two_opt.h" + +class TwoOptInit : public moMoveInit { + +public : + + void operator () (TwoOpt & __move, const Route & __route) ; + +} ; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_next.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_next.cpp new file mode 100644 index 000000000..9b7f8be16 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_next.cpp @@ -0,0 +1,27 @@ +// "two_opt_next.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include "two_opt_next.h" +#include "node.h" + +bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route) { + + if (__move.first == numNodes - 1 && __move.second == numNodes - 1) + return false; + + else { + + __move.second ++; + if (__move.second == numNodes) { + + __move.first ++; + __move.second = __move.first; + } + return true ; + } +} diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_next.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_next.h new file mode 100644 index 000000000..cd6605a8d --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_next.h @@ -0,0 +1,24 @@ +// "two_opt_next.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __two_opt_next_h +#define __two_opt_next_h + +#include + +#include "two_opt.h" + +class TwoOptNext : public moNextMove { + +public : + + bool operator () (TwoOpt & __move, const Route & __route); + +}; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_rand.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_rand.cpp new file mode 100644 index 000000000..69d64879b --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_rand.cpp @@ -0,0 +1,21 @@ +// "two_opt_rand.cpp" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#include + +#include "two_opt_rand.h" +#include "node.h" + +void TwoOptRand :: operator () (TwoOpt & __move, const Route & __route) { + + __move.second = rng.random (numNodes); + + __move.first = rng.random (__move.second); +} + + diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_rand.h b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_rand.h new file mode 100644 index 000000000..44f602b53 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/src/two_opt_rand.h @@ -0,0 +1,24 @@ +// "two_opt_rand.h" + +// (c) OPAC Team, LIFL, January 2006 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __two_opt_rand_h +#define __two_opt_rand_h + +#include + +#include "two_opt.h" + +class TwoOptRand : public eoMoveRand { + +public : + + void operator () (TwoOpt & __move, const Route & __route) ; + +} ; + +#endif