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:
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.
Fitness must have a ctor which takes 0 as a value. Best fitness mush also have the same constructor.

View file

@ -53,16 +53,20 @@
template<class EOT>
class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
{
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;
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
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;
typedef typename EOT::Fitness Fitness;
/** Default ctor. Creates empty pop
*/
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 */
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;
}
/** returns an iterator to the best individual DOES NOT MOVE ANYBODY */
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);
}
/** returns a const reference to the worse individual DOES NOT MOVE ANYBODY */
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);
}
/** returns an iterator to the worse individual DOES NOT MOVE ANYBODY */
typename eoPop<EOT>::iterator it_worse_element()
#if defined(__CUDACC__)
eoPop<EOT>::iterator it_worse_element()
{
typename eoPop<EOT>::iterator it = std::min_element(begin(), end());
eoPop<EOT>::iterator it = std::min_element(begin(), end());
#else
typename eoPop<EOT>::iterator it_worse_element()
{
typename eoPop<EOT>::iterator it = std::min_element(begin(), end());
#endif
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
than the nth individual. INDIVIDUALS ARE MOVED AROUND in the pop.
*/
typename eoPop<EOT>::iterator nth_element(int nth)
#if defined(__CUDACC__)
eoPop<EOT>::iterator nth_element(int nth)
{
typename eoPop<EOT>::iterator it = begin() + nth;
eoPop<EOT>::iterator it = begin() + nth;
#else
typename eoPop<EOT>::iterator nth_element(int nth)
{
typename eoPop<EOT>::iterator it = begin() + nth;
#endif
std::nth_element(begin(), it, end(), std::greater<EOT>());
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
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::greater<double> > eoMinimizingFitness;
#endif
template <class F, class Cmp>
std::ostream& operator<<(std::ostream& os, const eoScalarFitness<F, Cmp>& f)