transition.hpp

Go to the documentation of this file.
00001 
00027 #ifndef SGDK_AI_FSM_TRANSITION_HPP
00028 #define SGDK_AI_FSM_TRANSITION_HPP
00029 
00030 namespace sgdk {
00031 
00033 
00133 template <
00134 #ifndef SGDK_DOX
00135     typename StateInputMatrix
00136   , typename Index = unsigned int
00137 #endif  /* SGDK_DOX */
00138 >
00139 class IndexTypeTransitionFunction
00140 {
00141  private:
00142     Index            _state_count;
00143     Index            _input_count;
00144     StateInputMatrix _transition_matrix;
00145 
00146  public:
00148 
00160     explicit IndexTypeTransitionFunction(
00161         const Index state_count = 2
00162       , const Index input_count = 2
00163     );
00164 
00166 
00172     IndexTypeTransitionFunction(const IndexTypeTransitionFunction& copy)
00173       : _state_count(copy._state_count)
00174       , _input_count(copy._input_count)
00175       , _transition_matrix(copy._transition_matrix)
00176     {
00177     }
00178 
00180 
00187     IndexTypeTransitionFunction&
00188         operator=(const IndexTypeTransitionFunction& copy)
00189     {
00190         _state_count       = copy._state_count;
00191         _input_count       = copy._input_count;
00192         _transition_matrix = copy._transition_matrix;
00193         return *this;
00194     }
00195 
00207     inline const Index&
00208         operator()(const Index state, const Index input) const
00209     {
00210         const Index& value = _transition_matrix(state, input);
00211 
00212         return value;
00213     }
00214 
00226     inline void
00227         setTransition(
00228             const Index state
00229           , const Index input
00230           , const Index next_state
00231         )
00232     {
00233         _transition_matrix(state, input) = next_state;
00234     }
00235 
00243     inline Index getStateCount() const
00244     {
00245         return _state_count;
00246     }
00247 
00255     inline Index getInputCount() const
00256     {
00257         return _input_count;
00258     }
00259 
00272     void resize(const Index state_count, const Index input_count);
00273 };
00274 
00275 #ifndef SGDK_DOX
00276 template <typename StateInputMatrix, typename Index>
00277 #endif  /* SGDK_DOX */
00278 IndexTypeTransitionFunction<
00279 #ifndef SGDK_DOX
00280     StateInputMatrix
00281   , Index
00282 #endif  /* SGDK_DOX */
00283 >::IndexTypeTransitionFunction(const Index state_count, const Index input_count)
00284   : _state_count(state_count)
00285   , _input_count(input_count)
00286   , _transition_matrix(state_count, input_count)
00287 {
00288     for (Index state = 0; state < state_count; ++state)
00289     {
00290         for (Index input = 0; input < input_count; ++input)
00291         {
00292             _transition_matrix(state, input) = state;
00293         }
00294     }
00295 }
00296 
00297 #ifndef SGDK_DOX
00298 template <typename StateInputMatrix, typename Index>
00299 #endif  /* SGDK_DOX */
00300 void
00301     IndexTypeTransitionFunction<
00302 #ifndef SGDK_DOX
00303         StateInputMatrix
00304       , Index
00305 #endif  /* SGDK_DOX */
00306     >::resize(const Index state_count, const Index input_count)
00307 {
00308     _state_count = state_count;
00309     _input_count = input_count;
00310     _transition_matrix.resize(state_count, input_count);
00311 
00312     for (Index state = 0; state < state_count; ++state)
00313     {
00314         for (Index input = 0; input < input_count; ++input)
00315         {
00316             _transition_matrix(state, input) = state;
00317         }
00318     }
00319 }
00320 }  // namespace sgdk
00321 
00322 #endif  /* SGDK_AI_FSM_TRANSITION_HPP */

Swiss GD Knife is hosted by SourceForge.net.