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 ();}
|
||||||
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.
|
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||||
* @param _os A std::ostream.
|
* @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.\\
|
* Read object.\\
|
||||||
* Calls base class, just in case that one had something to do.
|
* Calls base class, just in case that one had something to do.
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,6 @@ public:
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the neighborhood: update the particle's best fitness and the best particle
|
* Update the neighborhood: update the particle's best fitness and the best particle
|
||||||
* of the corresponding neighborhood.
|
* of the corresponding neighborhood.
|
||||||
|
|
@ -139,6 +138,8 @@ public:
|
||||||
if (_po.fitness() > _po.best())
|
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
|
// update the best in its neighborhood
|
||||||
|
|
@ -149,7 +150,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the best informative of a particle. Could be itself.
|
* Return the best informative of a particle. Could be itself.
|
||||||
* @param _indice - The indice of a particle in the population
|
* @param _indice - The indice of a particle in the population
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,8 @@ public:
|
||||||
if (_po.fitness() > _po.best())
|
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"
|
// update the global best if the given particle is "better"
|
||||||
if (_po.fitness() > neighborhood.best().fitness())
|
if (_po.fitness() > neighborhood.best().fitness())
|
||||||
|
|
@ -120,6 +122,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
eoSocialNeighborhood<POT> neighborhood; // the only neighborhood
|
eoSocialNeighborhood<POT> neighborhood; // the only neighborhood
|
||||||
bool isSetup;
|
bool isSetup;
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,16 @@ public:
|
||||||
velocities.resize (_size);
|
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 */
|
/* public attributes */
|
||||||
std::vector < PositionType > bestPositions;
|
std::vector < PositionType > bestPositions;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue