Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2005-05-14 23:07:39
Size: 3522
Editor: aaron
Comment: researching FSM's in the wild
Revision 3 as of 2005-10-10 06:32:21
Size: 3840
Editor: 62
Comment:
Deletions are marked like this. Additions are marked like this.
Line 19: Line 19:
Line 22: Line 23:
Line 27: Line 29:
You can also [http://www.noah.org/python/FSM/ find it on his website.]

Line 30: Line 35:
Line 97: Line 103:

----
The Best monitor Directory on the Web

http://www.monitordirectory.vip.su

Monitor Directory has delivered to the market scores of standard and custom products and software solutions.

http://www.monitordirectory.vip.su

This is a summary of FSM implementations in Python right now.

For general information about finite state machines, see:

  • [wiki:WikiPedia/Finite_state_machine Wikipedia:Finite_state_machine] -- B) excellent! B)

  • [wiki:Wiki/FiniteStateMachine FiniteStateMachine]

TableOfContents()

[http://fsme.sourceforge.net/ Finite State Machine Editor]

This is a tool where you can draw FSM diagrams, and then compile to a Python module (or C++ code.) It also makes an XML description of the FSM.

Requires QT for the editor. (Not the compiler, though, which probably reads XML.)

* [http://fsme.sourceforge.net/doc/tutorial.html tutorial] * [http://fsme.sourceforge.net/phpwiki/ project wiki]

[http://osteele.com/software/python/fsa/ FSA - Finite State Automation in Python]

This seems to be all about making FSMs, but I don't see a whole lot on how to use them!

[http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146262 Noah Spurrier's FSM]

This is one found on ActiveState; It's purely Python code. You init an FSM, register transitions, and then throw inputs at it. States and inputs must be hashable.

You can also [http://www.noah.org/python/FSM/ find it on his website.]

[http://www.research.att.com/projects/mohri/fsm/doc4/fsmpy.html fsmpy module]

This seems to be a Python wrapper around [http://www.research.att.com/projects/mohri/fsm/ AT&T's FSM library.] It's all oriented around "weighted" finite state machines, so I'm not so sure how suitable it is if you just want to use unweighted FSM.

SkipMontanaro's FSM

[http://www.python.org/search/hypermail/python-recent/0667.html From an e-mail.]

Features transition actions.

I've re-interpreted the code, adding formatting lost in e-mail, and PythonStyle-itizing it a bit.

   1 """Finite state machine, featuring transition actions."""
   2 
   3 FSMError = 'Invalid input to finite state machine'
   4 
   5 class FSM:
   6 
   7     """Finite state machine, featuring transition actions.
   8 
   9     The class stores a dictionary of (state, input) keys,
  10     and (state, action) values.
  11 
  12     When a (state, input) search is performed:
  13     * an exact match is checked first,
  14     * (state, None) is checked next.
  15 
  16     The action is of the following form:
  17     * function(current_state, input)
  18     """
  19     
  20     def __init__(self):
  21         self.states = {}
  22         self.state = None
  23         self.dbg = None
  24 
  25     def add(self, state, input, newstate, action):
  26         """Add a transition to the FSM."""
  27         self.states[(state, input)] = (newstate, action)
  28 
  29     def execute(self, input):
  30         """Perform a transition and execute action."""
  31         si = (self.state, input)
  32         sn = (self.state, None)
  33         # exact state match?
  34         if self.states.has_key(si):
  35             newstate, action = self.states[si]
  36         # no, how about a None (catch-all) match?
  37         elif self.states.has_key(sn):
  38             newstate, action = self.states[sn]
  39         if self.dbg != None:
  40             self.dbg.write('State: %s / Input: %s /'
  41                            'Next State: %s / Action: %s\n' %
  42                            (self.state, input, newstate, action))
  43         apply(action, (self.state, input))
  44         self.state = newstate
  45 
  46     def start(self, state):
  47         """Define the start state.
  48 
  49         Actually, this just resets the current state.
  50         """
  51         self.state = state
  52 
  53     def debug(self, out):
  54         """Assign a writable file to log transitions."""
  55         self.dbg = out


The Best monitor Directory on the Web

http://www.monitordirectory.vip.su

Monitor Directory has delivered to the market scores of standard and custom products and software solutions.

http://www.monitordirectory.vip.su

FiniteStateMachine (last edited 2014-09-06 09:12:52 by IoannisFilippidis)

Unable to edit the page? See the FrontPage for instructions.