added best position updating + printOn
This commit is contained in:
parent
7d89f5a97c
commit
c864f2deb5
4 changed files with 24 additions and 29 deletions
22
eo/src/PO.h
22
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.
|
||||
|
|
|
|||
|
|
@ -128,7 +128,6 @@ public:
|
|||
return i;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the neighborhood: update the particle's best fitness and the best particle
|
||||
* of the corresponding neighborhood.
|
||||
|
|
@ -139,6 +138,8 @@ public:
|
|||
if (_po.fitness() > _po.best())
|
||||
{
|
||||
_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
|
||||
|
|
|
|||
|
|
@ -89,6 +89,8 @@ public:
|
|||
if (_po.fitness() > _po.best())
|
||||
{
|
||||
_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())
|
||||
|
|
@ -120,6 +122,7 @@ public:
|
|||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
eoSocialNeighborhood<POT> neighborhood; // the only neighborhood
|
||||
bool isSetup;
|
||||
|
|
|
|||
|
|
@ -120,6 +120,16 @@ public:
|
|||
velocities.resize (_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print-on a vector-particle
|
||||
*/
|
||||
virtual void printOn(std::ostream& os) const
|
||||
{
|
||||
PO<FitT>::printOn(os);
|
||||
os << ' ';
|
||||
os << size() << ' ';
|
||||
std::copy(bestPositions.begin(), bestPositions.end(), std::ostream_iterator<AtomType>(os, " "));
|
||||
}
|
||||
|
||||
/* public attributes */
|
||||
std::vector < PositionType > bestPositions;
|
||||
|
|
|
|||
Reference in a new issue