main.cpp

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "main_ga.cpp"
00004 
00005 // (c) OPAC Team, LIFL, January 2006
00006 
00007 /* This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011    
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016    
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with this library; if not, write to the Free Software
00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020    
00021    Contact: paradiseo-help@lists.gforge.inria.fr
00022 */
00023 
00024 #include "param.h"
00025 #include "route_init.h"
00026 #include "route_eval.h"
00027 
00028 #include "order_xover.h"
00029 #include "city_swap.h"
00030 
00031 #include <paradiseo>
00032 
00033 #define POP_SIZE 10
00034 #define NUM_GEN 100
00035 #define CROSS_RATE 1.0
00036 #define MUT_RATE 0.01
00037 
00038 
00039 int main( int __argc, char** __argv ) {
00040 
00041         // initializing the ParadisEO-PEO environment
00042         peo :: init( __argc, __argv );
00043 
00044 
00045         // processing the command line specified parameters
00046         loadParameters( __argc, __argv );
00047 
00048 
00049         // init, eval operators, EA operators -------------------------------------------------------------------------------------------------------------
00050 
00051         RouteInit route_init;   // random init object - creates random Route objects
00052         RouteEval full_eval;    // evaluator object - offers a fitness value for a specified Route object
00053 
00054         OrderXover crossover;   // crossover operator - creates two offsprings out of two specified parents
00055         CitySwap mutation;      // mutation operator - randomly mutates one gene for a specified individual
00056         // ------------------------------------------------------------------------------------------------------------------------------------------------
00057 
00058 
00059         // evolutionary algorithm components --------------------------------------------------------------------------------------------------------------
00060 
00061         eoPop< Route > population( POP_SIZE, route_init );      // initial population for the algorithm having POP_SIZE individuals
00062         peoSeqPopEval< Route > eaPopEval( full_eval );          // evaluator object - to be applied at each iteration on the entire population
00063 
00064         eoGenContinue< Route > eaCont( NUM_GEN );               // continuation criterion - the algorithm will iterate for NUM_GEN generations
00065         eoCheckPoint< Route > eaCheckpointContinue( eaConts );  // checkpoint object - verify at each iteration if the continuation criterion is met
00066 
00067         eoRankingSelect< Route > selectionStrategy;             // selection strategy - applied at each iteration for selecting parent individuals
00068         eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE ); // selection object - POP_SIZE individuals are selected at each iteration
00069 
00070         // transform operator - includes the crossover and the mutation operators with a specified associated rate
00071         eoSGATransform< Route > transform( crossover, CROSS_RATE, mutation, MUT_RATE );
00072         peoSeqTransform< Route > eaTransform( transform );      // ParadisEO transform operator (please remark the peo prefix) - wraps an e EO transform object
00073 
00074         eoPlusReplacement< Route > eaReplace;                   // replacement strategy - for replacing the initial population with offspring individuals
00075         // ------------------------------------------------------------------------------------------------------------------------------------------------
00076 
00077 
00078         // ParadisEO-PEO evolutionary algorithm -----------------------------------------------------------------------------------------------------------
00079 
00080         peoEA< Route > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace );
00081         
00082         eaAlg( population );    // specifying the initial population for the algorithm, to be iteratively evolved
00083         // ------------------------------------------------------------------------------------------------------------------------------------------------
00084 
00085 
00086         peo :: run( );
00087         peo :: finalize( );
00088         // shutting down the ParadisEO-PEO environment
00089 
00090         return 0;
00091 }

Generated on Sat Dec 30 14:55:34 2006 for ParadisEO-PEO Lesson1 by  doxygen 1.4.7