Evocosm - A C++ Framework for Evolutionary Computing

Main Index

Created by Scott Robert Ladd at Coyote Gulch Productions.


libevocosm::fsm< InputT, OutputT > Class Template Reference

A finite state machine. More...

#include <fsm.h>

Inheritance diagram for libevocosm::fsm< InputT, OutputT >:

libevocosm::globals libevocosm::fsm_tools

List of all members.

Public Types

Public Member Functions

Protected Attributes

Static Protected Attributes


Detailed Description

template<typename InputT, typename OutputT>
class libevocosm::fsm< InputT, OutputT >

The class defines an abstract finite state machine with parameterized input and output types. A machine could take character inputs and return integer outputs, for example.

While this class provides great flexibility in FSM design (given that inputs and outputs can be almost any type of object), the class suffers from performance problems, especially when used in a genetic algorithm, where many, many objects are copied and created. In general, I've switched to using the simple_fsm class, mapping integer inputs and outputs to object tables where required.

Parameters:
InputT Input type
OutputT Output type

Constructor & Destructor Documentation

template<typename InputT, typename OutputT>
libevocosm::fsm< InputT, OutputT >::fsm ( size_t  a_size,
const std::vector< t_input > &  a_inputs,
const std::vector< t_output > &  a_outputs 
) [inline]

Creates a new finite state machine with a given number of states, and input set and an output set.

Parameters:
a_size - Initial number of states in this machine
a_inputs - A list of input values
a_outputs - A list of output values

References libevocosm::fsm< InputT, OutputT >::m_current_state, libevocosm::fsm< InputT, OutputT >::m_init_state, libevocosm::fsm< InputT, OutputT >::m_size, libevocosm::fsm< InputT, OutputT >::m_state_table, and libevocosm::globals::rand_index().

template<typename InputT, typename OutputT>
libevocosm::fsm< InputT, OutputT >::fsm ( const fsm< InputT, OutputT > &  a_parent1,
const fsm< InputT, OutputT > &  a_parent2 
) [inline]

Creates a new fsm by combining the states of two parent machines. Each state in the child has an equal likelihood of being a copy of the corresponding state in either a_parent1 or a_parent2. If one parent has more states than the other, the child will also have copies of the "extra" states taken from the longer parent.

Parameters:
a_parent1 - The first parent organism
a_parent2 - The second parent organism

References libevocosm::globals::g_random, libevocosm::prng::get_real(), libevocosm::fsm< InputT, OutputT >::m_current_state, libevocosm::fsm< InputT, OutputT >::m_init_state, libevocosm::fsm< InputT, OutputT >::m_size, and libevocosm::fsm< InputT, OutputT >::m_state_table.

template<typename InputT, typename OutputT>
libevocosm::fsm< InputT, OutputT >::fsm ( const fsm< InputT, OutputT > &  a_source  )  [inline]

Creates a new fsm identical to an existing one.

Parameters:
a_source - Object to be copied

template<typename InputT, typename OutputT>
libevocosm::fsm< InputT, OutputT >::~fsm (  )  [inline, virtual]

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


Member Function Documentation

template<typename InputT, typename OutputT>
fsm< InputT, OutputT > & libevocosm::fsm< InputT, OutputT >::operator= ( const fsm< InputT, OutputT > &  a_source  )  [inline]

template<typename InputT, typename OutputT>
void libevocosm::fsm< InputT, OutputT >::mutate ( double  a_rate,
const std::vector< t_input > &  a_inputs,
const std::vector< t_output > &  a_outputs,
mutation_selector a_selector = g_default_selector 
) [inline]

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 fsm. The same principle holds for the mutation selector.
    Parameters:
    a_rate - Chance that any given state will mutate
    a_inputs - A list of valid input states
    a_outputs - A list of valid output states
    a_selector - A mutation selector

References libevocosm::globals::g_random, libevocosm::fsm_tools::mutation_selector::get_index(), libevocosm::prng::get_real(), libevocosm::fsm< InputT, OutputT >::m_current_state, libevocosm::fsm< InputT, OutputT >::m_init_state, libevocosm::fsm< InputT, OutputT >::m_size, libevocosm::fsm< InputT, OutputT >::m_state_table, libevocosm::fsm_tools::MUTATE_INIT_STATE, libevocosm::fsm_tools::MUTATE_OUTPUT_SYMBOL, libevocosm::fsm_tools::MUTATE_REPLACE_STATE, libevocosm::fsm_tools::MUTATE_SWAP_STATES, libevocosm::fsm_tools::MUTATE_TRANSITION, and libevocosm::globals::rand_index().

template<typename InputT, typename OutputT>
fsm< InputT, OutputT >::t_output libevocosm::fsm< InputT, OutputT >::transition ( const fsm< InputT, OutputT >::t_input a_input  )  [inline]

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

Parameters:
a_input - An input symbol

References libevocosm::fsm< InputT, OutputT >::m_current_state, and libevocosm::fsm< InputT, OutputT >::m_state_table.

template<typename InputT, typename OutputT>
void libevocosm::fsm< InputT, OutputT >::reset (  )  [inline]

Prepares the FSM to start running from its initial state.

References libevocosm::fsm< InputT, OutputT >::m_current_state, and libevocosm::fsm< InputT, OutputT >::m_init_state.

template<typename InputT, typename OutputT>
fsm< InputT, OutputT >::t_state_table libevocosm::fsm< InputT, OutputT >::get_table (  )  const [inline]

Returns a copy of the state transition table. Useful for reporting the "program" stored in an fsm.

Returns:
A copy of the internal state transition table

References libevocosm::fsm< InputT, OutputT >::m_state_table.

template<typename InputT, typename OutputT>
size_t libevocosm::fsm< InputT, OutputT >::get_init_state (  )  const [inline]

Returns the initial (start up) state.

Returns:
The initial state

References libevocosm::fsm< InputT, OutputT >::m_init_state.

template<typename InputT, typename OutputT>
size_t libevocosm::fsm< InputT, OutputT >::get_current_state (  )  const [inline]

Returns the current (active) state.

Returns:
The current state

References libevocosm::fsm< InputT, OutputT >::m_current_state.


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.