diff --git a/eo/src/PO.h b/eo/src/PO.h index 9e0d9487..af4cfe2f 100644 --- a/eo/src/PO.h +++ b/eo/src/PO.h @@ -135,32 +135,14 @@ public: bool operator< (const PO & _po2) const { return fitness () < _po2.fitness ();} bool operator> (const PO & _po2) const { return !(fitness () <= _po2.fitness ());} - /** + + /** * Write object. Called printOn since it prints the object _on_ a stream. * @param _os A std::ostream. */ - virtual void printOn(std::ostream& _os) const { + virtual void printOn(std::ostream& _os) const { _os << bestFitness <<' ' ;} - // the latest version of the code. Very similar to the old code - if (invalid()) { - _os << "INVALID "; - } - else - { - _os << repFitness << ' ' ; - } - - if (invalidBest()) { - _os << "INVALID BEST"; - } - else - { - _os << "best: " << bestFitness ; - } - - } - /** * Read object.\\ * Calls base class, just in case that one had something to do. diff --git a/eo/src/eoLinearTopology.h b/eo/src/eoLinearTopology.h index a6417c25..7eb68ec5 100644 --- a/eo/src/eoLinearTopology.h +++ b/eo/src/eoLinearTopology.h @@ -128,17 +128,18 @@ public: return i; } - - /** + /** * Update the neighborhood: update the particle's best fitness and the best particle * of the corresponding neighborhood. */ void updateNeighborhood(POT & _po,unsigned _indice) - { + { // update the best fitness of the particle if (_po.fitness() > _po.best()) { - _po.best(_po.fitness()); + _po.best(_po.fitness()); + for(unsigned i=0;i<_po.size();i++) + _po.bestPositions[i]=_po[i]; } // update the best in its neighborhood @@ -149,7 +150,6 @@ public: } } - /** * Return the best informative of a particle. Could be itself. * @param _indice - The indice of a particle in the population diff --git a/eo/src/eoStarTopology.h b/eo/src/eoStarTopology.h index 58e223f2..55fe81b0 100644 --- a/eo/src/eoStarTopology.h +++ b/eo/src/eoStarTopology.h @@ -77,7 +77,7 @@ public: } } - /* + /* * Update the best fitness of the given particle if it's better. * Also replace the global best by the given particle if it's better. * @param _po - The particle to update @@ -88,7 +88,9 @@ public: // update the best fitness of the particle if (_po.fitness() > _po.best()) { - _po.best(_po.fitness()); + _po.best(_po.fitness()); + for(unsigned i=0;i<_po.size();i++) + _po.bestPositions[i]=_po[i]; } // update the global best if the given particle is "better" if (_po.fitness() > neighborhood.best().fitness()) @@ -106,7 +108,7 @@ public: POT & best (unsigned _indice) {return (neighborhood.best());} - /** + /** * Print the structure of the topology on the standard output. * @param * @return @@ -120,6 +122,7 @@ public: } + protected: eoSocialNeighborhood neighborhood; // the only neighborhood bool isSetup; diff --git a/eo/src/eoVectorParticle.h b/eo/src/eoVectorParticle.h index 2bd0d87a..21be1dac 100644 --- a/eo/src/eoVectorParticle.h +++ b/eo/src/eoVectorParticle.h @@ -120,6 +120,16 @@ public: velocities.resize (_size); } + /** + * Print-on a vector-particle + */ + virtual void printOn(std::ostream& os) const + { + PO::printOn(os); + os << ' '; + os << size() << ' '; + std::copy(bestPositions.begin(), bestPositions.end(), std::ostream_iterator(os, " ")); + } /* public attributes */ std::vector < PositionType > bestPositions;