Evocosm - A C++ Framework for Evolutionary Computing

Main Index

Created by Scott Robert Ladd at Coyote Gulch Productions.


landscape.h
1 //---------------------------------------------------------------------
2 // Algorithmic Conjurings @ http://www.coyotegulch.com
3 // Evocosm -- An Object-Oriented Framework for Evolutionary Algorithms
4 //
5 // landscape.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_LANDSCAPE_H)
36 #define LIBEVOCOSM_LANDSCAPE_H
37 
38 // libevocosm
39 #include "organism.h"
40 
41 #include <iostream>
42 #include <iomanip>
43 
44 namespace libevocosm
45 {
47 
60  template <class OrganismType>
61  class landscape : protected globals
62  {
63  public:
65 
69  landscape(listener & a_listener)
70  : m_listener(a_listener)
71  {
72  // nada
73  }
74 
76  landscape(const landscape & a_source)
77  : m_listener(a_source.m_listener)
78  {
79  // nada
80  }
81 
83  landscape & operator = (const landscape & a_source)
84  {
85  m_listener = a_source.m_listener;
86  return *this;
87  }
88 
90 
97  virtual ~landscape()
98  {
99  // nada
100  }
101 
103 
109  virtual double test(OrganismType & a_organism, bool a_verbose = false) const = 0;
110 
112 
117  virtual double test_pop(vector<OrganismType> & a_population) const
118  {
119  double result = 0.0;
120  int n = 0;
121  int stop = (int)a_population.size();
122 
123  #ifdef _OPENMP
124  #pragma omp parallel for schedule(static) reduction(+:result) private(n)
125  #endif
126  for (n = 0; n < stop; ++n)
127  {
128  a_population[n].fitness() = test(a_population[n]);
129  result += a_population[n].fitness();
130  }
131 
132  // algorithm doesn't use this return value, so return nothing.
133  return result / (double)a_population.size();
134  }
135 
136  protected:
139  };
140 };
141 
142 #endif
landscape(const landscape &a_source)
Copy constructor.
Definition: landscape.h:76
virtual ~landscape()
Virtual destructor.
Definition: landscape.h:97
virtual double test(OrganismType &a_organism, bool a_verbose=false) const =0
Performs fitness testing.
landscape & operator=(const landscape &a_source)
Assignment operator.
Definition: landscape.h:83
virtual double test_pop(vector< OrganismType > &a_population) const
Performs fitness testing.
Definition: landscape.h:117
An abstract interface defining a fitness landscape.
Definition: landscape.h:61
An abstract interface defining a listener.
Definition: evocommon.h:156
listener & m_listener
The listener for landscape events.
Definition: landscape.h:138
A toolkit and framework for implementing evolutionary algorithms.
Definition: evocommon.h:60
Elements shared by all classes in Evocosm.
Definition: evocommon.h:115
landscape(listener &a_listener)
Constructor.
Definition: landscape.h:69

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