sgdk::IndexTypeTransitionFunction<> Class Template Reference
[FSM Module]

#include <swiss_gd_knife/ai/fsm/transition.hpp>

List of all members.


Detailed Description

template<>
class sgdk::IndexTypeTransitionFunction<>

The theoretical backbone of a finite state machine (FSM) is its transition function. Given a state in the FSM and an input that the FSM recognizes, the transition function outputs the next state. The table below shows the output of a sample transition function.

Next State Transition Function
Current State Input
alpha beta gamma delta
S A A B S
A A B S A
B B B B F
F F F F F

The example below shows how to generate the above transition function using this class.

// std::ostream and std::cout
#include <iostream>
// std::string
#include <string>
// std::vector
#include <vector>
// sgdk::IndexTypeTransitionFunction
#include <swiss_gd_knife/ai/fsm/transition.hpp>
// sgdk::DenseMatrix
#include <swiss_gd_knife/zref/matrix.hpp>

/*
 * Runs the example.
 */
int main()
{
    typedef sgdk::IndexTypeTransitionFunction<sgdk::DenseMatrix<unsigned int> >
            TransitionFunction;

    std::vector<std::string> alphabet;

    alphabet.push_back("S");
    alphabet.push_back("A");
    alphabet.push_back("B");
    alphabet.push_back("F");

    std::vector<std::string> input;

    input.push_back("alpha");
    input.push_back("beta");
    input.push_back("gamma");
    input.push_back("delta");

    TransitionFunction trans_func(alphabet.size(), input.size());

    trans_func.setTransition(0, 0, 1);
    trans_func.setTransition(0, 1, 1);
    trans_func.setTransition(0, 2, 2);
    trans_func.setTransition(1, 1, 2);
    trans_func.setTransition(1, 2, 0);
    trans_func.setTransition(2, 3, 3);

    std::cout << "Next State Table:" << std::endl << std::endl << "Current";

    for (unsigned int i = 0; i < input.size(); ++i)
    {
        std::cout << "\t" << input[i];
    }

    for (unsigned int s = 0; s < alphabet.size(); ++s)
    {
        std::cout << std::endl << alphabet[s];

        for (unsigned int i = 0; i < input.size(); ++i)
        {
            std::cout << "\t" << alphabet[trans_func(s, i)];
        }
    }

    std::cout << std::endl;

    return 0;
}


Template parameters

Parameter Description Default
StateInputMatrix The type of the underlying table used to implement operator().
Index The type of the states and inputs. unsigned int


Model of


Type requirements



Public Member Functions

 IndexTypeTransitionFunction (const Index state_count=2, const Index input_count=2)
 The default constructor.
 IndexTypeTransitionFunction (const IndexTypeTransitionFunction &copy)
 The copy constructor.
IndexTypeTransitionFunctionoperator= (const IndexTypeTransitionFunction &copy)
 The assignment operator.
const Index & operator() (const Index state, const Index input) const
void setTransition (const Index state, const Index input, const Index next_state)
Index getStateCount () const
Index getInputCount () const
void resize (const Index state_count, const Index input_count)


Constructor & Destructor Documentation

sgdk::IndexTypeTransitionFunction<>::IndexTypeTransitionFunction const Index  state_count = 2,
const Index  input_count = 2
[explicit]
 

Constructs a new IndexTypeTransitionFunction. Each state will transition back to itself regardless of any legal input that is processed.

Parameters:
state_count the number of states that this transition function will recognize. The states themselves will number from zero to state_count - 1.
input_count the number of inputs that this transition function will recognize. The inputs themselves will number from zero to input_count - 1.

sgdk::IndexTypeTransitionFunction<>::IndexTypeTransitionFunction const IndexTypeTransitionFunction<> &  copy  )  [inline]
 

Constructs a new IndexTypeTransitionFunction that will be internally equivalent to the copy at this point in time.

Parameters:
copy the IndexTypeTransitionFunction being copied.


Member Function Documentation

IndexTypeTransitionFunction& sgdk::IndexTypeTransitionFunction<>::operator= const IndexTypeTransitionFunction<> &  copy  )  [inline]
 

Sets this IndexTypeTransitionFunction to be internally equivalent to the copy.

Parameters:
copy the IndexTypeTransitionFunction being copied.
Returns:
a reference to this IndexTypeTransitionFunction.

const Index& sgdk::IndexTypeTransitionFunction<>::operator() const Index  state,
const Index  input
const [inline]
 

Returns a const reference to the state that will result when the specified input is processed in the specified state.

Parameters:
state the current state.
input the input to be processed in the current state.
Precondition:
0 <= state < getStateCount()

0 <= input < getInputCount()

Returns:
the next state.
See also:
setTransition()

void sgdk::IndexTypeTransitionFunction<>::setTransition const Index  state,
const Index  input,
const Index  next_state
[inline]
 

Sets operator() to return next_state when state and input are passed as arguments.

Parameters:
state the current state.
input the input to be processed in the current state.
next_state the next state.
Precondition:
0 <= state < getStateCount()

0 <= input < getInputCount()

0 <= next_state < getStateCount()

Index sgdk::IndexTypeTransitionFunction<>::getStateCount  )  const [inline]
 

Returns the number of states in the domain of this IndexTypeTransitionFunction.

Returns:
the number of valid states recognized by this IndexTypeTransitionFunction.

Index sgdk::IndexTypeTransitionFunction<>::getInputCount  )  const [inline]
 

Returns the number of inputs this IndexTypeTransitionFunction can process.

Returns:
the number of valid inputs recognized by this IndexTypeTransitionFunction.

void sgdk::IndexTypeTransitionFunction<>::resize const Index  state_count,
const Index  input_count
 

Resets this IndexTypeTransitionFunction. Until the next setTransition() call, each state will transition back to itself regardless of any legal input that is processed.

Parameters:
state_count the number of states that this transition function will recognize. The states themselves will number from zero to state_count - 1.
input_count the number of inputs that this transition function will recognize. The inputs themselves will number from zero to input_count - 1.


Swiss GD Knife is hosted by SourceForge.net.