Evocosm - A C++ Framework for Evolutionary Computing

Main Index

Created by Scott Robert Ladd at Coyote Gulch Productions.


fsm_tools.h
1 //---------------------------------------------------------------------
2 // Algorithmic Conjurings @ http://www.coyotegulch.com
3 // Evocosm -- An Object-Oriented Framework for Evolutionary Algorithms
4 //
5 // fsm_tools.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_FSM_TOOLS_H)
36 #define LIBEVOCOSM_FSM_TOOLS_H
37 
38 // libevocosm
39 #include "roulette.h"
40 
41 namespace libevocosm
42 {
44 
47  class fsm_tools
48  {
49  protected:
52  {
58  };
59 
61 
78  {
79  public:
81 
86  : m_selector(NULL)
87  {
88  static const double default_weights [] = { 20.0, 20.0, 20.0, 20.0, 20.0 };
89 
90  m_selector = new roulette_wheel(default_weights,5);
91  }
92 
94 
99  : m_selector(new roulette_wheel(*a_source.m_selector))
100  {
101  // nada
102  }
103 
105 
109  {
110  delete m_selector;
111  }
112 
114 
119  {
120  m_selector = new roulette_wheel(*a_source.m_selector);
121  return *this;
122  }
123 
125 
130  void set_weight(mutation_id a_type, double & a_new_weight)
131  {
132  m_selector->set_weight(a_type,a_new_weight);
133  }
134 
136  /*
137  Returns an index, shosen by roulette wheel, corresponding to a
138  <i>mutation_id</i> value.
139  \return A mutation_id index
140  */
141  size_t get_index() const
142  {
143  return m_selector->get_index();
144  }
145 
146  private:
147  // The actual roulette wheel
148  roulette_wheel * m_selector;
149  };
150  };
151 }
152 
153 #endif
Wraps a roulette wheel for selecting mutations.
Definition: fsm_tools.h:77
size_t get_index() const
Retrieve a random index.
mutation_selector()
Creation constructor.
Definition: fsm_tools.h:85
double set_weight(size_t a_index, double a_weight)
Change the weight assigned to an entry.
mutation_selector & operator=(const mutation_selector &a_source)
Assignment operator.
Definition: fsm_tools.h:118
A set of common tools for finite state machines.
Definition: fsm_tools.h:47
Mutate an output symbol.
Definition: fsm_tools.h:53
void set_weight(mutation_id a_type, double &a_new_weight)
Change a given weight.
Definition: fsm_tools.h:130
Mutate that initial state.
Definition: fsm_tools.h:57
Mutate a state transition.
Definition: fsm_tools.h:54
~mutation_selector()
Destructor.
Definition: fsm_tools.h:108
A toolkit and framework for implementing evolutionary algorithms.
Definition: evocommon.h:60
Swap two states.
Definition: fsm_tools.h:56
Replace a new state with a randomly-generated one.
Definition: fsm_tools.h:55
mutation_id
Types of mutation supported.
Definition: fsm_tools.h:51
mutation_selector(const mutation_selector &a_source)
Copy constructor.
Definition: fsm_tools.h:98
A simulated roulette wheel for weighted selection.
Definition: roulette.h:71
size_t get_index() const
Get a mutation index.
Definition: fsm_tools.h:141

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