26 #include <boost/numeric/conversion/cast.hpp>
30 #include "../population.h"
32 #include "base_r_policy.h"
33 #include "worst_r_policy.h"
35 namespace pagmo {
namespace migration {
52 template <
class Container>
53 struct indirect_individual_sorter
55 indirect_individual_sorter(
const Container &container,
const population &pop):
56 m_container(container),m_pop(pop) {}
58 bool operator()(
const Idx &idx1,
const Idx &idx2)
const
60 typedef typename Container::const_iterator::difference_type diff_type;
61 return m_pop.n_dominated(*(m_container.begin() + boost::numeric_cast<diff_type>(idx1))) >
62 m_pop.n_dominated(*(m_container.begin() + boost::numeric_cast<diff_type>(idx2)));
65 const Container &m_container;
66 const population &m_pop;
70 std::vector<std::pair<population::size_type,std::vector<population::individual_type>::size_type> >
75 std::vector<population::size_type> immigrants_idx(boost::numeric_cast<std::vector<population::size_type>::size_type>(immigrants.size()));
76 std::vector<population::size_type> dest_idx(boost::numeric_cast<std::vector<population::size_type>::size_type>(dest.size()));
82 std::sort(immigrants_idx.begin(),immigrants_idx.end(),indirect_individual_sorter<std::vector<population::individual_type> >(immigrants,dest));
84 std::sort(dest_idx.begin(),dest_idx.end(),indirect_individual_sorter<population>(dest,dest));
85 std::reverse(dest_idx.begin(),dest_idx.end());
87 std::vector<std::pair<population::size_type,std::vector<population::individual_type>::size_type> > result;
90 result.push_back(std::make_pair(dest_idx[i],immigrants_idx[i]));
Base class for migration replacement policies.
boost::shared_ptr< base_r_policy > base_r_policy_ptr
Shared pointer to base replacement policy.
std::vector< std::pair< population::size_type, std::vector< population::individual_type >::size_type > > select(const std::vector< population::individual_type > &, const population &) const
Assign pairs of individuals for replacement during migration.
worst_r_policy(const double &rate=1, rate_type type=absolute)
Constructor from rate and rate type.
Worst replacement policy.
population::size_type get_n_individuals(const population &) const
Get number of individuals to migrate from/to input population.
static void iota(ForwardIterator first, ForwardIterator last, T value)
Iota function, usefull to fill iterator range with increasing values.
container_type::size_type size_type
Population size type.
base_r_policy_ptr clone() const
Clone method.
rate_type
Type of migration rate.