main.cpp

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "main.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 
00026 #include "route.h"
00027 #include "route_init.h"
00028 #include "route_eval.h"
00029 
00030 #include "order_xover.h"
00031 #include "city_swap.h"
00032 
00033 #include <paradiseo>
00034 
00035 
00036 #define POP_SIZE 10
00037 #define NUM_GEN 100
00038 #define CROSS_RATE 1.0
00039 #define MUT_RATE 0.01
00040 
00041 
00042 int main( int __argc, char** __argv ) {
00043 
00044         // initializing the ParadisEO-PEO environment
00045         peo :: init( __argc, __argv );
00046 
00047 
00048         // processing the command line specified parameters
00049         loadParameters( __argc, __argv );
00050 
00051 
00052         // init, eval operators, EA operators -------------------------------------------------------------------------------------------------------------
00053 
00054         RouteInit route_init;   // random init object - creates random Route objects
00055         RouteEval full_eval;    // evaluator object - offers a fitness value for a specified Route object
00056 
00057         OrderXover crossover;   // crossover operator - creates two offsprings out of two specified parents
00058         CitySwap mutation;      // mutation operator - randomly mutates one gene for a specified individual
00059         // ------------------------------------------------------------------------------------------------------------------------------------------------
00060 
00061 
00062         // evolutionary algorithm components --------------------------------------------------------------------------------------------------------------
00063 
00064         eoPop< Route > population( POP_SIZE, route_init );      // initial population for the algorithm having POP_SIZE individuals
00065         peoSeqPopEval< Route > eaPopEval( full_eval );          // evaluator object - to be applied at each iteration on the entire population
00066 
00067         eoGenContinue< Route > eaCont( NUM_GEN );               // continuation criterion - the algorithm will iterate for NUM_GEN generations
00068         eoCheckPoint< Route > eaCheckpointContinue( eaCont );   // checkpoint object - verify at each iteration if the continuation criterion is met
00069 
00070         eoRankingSelect< Route > selectionStrategy;             // selection strategy - applied at each iteration for selecting parent individuals
00071         eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE ); // selection object - POP_SIZE individuals are selected at each iteration
00072 
00073         // transform operator - includes the crossover and the mutation operators with a specified associated rate
00074         eoSGATransform< Route > transform( crossover, CROSS_RATE, mutation, MUT_RATE );
00075         peoSeqTransform< Route > eaTransform( transform );      // ParadisEO transform operator (please remark the peo prefix) - wraps an e EO transform object
00076 
00077         eoPlusReplacement< Route > eaReplace;                   // replacement strategy - for replacing the initial population with offspring individuals
00078         // ------------------------------------------------------------------------------------------------------------------------------------------------
00079 
00080 
00081         // ParadisEO-PEO evolutionary algorithm -----------------------------------------------------------------------------------------------------------
00082 
00083         peoEA< Route > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace );
00084         
00085         eaAlg( population );    // specifying the initial population for the algorithm, to be iteratively evolved
00086         // ------------------------------------------------------------------------------------------------------------------------------------------------
00087 
00088 
00089         peo :: run( );
00090         peo :: finalize( );
00091         // shutting down the ParadisEO-PEO environment
00092 
00093         return 0;
00094 }

Generated on Sun Jan 7 18:35:29 2007 for ParadisEO-PEO Lesson1 by  doxygen 1.4.7