Evocosm - A C++ Framework for Evolutionary Computing

Main Index

Created by Scott Robert Ladd at Coyote Gulch Productions.


organism.h
1 //---------------------------------------------------------------------
2 // Algorithmic Conjurings @ http://www.coyotegulch.com
3 // Evocosm -- An Object-Oriented Framework for Evolutionary Algorithms
4 //
5 // organism.h
6 //---------------------------------------------------------------------
7 //
8 // Copyright 1996, 1999, 2002, 2003, 2004, 2005, 2007 Scott Robert Ladd
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the
22 // Free Software Foundation, Inc.
23 // 59 Temple Place - Suite 330
24 // Boston, MA 02111-1307, USA.
25 //
26 //-----------------------------------------------------------------------
27 //
28 // For more information on this software package, please visit
29 // Scott's web site, Coyote Gulch Productions, at:
30 //
31 // http://www.coyotegulch.com
32 //
33 //-----------------------------------------------------------------------
34 
35 #if !defined(LIBEVOCOSM_ORGANISM_H)
36 #define LIBEVOCOSM_ORGANISM_H
37 
38 // Standard C++ Library
39 #include <cstddef>
40 
41 // libevocosm
42 #include "evocommon.h"
43 
44 namespace libevocosm
45 {
46  using std::vector;
47 
49 
59  template <typename Genotype>
60  class organism : protected globals
61  {
62  protected:
64  double m_fitness;
65 
67  Genotype m_genes;
68 
69  public:
71 
75  : m_fitness(0.0),
76  m_genes()
77  {
78  // nada
79  }
80 
82 
86  organism(const Genotype & a_value)
87  : m_fitness(0.0),
88  m_genes(a_value)
89  {
90  // nada
91  }
92 
94 
98  organism(const organism & a_source)
99  : m_fitness(a_source.m_fitness),
100  m_genes(a_source.m_genes)
101  {
102  // nada
103  }
104 
106 
111  organism(const organism & a_parent1, const organism & a_parent2)
112  : m_fitness(a_parent1.m_fitness),
113  m_genes(a_parent1.m_genes,a_parent2.m_genes)
114  {
115  // nada
116  }
117 
119 
126  virtual ~organism()
127  {
128  // nada
129  }
130 
132 
137  organism & operator = (const organism & a_source)
138  {
139  m_fitness = a_source.m_fitness;
140  m_genes = a_source.m_genes;
141  return *this;
142  }
143 
145 
150  virtual bool operator < (const organism & a_right) const
151  {
152  return (m_fitness > a_right.m_fitness);
153  }
154 
156 
161  virtual void reset_all()
162  {
163  m_fitness = 0.0;
164  }
165 
167 
179  double & fitness()
180  {
181  return m_fitness;
182  }
183 
185 
197  double fitness() const
198  {
199  return m_fitness;
200  }
201 
203 
212  Genotype & genes()
213  {
214  return m_genes;
215  }
216 
218 
227  const Genotype & genes() const
228  {
229  return m_genes;
230  }
231  };
232 
233 };
234 
235 #endif
const Genotype & genes() const
Get genes (read-only)
Definition: organism.h:227
Genotype m_genes
Genetic material; could be almost anything.
Definition: organism.h:67
virtual void reset_all()
Comparison operator for algorithms.
Definition: organism.h:161
organism()
Creation constructor.
Definition: organism.h:74
organism(const Genotype &a_value)
Value constructor.
Definition: organism.h:86
double fitness() const
Get fitness (read-only)
Definition: organism.h:197
An evolving organism.
Definition: organism.h:60
double & fitness()
Get fitness (read-write)
Definition: organism.h:179
organism(const organism &a_parent1, const organism &a_parent2)
Crossover constructor.
Definition: organism.h:111
Genotype & genes()
Get genes (read-write)
Definition: organism.h:212
A toolkit and framework for implementing evolutionary algorithms.
Definition: evocommon.h:60
double m_fitness
Fitness value.
Definition: organism.h:64
virtual bool operator<(const organism &a_right) const
Comparison operator for algorithms.
Definition: organism.h:150
organism(const organism &a_source)
Copy constructor.
Definition: organism.h:98
Elements shared by all classes in Evocosm.
Definition: evocommon.h:115
virtual ~organism()
Virtual destructor.
Definition: organism.h:126
organism & operator=(const organism &a_source)
assignment operator
Definition: organism.h:137

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.