#include <swiss_gd_knife/ai/fsm/transition.hpp>
| 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; }
| Parameter | Description | Default | 
|---|---|---|
StateInputMatrix  | The type of the underlying table used to implement operator().  |     | 
Index  | The type of the states and inputs. | unsigned int   | 
Index must be an unsigned integral type. StateInputMatrix::operator() must be convertible to const Index&. 
Public Member Functions | |
| IndexTypeTransitionFunction (const Index state_count=2, const Index input_count=2) | |
| The default constructor.   | |
| IndexTypeTransitionFunction (const IndexTypeTransitionFunction ©) | |
| The copy constructor.   | |
| IndexTypeTransitionFunction & | operator= (const IndexTypeTransitionFunction ©) | 
| 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) | 
      
  | 
  ||||||||||||
| 
 
Constructs a new  
 
  | 
  
      
  | 
  
| 
 
Constructs a new  
 
  | 
  
      
  | 
  
| 
 
Sets this  
 
 
  | 
  
      
  | 
  ||||||||||||
| 
 Returns a const reference to the state that will result when the specified input is processed in the specified state. 
 
 
 
 
  | 
  
      
  | 
  ||||||||||||||||
| 
 
Sets  
 
 
  | 
  
      
  | 
  
| 
 
Returns the number of states in the domain of this  
 
  | 
  
      
  | 
  
| 
 
Returns the number of inputs this  
 
  | 
  
      
  | 
  ||||||||||||
| 
 
Resets this  
 
  | 
  
Swiss GD Knife is hosted by .