35 #if !defined(LIBEVOCOSM_MIGRATOR_H)
36 #define LIBEVOCOSM_MIGRATOR_H
52 template <
class OrganismType>
80 virtual void migrate(vector< vector<OrganismType> > & a_populations) = 0;
89 template <
class OrganismType>
98 virtual void migrate(vector< vector<OrganismType> > & a_populations)
110 template <
class OrganismType>
119 : m_how_many(a_how_many)
129 virtual void migrate(vector< vector<OrganismType> > & a_populations)
136 size_t pop_count = a_populations.size();
139 size_t * move_count =
new size_t [pop_count];
141 for (
size_t n = 0; n < pop_count; ++n)
145 for (
size_t p = 0; p < pop_count; ++p)
148 if (move_count[p] < m_how_many)
150 size_t pop_size = a_populations[p].size();
151 size_t number_to_move = m_how_many - move_count[p];
153 for (
size_t n = 0; n < number_to_move; ++n);
165 while (move_count[trader] >= m_how_many)
169 if (trader == pop_count)
179 OrganismType temp = a_populations[p][org1];
180 a_populations[p][org1] = a_populations[trader][org2];
181 a_populations[trader][org2] = temp;
185 ++move_count[trader];
191 delete [] move_count;
virtual void migrate(vector< vector< OrganismType > > &a_populations)=0
Removes organisms from a population for later immigration.
virtual ~migrator()
Virtual destructor.
Definition: migrator.h:64
static size_t rand_index(size_t n)
Static function to allow use of g_random function pointer in random_shuffle.
Definition: evocommon.h:119
A do-nothing migrator.
Definition: migrator.h:90
Defines migration between populations.
Definition: migrator.h:53
random_pool_migrator(size_t a_how_many)
Constructor.
Definition: migrator.h:118
A toolkit and framework for implementing evolutionary algorithms.
Definition: evocommon.h:60
A pool-based migrator.
Definition: migrator.h:111
Elements shared by all classes in Evocosm.
Definition: evocommon.h:115
virtual void migrate(vector< vector< OrganismType > > &a_populations)
Do-nothing emigration.
Definition: migrator.h:98
virtual void migrate(vector< vector< OrganismType > > &a_populations)
Emigrate organisms to pool.
Definition: migrator.h:129