53 #if !defined(LIBEVOCOSM_EVOCOSM_H)
54 #define LIBEVOCOSM_EVOCOSM_H
57 #pragma warning (disable : 4786)
70 #include "validator.h"
73 #include "landscape.h"
75 #include "reproducer.h"
101 template <
class OrganismType>
152 evocosm(vector<OrganismType> & a_population,
226 m_sleep_time = a_sleep_time;
238 if (m_sleep_time > 0)
240 #if defined(_MSC_VER)
243 usleep((useconds_t)m_sleep_time);
251 template <
class OrganismType>
260 : m_population(a_population),
261 m_landscape(a_landscape),
262 m_mutator(a_mutator),
263 m_reproducer(a_reproducer),
265 m_selector(a_selector),
266 m_analyzer(a_analyzer),
267 m_listener(a_listener),
275 template <
class OrganismType>
277 : m_population(a_source.a_population),
278 m_landscape(a_source.m_landscape),
279 m_mutator(a_source.m_mutator),
280 m_reproducer(a_source.m_reproducer),
281 m_scaler(a_source.m_scaler),
282 m_selector(a_source.m_selector),
283 m_analyzer(a_source.m_analyzer),
284 m_listener(a_source.m_listener),
285 m_iteration(a_source.m_iteration),
286 m_sleep_time(a_source.m_sleep_time)
292 template <
class OrganismType>
299 template <
class OrganismType>
314 template <
class OrganismType>
317 bool keep_going =
true;
319 OrganismType * best = NULL;
324 m_listener.ping_generation_begin(m_population, m_iteration);
327 m_landscape.test(m_population);
331 m_listener.ping_generation_end(m_population, m_iteration);
335 keep_going = m_analyzer.analyze(m_population, m_iteration);
340 m_scaler.scale_fitness(m_population);
344 vector<OrganismType> survivors = m_selector.select_survivors(m_population);
348 vector<OrganismType> children = m_reproducer.breed(m_population, m_population.size() - survivors.size());
356 m_mutator.mutate(children);
360 survivors.insert(survivors.end(),children.begin(),children.end());
361 m_population = survivors;
366 m_listener.run_complete(m_population);
listener< OrganismType > & m_listener
A listener for evocosm progress.
Definition: evocosm.h:127
void set_sleep_time(unsigned int a_sleep_time)
Set the sleep time property value.
Definition: evocosm.h:224
mutator< OrganismType > & m_mutator
A mutator to randomly influence genes.
Definition: evocosm.h:112
Mutates organisms.
Definition: mutator.h:72
scaler< OrganismType > & m_scaler
Scales the fitness of the evocosm.
Definition: evocosm.h:118
vector< OrganismType > & get_population()
Directly view population.
Definition: evocosm.h:204
An abstract interface defining a fitness landscape.
Definition: landscape.h:80
selector< OrganismType > & m_selector
Selects organisms that survive from one generation to the next.
Definition: evocosm.h:121
A toolkit and framework for implementing evolutionary algorithms.
Definition: analyzer.h:60
void yield()
Yield.
Definition: evocosm.h:236
Elements shared by all classes in Evocosm.
Definition: evocommon.h:117
Selects organisms that survive.
Definition: selector.h:79
An abstract interface defining a listener.
Definition: listener.h:80
virtual ~evocosm()
Virtual destructor.
Definition: evocosm.h:293
unsigned int m_sleep_time
Number microseconds for process to sleep on yield.
Definition: evocosm.h:133
evocosm & operator=(const evocosm< OrganismType > &a_source)
Assignment operator.
Definition: evocosm.h:300
reproducer< OrganismType > & m_reproducer
Creates new organisms.
Definition: evocosm.h:115
landscape< OrganismType > & m_landscape
Fitness landscapes common to all populations.
Definition: evocosm.h:109
Fitness scaling for a population.
Definition: scaler.h:72
Creates new organisms from an existing population.
Definition: reproducer.h:72
analyzer< OrganismType > & m_analyzer
Reports the a evocosm for analysis or display.
Definition: evocosm.h:124
unsigned int get_sleep_time()
Get the sleep time property value.
Definition: evocosm.h:214
size_t m_iteration
Count of iterations made.
Definition: evocosm.h:130
Associates organisms with the components of an evolutionary system.
Definition: evocosm.h:102
Reports on a given population.
Definition: analyzer.h:70
virtual bool run_generation()
Compute next generation.
Definition: evocosm.h:315
evocosm(vector< OrganismType > &a_population, landscape< OrganismType > &a_landscape, mutator< OrganismType > &a_mutator, reproducer< OrganismType > &a_reproducer, scaler< OrganismType > &a_scaler, selector< OrganismType > &a_selector, analyzer< OrganismType > &a_analyzer, listener< OrganismType > &a_listener)
Creation constructor.
Definition: evocosm.h:252
vector< OrganismType > & m_population
The populations of organisms.
Definition: evocosm.h:106