Merge branch 'cudacc'
This commit is contained in:
commit
1d7da98de7
3 changed files with 56 additions and 17 deletions
|
|
@ -41,7 +41,11 @@ template < class F > class PO:public EO < F >
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef typename PO < F >::Fitness Fitness;
|
#if defined(__CUDACC__)
|
||||||
|
typedef typename EO < F >::Fitness Fitness;
|
||||||
|
#else
|
||||||
|
typedef typename PO<F>::Fitness Fitness;
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Default constructor.
|
/** Default constructor.
|
||||||
Fitness must have a ctor which takes 0 as a value. Best fitness mush also have the same constructor.
|
Fitness must have a ctor which takes 0 as a value. Best fitness mush also have the same constructor.
|
||||||
|
|
|
||||||
|
|
@ -53,16 +53,20 @@
|
||||||
template<class EOT>
|
template<class EOT>
|
||||||
class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
|
class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
public:
|
using std::vector<EOT>::size;
|
||||||
|
using std::vector<EOT>::resize;
|
||||||
|
using std::vector<EOT>::operator[];
|
||||||
|
using std::vector<EOT>::begin;
|
||||||
|
using std::vector<EOT>::end;
|
||||||
|
|
||||||
using std::vector<EOT>::size;
|
typedef typename EOT::Fitness Fitness;
|
||||||
using std::vector<EOT>::resize;
|
#if defined(__CUDACC__)
|
||||||
using std::vector<EOT>::operator[];
|
typedef typename std::vector<EOT>::iterator iterator;
|
||||||
using std::vector<EOT>::begin;
|
typedef typename std::vector<EOT>::const_iterator const_iterator;
|
||||||
using std::vector<EOT>::end;
|
#endif
|
||||||
|
|
||||||
typedef typename EOT::Fitness Fitness;
|
|
||||||
/** Default ctor. Creates empty pop
|
/** Default ctor. Creates empty pop
|
||||||
*/
|
*/
|
||||||
eoPop() : std::vector<EOT>(), eoObject(), eoPersistent() {};
|
eoPop() : std::vector<EOT>(), eoObject(), eoPersistent() {};
|
||||||
|
|
@ -177,30 +181,49 @@ class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns an iterator to the best individual DOES NOT MOVE ANYBODY */
|
/** returns an iterator to the best individual DOES NOT MOVE ANYBODY */
|
||||||
typename eoPop<EOT>::iterator it_best_element()
|
#if defined(__CUDACC__)
|
||||||
|
eoPop<EOT>::iterator it_best_element()
|
||||||
{
|
{
|
||||||
typename eoPop<EOT>::iterator it = std::max_element(begin(), end());
|
eoPop<EOT>:: iterator it = std::max_element(begin(), end());
|
||||||
|
#else
|
||||||
|
typename eoPop<EOT>::iterator it_best_element() {
|
||||||
|
typename eoPop<EOT>::iterator it = std::max_element(begin(), end());
|
||||||
|
#endif
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns an iterator to the best individual DOES NOT MOVE ANYBODY */
|
/** returns an iterator to the best individual DOES NOT MOVE ANYBODY */
|
||||||
const EOT & best_element() const
|
const EOT & best_element() const
|
||||||
{
|
{
|
||||||
typename eoPop<EOT>::const_iterator it = std::max_element(begin(), end());
|
#if defined(__CUDACC__)
|
||||||
|
eoPop<EOT>::const_iterator it = std::max_element(begin(), end());
|
||||||
|
#else
|
||||||
|
typename eoPop<EOT>::const_iterator it = std::max_element(begin(), end());
|
||||||
|
#endif
|
||||||
return (*it);
|
return (*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns a const reference to the worse individual DOES NOT MOVE ANYBODY */
|
/** returns a const reference to the worse individual DOES NOT MOVE ANYBODY */
|
||||||
const EOT & worse_element() const
|
const EOT & worse_element() const
|
||||||
{
|
{
|
||||||
typename eoPop<EOT>::const_iterator it = std::min_element(begin(), end());
|
#if defined(__CUDACC__)
|
||||||
|
eoPop<EOT>::const_iterator it = std::min_element(begin(), end());
|
||||||
|
#else
|
||||||
|
typename eoPop<EOT>::const_iterator it = std::min_element(begin(), end());
|
||||||
|
#endif
|
||||||
return (*it);
|
return (*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns an iterator to the worse individual DOES NOT MOVE ANYBODY */
|
/** returns an iterator to the worse individual DOES NOT MOVE ANYBODY */
|
||||||
|
#if defined(__CUDACC__)
|
||||||
|
eoPop<EOT>::iterator it_worse_element()
|
||||||
|
{
|
||||||
|
eoPop<EOT>::iterator it = std::min_element(begin(), end());
|
||||||
|
#else
|
||||||
typename eoPop<EOT>::iterator it_worse_element()
|
typename eoPop<EOT>::iterator it_worse_element()
|
||||||
{
|
{
|
||||||
typename eoPop<EOT>::iterator it = std::min_element(begin(), end());
|
typename eoPop<EOT>::iterator it = std::min_element(begin(), end());
|
||||||
|
#endif
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,9 +231,15 @@ class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
|
||||||
slightly faster algorithm than sort to find all individuals that are better
|
slightly faster algorithm than sort to find all individuals that are better
|
||||||
than the nth individual. INDIVIDUALS ARE MOVED AROUND in the pop.
|
than the nth individual. INDIVIDUALS ARE MOVED AROUND in the pop.
|
||||||
*/
|
*/
|
||||||
|
#if defined(__CUDACC__)
|
||||||
|
eoPop<EOT>::iterator nth_element(int nth)
|
||||||
|
{
|
||||||
|
eoPop<EOT>::iterator it = begin() + nth;
|
||||||
|
#else
|
||||||
typename eoPop<EOT>::iterator nth_element(int nth)
|
typename eoPop<EOT>::iterator nth_element(int nth)
|
||||||
{
|
{
|
||||||
typename eoPop<EOT>::iterator it = begin() + nth;
|
typename eoPop<EOT>::iterator it = begin() + nth;
|
||||||
|
#endif
|
||||||
std::nth_element(begin(), it, end(), std::greater<EOT>());
|
std::nth_element(begin(), it, end(), std::greater<EOT>());
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,14 @@ and minimizing fitness compares with greater. This because we want ordinary
|
||||||
fitness values (doubles) to be equivalent with Maximizing Fitness, and
|
fitness values (doubles) to be equivalent with Maximizing Fitness, and
|
||||||
comparing with less is the default behaviour.
|
comparing with less is the default behaviour.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined(__CUDACC__)
|
||||||
|
typedef eoScalarFitness<float, std::less<float> > eoMaximizingFitness;
|
||||||
|
typedef eoScalarFitness<float, std::greater<float> > eoMinimizingFitness;
|
||||||
|
#else
|
||||||
typedef eoScalarFitness<double, std::less<double> > eoMaximizingFitness;
|
typedef eoScalarFitness<double, std::less<double> > eoMaximizingFitness;
|
||||||
typedef eoScalarFitness<double, std::greater<double> > eoMinimizingFitness;
|
typedef eoScalarFitness<double, std::greater<double> > eoMinimizingFitness;
|
||||||
|
#endif
|
||||||
|
|
||||||
template <class F, class Cmp>
|
template <class F, class Cmp>
|
||||||
std::ostream& operator<<(std::ostream& os, const eoScalarFitness<F, Cmp>& f)
|
std::ostream& operator<<(std::ostream& os, const eoScalarFitness<F, Cmp>& f)
|
||||||
|
|
|
||||||
Reference in a new issue