Merge branch 'cudacc'

This commit is contained in:
Johann Dreo 2010-10-31 21:50:15 +01:00
commit 1d7da98de7
3 changed files with 56 additions and 17 deletions

View file

@ -41,7 +41,11 @@ template < class F > class PO:public EO < F >
public: public:
#if defined(__CUDACC__)
typedef typename EO < F >::Fitness Fitness;
#else
typedef typename PO<F>::Fitness Fitness; 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.

View file

@ -53,7 +53,6 @@
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>::size;
@ -63,6 +62,11 @@ class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
using std::vector<EOT>::end; using std::vector<EOT>::end;
typedef typename EOT::Fitness Fitness; typedef typename EOT::Fitness Fitness;
#if defined(__CUDACC__)
typedef typename std::vector<EOT>::iterator iterator;
typedef typename std::vector<EOT>::const_iterator const_iterator;
#endif
/** 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()
{ {
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()); 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
{ {
#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()); 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
{ {
#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()); 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;
} }

View file

@ -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)