Evocosm - A C++ Framework for Evolutionary Computing

Main Index

Created by Scott Robert Ladd at Coyote Gulch Productions.


listener.h
1 /*
2  Evocosm is a C++ framework for implementing evolutionary algorithms.
3 
4  Copyright 2011 Scott Robert Ladd. All rights reserved.
5 
6  Evocosm is user-supported open source software. Its continued development is dependent
7  on financial support from the community. You can provide funding by visiting the Evocosm
8  website at:
9 
10  http://www.coyotegulch.com
11 
12  You may license Evocosm in one of two fashions:
13 
14  1) Simplified BSD License (FreeBSD License)
15 
16  Redistribution and use in source and binary forms, with or without modification, are
17  permitted provided that the following conditions are met:
18 
19  1. Redistributions of source code must retain the above copyright notice, this list of
20  conditions and the following disclaimer.
21 
22  2. Redistributions in binary form must reproduce the above copyright notice, this list
23  of conditions and the following disclaimer in the documentation and/or other materials
24  provided with the distribution.
25 
26  THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED
27  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
28  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR
29  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
32  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 
36  The views and conclusions contained in the software and documentation are those of the
37  authors and should not be interpreted as representing official policies, either expressed
38  or implied, of Scott Robert Ladd.
39 
40  2) Closed-Source Proprietary License
41 
42  If your project is a closed-source or proprietary project, the Simplified BSD License may
43  not be appropriate or desirable. In such cases, contact the Evocosm copyright holder to
44  arrange your purchase of an appropriate license.
45 
46  The author can be contacted at:
47 
48  scott.ladd@coyotegulch.com
49  scott.ladd@gmail.com
50  http:www.coyotegulch.com
51 */
52 
53 #if !defined(LIBEVOCOSM_LISTENER_H)
54 #define LIBEVOCOSM_LISTENER_H
55 
56 // Standard C++ Library
57 #include <string>
58 #include <iostream>
59 #include <iomanip>
60 #include <vector>
61 
62 // Windows
63 #if defined(_MSC_VER)
64 #include "windows.h"
65 #undef max
66 #undef min
67 #endif
68 
69 namespace libevocosm
70 {
71  template<typename T> class population;
72 
74 
79  template <typename OrganismType>
80  class listener
81  {
82  public:
84 
89  virtual void ping_generation_begin(const std::vector<OrganismType> & a_population, size_t a_iteration) = 0;
90 
92 
97  virtual void ping_generation_end(const std::vector<OrganismType> & a_population, size_t a_iteration) = 0;
98 
100 
104  virtual void ping_fitness_test_begin(const OrganismType & a_organism_number) = 0;
105 
107 
111  virtual void ping_fitness_test_end(const OrganismType & a_organism_number) = 0;
112 
114 
122  virtual void report(const std::string & a_text) = 0;
123 
125 
132  virtual void report_error(const std::string & a_text) = 0;
133 
135 
139  virtual void run_complete(const std::vector<OrganismType> & a_population) = 0;
140  };
141 
143 
146  template <typename OrganismType>
147  class null_listener : public listener<OrganismType>
148  {
149  public:
151 
156  virtual void ping_generation_begin(const std::vector<OrganismType> & a_population, size_t a_iteration)
157  {
158  // do nothing
159  }
160 
162 
167  virtual void ping_generation_end(const std::vector<OrganismType> & a_population, size_t a_iteration)
168  {
169  // do nothing
170  }
171 
173 
177  virtual void ping_fitness_test_begin(const OrganismType & a_organism_number)
178  {
179  // do nothing
180  }
181 
183 
187  virtual void ping_fitness_test_end(const OrganismType & a_organism_number)
188  {
189  // do nothing
190  }
191 
193 
201  virtual void report(const std::string & a_text)
202  {
203  // do nothing
204  }
205 
207 
214  virtual void report_error(const std::string & a_text)
215  {
216  // do nothing
217  }
218 
220 
224  virtual void run_complete(const std::vector<OrganismType> & a_population)
225  {
226  // do nothing
227  }
228  };
229 
230 }
231 
232 #endif
An listener implementation that ignores all events.
Definition: listener.h:147
virtual void report_error(const std::string &a_text)=0
Send error message.
virtual void ping_generation_begin(const std::vector< OrganismType > &a_population, size_t a_iteration)
Ping that a generation begins.
Definition: listener.h:156
virtual void ping_generation_end(const std::vector< OrganismType > &a_population, size_t a_iteration)
Ping that a generation ends.
Definition: listener.h:167
virtual void run_complete(const std::vector< OrganismType > &a_population)
Evocosm is finished.
Definition: listener.h:224
virtual void ping_fitness_test_end(const OrganismType &a_organism_number)
Ping that a test run ends.
Definition: listener.h:187
virtual void report(const std::string &a_text)=0
Report non-specific text.
virtual void ping_fitness_test_begin(const OrganismType &a_organism_number)=0
Ping that a test run begins.
virtual void ping_fitness_test_begin(const OrganismType &a_organism_number)
Ping that a test run begins.
Definition: listener.h:177
A toolkit and framework for implementing evolutionary algorithms.
Definition: analyzer.h:60
virtual void ping_fitness_test_end(const OrganismType &a_organism_number)=0
Ping that a test run ends.
virtual void ping_generation_end(const std::vector< OrganismType > &a_population, size_t a_iteration)=0
Ping that a generation ends.
virtual void ping_generation_begin(const std::vector< OrganismType > &a_population, size_t a_iteration)=0
Ping that a generation begins.
An abstract interface defining a listener.
Definition: listener.h:80
virtual void run_complete(const std::vector< OrganismType > &a_population)=0
Evocosm is finished.
virtual void report(const std::string &a_text)
Report non-specific text.
Definition: listener.h:201
Definition: listener.h:71
virtual void report_error(const std::string &a_text)
Send error message.
Definition: listener.h:214

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