Addition of a method sort for PSO
This commit is contained in:
parent
ef8bc7b03f
commit
2273573e04
4 changed files with 22 additions and 93 deletions
|
|
@ -6,5 +6,6 @@ Gustavo Romero Lopez
|
||||||
Maarten Keijzer
|
Maarten Keijzer
|
||||||
Marc Schoenauer
|
Marc Schoenauer
|
||||||
Jeroen Eggermont
|
Jeroen Eggermont
|
||||||
Jochen Küpper
|
Jochen Kpper
|
||||||
Thomas Legrand
|
Thomas Legrand
|
||||||
|
Clive Canape
|
||||||
|
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// continuator.h
|
|
||||||
// (c) GeNeura Team, 1998
|
|
||||||
/*
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
|
||||||
*/
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef _CONTINUATOR_H
|
|
||||||
#define _CONTINUATOR_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <eoFunctor.h>
|
|
||||||
#include <data.h>
|
|
||||||
|
|
||||||
#include <eoContinue.h>
|
|
||||||
#include <eoSelectOne.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Continue interface
|
|
||||||
*/
|
|
||||||
class continuator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual bool check()=0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template < class EOT> class eoContinuator : public continuator{
|
|
||||||
public:
|
|
||||||
|
|
||||||
eoContinuator(eoContinue<EOT> & _cont, const eoPop<EOT> & _pop): cont (_cont), pop(_pop){}
|
|
||||||
|
|
||||||
virtual bool check(){
|
|
||||||
return cont(pop);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
eoContinue<EOT> & cont ;
|
|
||||||
const eoPop<EOT> & pop;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template < class TYPE> class selector
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual const TYPE & select()=0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template < class EOT> class eoSelector : public selector<EOT>{
|
|
||||||
public:
|
|
||||||
|
|
||||||
eoSelector(eoSelectOne<EOT> & _select, const eoPop<EOT> & _pop): selector (_select), pop(_pop){}
|
|
||||||
|
|
||||||
virtual const EOT & select(){
|
|
||||||
return select(pop);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
eoSelectOne<EOT> & selector ;
|
|
||||||
const eoPop<EOT> & pop;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -125,6 +125,16 @@ class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
|
||||||
bool operator()(const EOT* a, const EOT* b) const
|
bool operator()(const EOT* a, const EOT* b) const
|
||||||
{ return b->operator<(*a); }
|
{ return b->operator<(*a); }
|
||||||
};
|
};
|
||||||
|
/// helper struct for comparing (EA or PSO)
|
||||||
|
struct Cmp2
|
||||||
|
{
|
||||||
|
bool operator()(const EOT & a,const EOT & b) const
|
||||||
|
{
|
||||||
|
return b.operator<(a);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
sort the population. Use this member to sort in order
|
sort the population. Use this member to sort in order
|
||||||
|
|
@ -132,7 +142,7 @@ class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
|
||||||
*/
|
*/
|
||||||
void sort(void)
|
void sort(void)
|
||||||
{
|
{
|
||||||
std::sort(begin(), end(), std::greater<EOT>());
|
std::sort(begin(), end(), Cmp2());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** creates a std::vector<EOT*> pointing to the individuals in descending order */
|
/** creates a std::vector<EOT*> pointing to the individuals in descending order */
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,15 @@ public:
|
||||||
{
|
{
|
||||||
velocities.resize (_size);
|
velocities.resize (_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// to avoid conflicts between EA and PSO
|
||||||
|
bool operator<(const eoVectorParticle<FitT, PositionType, VelocityType >& _eo) const
|
||||||
|
{
|
||||||
|
if (_eo.best() > this->best())
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print-on a vector-particle
|
* Print-on a vector-particle
|
||||||
|
|
|
||||||
Reference in a new issue