eoEasyPSO.h

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

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