eoSyncEasyPSO.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoSyncEasyPSO.h
00005 // (c) OPAC 2007
00006 /*
00007     Contact: paradiseo-help@lists.gforge.inria.fr
00008  */
00009 //-----------------------------------------------------------------------------
00010 
00011 #ifndef _EOSYNCEASYPSO_H
00012 #define _EOSYNCEASYPSO_H
00013 
00014 //-----------------------------------------------------------------------------
00015 #include <eoContinue.h>
00016 #include <eoPopEvalFunc.h>
00017 #include <eoPSO.h>
00018 #include <eoVelocity.h>
00019 #include <eoFlight.h>
00020 #include <eoDummyFlight.h>
00021 //-----------------------------------------------------------------------------
00022 
00032 template < class POT > class eoSyncEasyPSO:public eoPSO < POT >
00033 {
00034 public:
00035 
00043     eoSyncEasyPSO (
00044         eoContinue < POT > &_continuator,
00045         eoEvalFunc < POT > &_eval,
00046         eoVelocity < POT > &_velocity,
00047         eoFlight < POT > &_flight):
00048             continuator (_continuator),
00049             eval (_eval),
00050             loopEval(_eval),
00051             popEval(loopEval),
00052             velocity (_velocity),
00053             flight (_flight){}
00054 
00055 
00061     eoSyncEasyPSO (
00062         eoContinue < POT > &_continuator,
00063         eoEvalFunc < POT > &_eval,
00064         eoVelocity < POT > &_velocity):
00065             continuator (_continuator),
00066             eval (_eval),
00067             loopEval(_eval),
00068             popEval(loopEval),
00069             velocity (_velocity),
00070             flight (dummyFlight){}
00071 
00072 
00073 
00075     virtual void operator  () (eoPop < POT > &_pop)
00076     {
00077         try
00078         {
00079             // just to use a loop eval
00080             eoPop<POT> empty_pop;
00081 
00082             do
00083             {
00084                 // perform velocity evaluation
00085                 velocity.apply (_pop);
00086 
00087                 // apply the flight
00088                 flight.apply (_pop);
00089 
00090                 // evaluate the position (with a loop eval, empty_swarm IS USELESS)
00091                 loopEval(empty_pop,_pop);
00092 
00093                 // update the topology (particle and local/global best(s))
00094                 velocity.updateNeighborhood(_pop);
00095 
00096 
00097             }while (continuator (_pop));
00098 
00099         }
00100         catch (std::exception & e)
00101         {
00102             std::string s = e.what ();
00103             s.append (" in eoSyncEasyPSO");
00104             throw std::runtime_error (s);
00105         }
00106 
00107     }
00108 
00109 private:
00110     eoContinue < POT > &continuator;
00111 
00112     eoEvalFunc < POT > &eval;
00113     eoPopLoopEval<POT>        loopEval;
00114     eoPopEvalFunc<POT>&       popEval;
00115 
00116     eoVelocity < POT > &velocity;
00117     eoFlight < POT > &flight;
00118 
00119     // if the flight does not need to be used, use the dummy flight instance
00120     eoDummyFlight<POT> dummyFlight;
00121 };
00122 
00123 
00124 #endif /*_EOSYNCEASYPSO_H*/

Generated on Fri Jun 22 10:17:02 2007 for EO-PSO by  doxygen 1.4.7