Created by Scott Robert Ladd at Coyote Gulch Productions.
A finite state machine. More...
#include <simple_fsm.h>
Classes | |
| struct | tranout_t |
| Defines a transition and output state pair. More... | |
Public Member Functions | |
| simple_fsm (size_t a_size) | |
| Creation constructor. More... | |
| simple_fsm (const simple_fsm< InSize, OutSize > &a_parent1, const simple_fsm< InSize, OutSize > &a_parent2) | |
| Construct via bisexual crossover. More... | |
| simple_fsm (const simple_fsm< InSize, OutSize > &a_source) | |
| Copy constructor. More... | |
| virtual | ~simple_fsm () |
| Virtual destructor. More... | |
| simple_fsm & | operator= (const simple_fsm< 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_t & | get_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::fsm_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_random_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. | |
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.
| InputSize | Number of input states |
| OutputSize | Number of output states |
| libevocosm::simple_fsm< InSize, OutSize >::simple_fsm | ( | size_t | a_size | ) |
Creates a new finite state machine with a given number of states.
| a_size | - Initial number of states in this machine |
References libevocosm::simple_fsm< InSize, OutSize >::m_current_state, libevocosm::simple_fsm< InSize, OutSize >::m_init_state, libevocosm::simple_fsm< InSize, OutSize >::tranout_t::m_new_state, libevocosm::simple_fsm< InSize, OutSize >::tranout_t::m_output, libevocosm::simple_fsm< InSize, OutSize >::m_size, libevocosm::simple_fsm< InSize, OutSize >::m_state_table, and libevocosm::globals::rand_index().
| libevocosm::simple_fsm< InSize, OutSize >::simple_fsm | ( | const simple_fsm< InSize, OutSize > & | a_parent1, |
| const simple_fsm< InSize, OutSize > & | a_parent2 | ||
| ) |
Creates a new simple_fsm by combining the states of two parent machines.
| a_parent1 | - The first parent organism |
| a_parent2 | - The second parent organism |
References libevocosm::globals::g_random, libevocosm::prng::get_real(), libevocosm::simple_fsm< InSize, OutSize >::m_current_state, libevocosm::simple_fsm< InSize, OutSize >::m_init_state, libevocosm::simple_fsm< InSize, OutSize >::tranout_t::m_new_state, libevocosm::simple_fsm< InSize, OutSize >::tranout_t::m_output, libevocosm::simple_fsm< InSize, OutSize >::m_size, libevocosm::simple_fsm< InSize, OutSize >::m_state_table, and libevocosm::globals::rand_index().
| libevocosm::simple_fsm< InSize, OutSize >::simple_fsm | ( | const simple_fsm< InSize, OutSize > & | a_source | ) |
Creates a new simple_fsm identical to an existing one.
| a_source | - Object to be copied |
|
virtual |
Does nothing in the base class; exists to allow destruction of derived class objects through base class pointers.
|
inline |
Returns the current (active) state.
|
inline |
Get a transition from the internal state table.
| a_state | - Target state |
| a_input | - State information to return |
|
inline |
Returns the initial (start up) state.
| void libevocosm::simple_fsm< InSize, OutSize >::mutate | ( | double | a_rate | ) |
Mutates a finite state machine object. The four mutations supported are:
| a_rate | - Chance that any given state will mutate |
References libevocosm::simple_fsm< InSize, OutSize >::tranout_t::m_new_state.
|
inline |
Returns the number of input states
|
inline |
Returns the number of output states
| simple_fsm< InSize, OutSize > & libevocosm::simple_fsm< InSize, OutSize >::operator= | ( | const simple_fsm< InSize, OutSize > & | a_source | ) |
Copies the state of an existing simple_fsm.
| a_source | - Object to be copied |
References libevocosm::simple_fsm< InSize, OutSize >::m_current_state, libevocosm::simple_fsm< InSize, OutSize >::m_init_state, and libevocosm::simple_fsm< InSize, OutSize >::m_size.
|
inline |
Prepares the FSM to start running from its initial state.
|
inlinestatic |
Sets the weight value associated with a specific mutation; this changes the relative chance of this mutation happening.
| a_type | - ID of the weight to be changed |
| a_weight | - New weight to be assigned |
|
inline |
Returns the size of a simple_fsm.
|
inline |
Based on an input symbol, this function changes the state of an simple_fsm and returns an output symbol.
| a_input | - An input value |
© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.