Evocosm - A C++ Framework for Evolutionary Computing

Main Index

Created by Scott Robert Ladd at Coyote Gulch Productions.


Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
libevocosm::simple_machine< InSize, OutSize > Class Template Reference

A simple finite state machine with integer-indexed states. More...

#include <simple_machine.h>

Inheritance diagram for libevocosm::simple_machine< InSize, OutSize >:
libevocosm::globals libevocosm::machine_tools

Classes

struct  tranout_t
 Defines a transition and output state pair. More...
 

Public Member Functions

 simple_machine (size_t a_size)
 Creation constructor. More...
 
 simple_machine (const simple_machine< InSize, OutSize > &a_parent1, const simple_machine< InSize, OutSize > &a_parent2)
 Construct via bisexual crossover. More...
 
 simple_machine (const simple_machine< InSize, OutSize > &a_source)
 Copy constructor. More...
 
virtual ~simple_machine ()
 Virtual destructor. More...
 
simple_machineoperator= (const simple_machine< InSize, OutSize > &a_source)
 
void mutate (double a_rate)
 Mutation. More...
 
size_t transition (size_t a_input)
 Cause state transition. More...
 
void reset ()
 Reset to start-up state. More...
 
size_t size () const
 Get size. More...
 
const tranout_tget_transition (size_t a_state, size_t a_input) const
 Get a transition from the internal state table. More...
 
size_t num_input_states () const
 Get number of input states. More...
 
size_t num_output_states () const
 Get number of output states. More...
 
size_t init_state () const
 Get initial state. More...
 
size_t current_state () const
 Get current state. More...
 

Static Public Member Functions

static void set_mutation_weight (mutation_id a_type, double a_weight)
 Set a mutation weight. More...
 

Protected Attributes

tranout_t ** m_state_table
 State table (the machine definition)
 
size_t m_init_state
 Initial state.
 
size_t m_current_state
 Current state.
 
size_t m_size
 Number of states.
 

Static Protected Attributes

static mutation_selector g_selector
 Global mutation selector.
 
- Static Protected Attributes inherited from libevocosm::globals
static prng g_random
 A shared random number generator.
 
static std::string g_version
 Version number.
 

Additional Inherited Members

- Protected Types inherited from libevocosm::machine_tools
enum  mutation_id {
  MUTATE_OUTPUT_SYMBOL, MUTATE_TRANSITION, MUTATE_REPLACE_STATE, MUTATE_SWAP_STATES,
  MUTATE_INIT_STATE
}
 Types of mutation supported. More...
 
- Static Protected Member Functions inherited from libevocosm::globals
static size_t rand_index (size_t n)
 Static function to allow use of g_random function pointer in random_shuffle.
 
static void set_seed (uint32_t a_seed)
 Set the seed for the random number generator.
 
static uint32_t get_seed ()
 Set the seed for the random number generator.
 
static std::string version ()
 Get version number.
 

Detailed Description

template<size_t InSize, size_t OutSize>
class libevocosm::simple_machine< InSize, OutSize >

The class defines an abstract finite state machine that uses unsigned integer input and output types. This is much faster than the generic fsm class because the transition table can be represented as a simple two-dimensional array.

Parameters
InputSizeNumber of input states
OutputSizeNumber of output states

Constructor & Destructor Documentation

template<size_t InSize, size_t OutSize>
libevocosm::simple_machine< InSize, OutSize >::simple_machine ( size_t  a_size)
template<size_t InSize, size_t OutSize>
libevocosm::simple_machine< InSize, OutSize >::simple_machine ( const simple_machine< InSize, OutSize > &  a_parent1,
const simple_machine< InSize, OutSize > &  a_parent2 
)
template<size_t InSize, size_t OutSize>
libevocosm::simple_machine< InSize, OutSize >::simple_machine ( const simple_machine< InSize, OutSize > &  a_source)

Creates a new simple_machine identical to an existing one.

Parameters
a_source- Object to be copied
template<size_t InSize, size_t OutSize>
libevocosm::simple_machine< InSize, OutSize >::~simple_machine ( )
virtual

Does nothing in the base class; exists to allow destruction of derived class objects through base class pointers.

Member Function Documentation

template<size_t InSize, size_t OutSize>
size_t libevocosm::simple_machine< InSize, OutSize >::current_state ( ) const
inline

Returns the current (active) state.

Returns
The current state
template<size_t InSize, size_t OutSize>
const simple_machine< InSize, OutSize >::tranout_t & libevocosm::simple_machine< InSize, OutSize >::get_transition ( size_t  a_state,
size_t  a_input 
) const
inline

Get a transition from the internal state table.

Parameters
a_state- Target state
a_input- State information to return
Returns
A transition from the internal state table
template<size_t InSize, size_t OutSize>
size_t libevocosm::simple_machine< InSize, OutSize >::init_state ( ) const
inline

Returns the initial (start up) state.

Returns
The initial state
template<size_t InSize, size_t OutSize>
void libevocosm::simple_machine< InSize, OutSize >::mutate ( double  a_rate)

Mutates a finite state machine object. The four mutations supported are:

  • Change a random output symbol
  • Change a random state transition
  • Swap two randomly-selected states
  • Randomly change the initial state Why not store the input and output sets in the machine itself? That would duplicate information across every machine of a given type, greatly increasing the memory footprint of each simple_machine. The same principle holds for the mutation selector.
    Parameters
    a_rate- Chance that any given state will mutate

References libevocosm::simple_machine< InSize, OutSize >::tranout_t::m_new_state.

template<size_t InSize, size_t OutSize>
size_t libevocosm::simple_machine< InSize, OutSize >::num_input_states ( ) const
inline

Returns the number of input states

Returns
The number of input states
template<size_t InSize, size_t OutSize>
size_t libevocosm::simple_machine< InSize, OutSize >::num_output_states ( ) const
inline

Returns the number of output states

Returns
The number of output states
template<size_t InSize, size_t OutSize>
simple_machine< InSize, OutSize > & libevocosm::simple_machine< InSize, OutSize >::operator= ( const simple_machine< InSize, OutSize > &  a_source)

Copies the state of an existing simple_machine.

Parameters
a_source- Object to be copied
Returns
A reference to the target object

References libevocosm::simple_machine< InSize, OutSize >::m_current_state, libevocosm::simple_machine< InSize, OutSize >::m_init_state, and libevocosm::simple_machine< InSize, OutSize >::m_size.

template<size_t InSize, size_t OutSize>
void libevocosm::simple_machine< InSize, OutSize >::reset ( )
inline

Prepares the FSM to start running from its initial state.

template<size_t InSize, size_t OutSize>
void libevocosm::simple_machine< InSize, OutSize >::set_mutation_weight ( mutation_id  a_type,
double  a_weight 
)
inlinestatic

Sets the weight value associated with a specific mutation; this changes the relative chance of this mutation happening.

Parameters
a_type- ID of the weight to be changed
a_weight- New weight to be assigned
template<size_t InSize, size_t OutSize>
size_t libevocosm::simple_machine< InSize, OutSize >::size ( ) const
inline

Returns the size of a simple_machine.

Returns
The size, in number of states
template<size_t InSize, size_t OutSize>
size_t libevocosm::simple_machine< InSize, OutSize >::transition ( size_t  a_input)
inline

Based on an input symbol, this function changes the state of an simple_machine and returns an output symbol.

Parameters
a_input- An input value
Returns
Output value resulting from transition

The documentation for this class was generated from the following file:

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