Class Index

View All Classes

Class vs.core.Fsm

Extends vs.core.EventSource.

Fsm element defines a deterministic Finite-State-Machine (aka Finite-State Automaton). A fsn is an automaton such as:

A fsm is specified as flollowing : When an automaton is rendered (after run), it begins in the initial state. It changes to new states depending on events that it receives and the transition function. Whenever the automaton is deactivated (for instance by being in a deactivated branch of a Rules), it does not react any more to events. It will resume to its last state and react again to events when reactivated.

The general manner to control fsm and make it cross a transition is to associate event to a input lexem. For that use the methods setInput (). But an automaton can also be manually control by notifying to it a input lexem. For that, use the method Fsm.fsmNotify (String).

Automatons can have outputs associated to their transitions (aka Mealy machine) or states (aka Moore machine, not yet implemented). At that time the fsm emit event defined by an string (the output lexem) or call an action associated to the output lexem. The event can be received by setting a Binding on this fsm. Otherwise for specifying the action use the setOuput () method.

Known limitations: Simple example to create a automata:

Class Summary
Constructor Attributes Constructor Name and Description
 
vs.core.Fsm(owner)
The Fsm class
Field Summary
Field Attributes Field Name and Description
 
Define the initiale state Generate a exception if the state was not already defined
Fields borrowed from class vs.core.Object:
getOwnPropertyDescriptor, getPropertyDescriptor, id, propagateChange
Method Summary
Method Attributes Method Name and Description
 
Activate the FSM which start by the initial state.
 
addInput(input)
Add an imput to the fsm This input will be add to the list of input alphabet.
 
addOutput(output)
Add an ouput to the fsm This ouput will be add to the list of ouput alphabet.
 
addState(name)
Add a State to the fsm
 
addTransition(from, to, on, ouput)
Add a new transition from the state "from" to the state "to".
 
Clear the fsm.
 
existInput(input)
Test if a word in inlcude in imput alphabet
 
existOutput(output)
Test if a word in include in ouput alphabet
 
existState(state)
Test existance of a state
 
 
Return the input alphabet of the fsm
 
Get list of fsm State
 
Return the ouput alphabet of the fsm
 
Return the list of transitions from the state set
 
Return the list of transitions to the state set
 
initWithData(states, inputs, outputs, transitions)
Full facility constructor that takes specification of the fsm as parameter.
 
Full facility constructor that takes state x state matrix of the fsm as parameter:
  • First columm : list of "from" sates \n
  • First row : list of "to" sates \n
  • other cell : tuple "i/o" of input and ouput event \n
If no id is specified, will create a random one.
 
Remove a State from the fsm
 
Remove a transition from the state "from".
 
Remove a transition to the state "to".
 
renameState(old_name, new_name)
Rename a State of the fsm
 
setInput(on, src, spec)
Build a event binding to an input lexem.
 
setOutput(output, action)
Associate an action to the generation of an output lexem.
 
switchStates(state_id1, state_id2)
Switch two states of the fsm if states have transitions from or to them, the function reconfigures the transitions.
Methods borrowed from class vs.core.EventSource:
bind, clone, nodeBind, nodeUnbind, propagate, unbind
Methods borrowed from class vs.core.Object:
configure, getProperties, init, parseJSON, propertyChange, toJSON
Class Detail
vs.core.Fsm(owner)
The Fsm class
Author: David Thevenin.
  var my_fsm = new vs.core.Fsm (object);
  // States declaration 
  my_fsm.addState ("1");
  my_fsm.addState ("2");
  // Input lexems declaration
  my_fsm.addInput ("a");
  my_fsm.addInput ("b");
  // Ouptut lexems declaration
  my_fsm.addOutput ("c");
  my_fsm.addOutput ("d");
  // transitions declaration
  my_fsm.addTransition ("1", "2", "a", "c");
  my_fsm.addTransition ("2", "3", "b", "d");
  // initial state declaration
  my_fsm.setInitialState ("1");
  // activate the FSM
  my_fsm.activate ();

  // event associations
  // "a" will be generated after the button selection
  my_fsm.setInput ("a", aButton, 'select');
Parameters:
{vs.core.Object} owner
the Object using this Fsm [mandatory]
Field Detail
initialState
Define the initiale state Generate a exception if the state was not already defined
Method Detail
{boolean} activate()
Activate the FSM which start by the initial state.

Return false if no initial state is specified.

Returns:
{boolean} is activated

addInput(input)
Add an imput to the fsm This input will be add to the list of input alphabet.
Parameters:
{string} input
the new word that will be add to the alphabet

addOutput(output)
Add an ouput to the fsm This ouput will be add to the list of ouput alphabet.
Parameters:
{string} output
the new word that will be add to the alphabet

addState(name)
Add a State to the fsm
Parameters:
{string} name
the new state name

addTransition(from, to, on, ouput)
Add a new transition from the state "from" to the state "to". The state from have to be already specified, otherwise, it will generate a exception.
Parameters:
{string} from
State from
{string} to
State to
{string} on
input lexem which cause the crossing of transition
{string} ouput
optional ouput lexem that will be produce by the crossing

clear()
Clear the fsm. All state, event and binding are deleted

existInput(input)
Test if a word in inlcude in imput alphabet
Parameters:
{string} input
the input
Returns:
true is exists

existOutput(output)
Test if a word in include in ouput alphabet
Parameters:
{string} output
the output
Returns:
true is exists

existState(state)
Test existance of a state
Parameters:
{string} state
the state
Returns:
true if state exists

{Object} fsmNotify(on)
Parameters:
{String} on
input
Returns:
{Object} data associate to the event

{Array} getInputs()
Return the input alphabet of the fsm
Returns:
{Array} the alphabet as a set of String

{Array} getListState()
Get list of fsm State
Returns:
{Array} list of states

getOutputs()
Return the ouput alphabet of the fsm
Returns:
the alphanet as a set of String

{Array} getTransionsFromState(from)
Return the list of transitions from the state set
Parameters:
{string} from
State from
Returns:
{Array} list of transitions

{Array} getTransionsToState(to)
Return the list of transitions to the state set
Parameters:
{string} to
State to
Returns:
{Array} list of transitions

initWithData(states, inputs, outputs, transitions)
Full facility constructor that takes specification of the fsm as parameter. transitions is an array of object {from, to, on, output}
Parameters:
{Array} states
is an array of state
{Array} inputs
is an array of input
{Array} outputs
is an array of output
{Array} transitions
is an array of object {from, to, on, output}

initWithMatrix(matrix)
Full facility constructor that takes state x state matrix of the fsm as parameter:
  • First columm : list of "from" sates \n
  • First row : list of "to" sates \n
  • other cell : tuple "i/o" of input and ouput event \n
If no id is specified, will create a random one.
 // fsm is : 1 -a-> 2 -b-> 3 -c-> 1 \n

 matrix = [
      ["", "1", "2", "3"],
      ["1", "", "a/", ""],
      ["2", "", "", "b/"],
      ["3", "c/", "", ""]
 ];

 // Specification for input/output of a transition must have the following
 // form : "i" | "i/" | "/o" | "i/o"

 fsm = new Fsm (object);
 fsm.initWithMatrix (matrix);
Parameters:
{Array} matrix

removeState(name)
Remove a State from the fsm
Parameters:
{string} name
the new state name

removeTransitionFrom(from, on)
Remove a transition from the state "from".
Parameters:
{string} from
State from
{string} on
input lexem which cause the crossing of transition

removeTransitionTo(tp, on)
Remove a transition to the state "to".
Parameters:
{string} tp
State tp
{string} on
input lexem which cause the crossing of transition

renameState(old_name, new_name)
Rename a State of the fsm
Parameters:
{string} old_name
the old state name
{string} new_name
the new state name

setInput(on, src, spec)
Build a event binding to an input lexem. To control the fsm and make it passes trought a transition, the programmer is able to directly fsmNotify a entry lexem to the fsm (see the general fsm documentation), or associate event source and spec to an input lexem, like event binding.

This method takes as parameter a pointer on the event source and the specification of the event.
Parameters:
{string} on
input lexem on which is associated the event
{vs.core.EventSource} src
the object source of the event
{string} spec
the name of the event

setOutput(output, action)
Associate an action to the generation of an output lexem. To make able the fsm to control the application, the programmer can associate an action to the generation of an ouput lexem when the fsm cross a transition.

This method takes as parameter a pointer on an action object and a optional user data.
Parameters:
{string} output
output lexem on which is associated the action
{function|string} action
the function's name a function of the fsm owner

switchStates(state_id1, state_id2)
Switch two states of the fsm if states have transitions from or to them, the function reconfigures the transitions.
Parameters:
{string} state_id1
State
{string} state_id2
State