eoStarTopology.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoStarTopology.h
00005 // (c) OPAC 2007
00006 /*
00007     This library...
00008 
00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
00010  */
00011 //-----------------------------------------------------------------------------
00012 
00013 #ifndef EOSTARTOPOLOGY_H_
00014 #define EOSTARTOPOLOGY_H_
00015 
00016 //-----------------------------------------------------------------------------
00017 #include <eoTopology.h>
00018 #include <eoSocialNeighborhood.h>
00019 //-----------------------------------------------------------------------------
00020 
00021 
00027 template < class POT > class eoStarTopology:public eoTopology <POT>
00028 {
00029 
00030 public:
00031 
00035     eoStarTopology ():isSetup(false){}
00036 
00037 
00044     void setup(const eoPop<POT> & _pop)
00045     {
00046         if (!isSetup){
00047 
00048             // put all the particles in the only neighborhood
00049             for (unsigned i=0;i < _pop.size();i++)
00050                 neighborhood.put(i);
00051 
00052             // set the initial global best as the best initial particle
00053             neighborhood.best(_pop.best_element());
00054 
00055             isSetup=true;
00056         }
00057         else
00058         {
00059             // Should activate this part ?
00060             /*
00061                std::string s;
00062                s.append (" Linear topology already setup in eoStarTopology");
00063                throw std::runtime_error (s);
00064                */
00065         }
00066     }
00067 
00068     /*
00069      * Update the best fitness of the given particle if it's better.
00070      * Also replace the global best by the given particle if it's better.
00071      * @param _po - The particle to update
00072      * @param _indice - The indice of the given particle in the population
00073      */
00074     void updateNeighborhood(POT & _po,unsigned _indice)
00075     {
00076         // update the best fitness of the particle
00077         if (_po.fitness() > _po.best())
00078         {
00079             _po.best(_po.fitness());
00080         }
00081         // update the global best if the given particle is "better"
00082         if (_po.fitness() > neighborhood.best().fitness())
00083         {
00084             neighborhood.best(_po);
00085         }
00086     }
00087 
00088 
00094     POT & best (unsigned  _indice) {return (neighborhood.best());}
00095 
00096 
00102     void printOn()
00103     {
00104         std::cout << "{" ;
00105         for (unsigned i=0;i< neighborhood.size();i++)
00106             std::cout << neighborhood.get(i) << " ";
00107         std::cout << "}" << std::endl;
00108     }
00109 
00110 
00111 protected:
00112     eoSocialNeighborhood<POT> neighborhood; // the only neighborhood
00113     bool isSetup;
00114 };
00115 
00116 #endif /*EOSTARTOPOLOGY_H_ */
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 

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