Re: Finite state machine in python

2009-09-13 Thread Banibrata Dutta
For simplistic FSMs, if you want to avoid hand-coding all the transitions,
actions etc., you could consider something like Libero (
http://www.cs.vu.nl/~eliens/documents/libero/lrintr.htm), although the last
I checked Libero didn't generate Python yet (but I believe there might be
similar options available with Python, though haven't come accross
anything). Machine generated FSMs can be suboptimal for many cases though.

On Sun, Sep 13, 2009 at 10:28 AM, CTO debat...@gmail.com wrote:

 On Sep 12, 4:39 pm, Peng Yu pengyu...@gmail.com wrote:
  Hi,
 
  I have see some discussion on the implementation of finite state
  machine in python. Can somebody point to me the best way in implenting
  an FSM in python?
 
  http://code.activestate.com/recipes/146262/
 
  Regards,
  Peng

 I wrote an example of how to do it using Graphine a while back.
 Probably not the most efficient in the world, but pretty easy
 to read, and it allows you to add and remove states and transitions
 easily.

 URL: http://gitorious.org/graphine/pages/GraphineForPythonistas

 Geremy Condra
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finite state machine in python

2009-09-13 Thread Hendrik van Rooyen
On Saturday 12 September 2009 22:39:10 Peng Yu wrote:
 Hi,

 I have see some discussion on the implementation of finite state
 machine in python. Can somebody point to me the best way in implenting
 an FSM in python?

 http://code.activestate.com/recipes/146262/

You can go a long way with a far simpler model than the one in that recipe:

1) Define a routine for every state.
2) Have every state do the following:
 (i) Run the code to make the side effects like outputs happen.
(ii) Scan the conditions for the state transitions relevant to this state.
  (Only the arrows leaving this state on the state diagram.)
(iii) Return the next state (either the same or a different state).

3) The main loop of a long running machine then looks like this:

next_state = start_state()

while True:
next_state = next_state()
time.sleep(step_time)   # if needed

This simple model is surprisingly powerful, and it can be expanded to run a 
bundle of such machines in parallel very easily, by keeping a list of 
next_states and continuously cycling through and updating the list.

You do not even need a dispatch dictionary.

This is about the simplest model for making FSMs that I know of.
Not sure if it is the best - best for what?.

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Finite state machine in python

2009-09-12 Thread Peng Yu
Hi,

I have see some discussion on the implementation of finite state
machine in python. Can somebody point to me the best way in implenting
an FSM in python?

http://code.activestate.com/recipes/146262/

Regards,
Peng
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finite state machine in python

2009-09-12 Thread Tim Chase

I have see some discussion on the implementation of finite
state machine in python. Can somebody point to me the best way
in implenting an FSM in python?


To offer a best way requires knowing more about what you're 
trying to accomplish.  Are you looking for just some fixed 
states?  are you looking to dynamically adjust the available 
states?  Is this workflow for a single user, or is it for 
multiple users?  A FSM merely involves a list of states and the 
transitions between them.  You can augment the states and/or the 
transitions with additional metadata.  You can store your states 
in fixed internal hard-coded structures, or you can store them in 
a file/database that can grow external.


I posted information on doing this with a SQL-ish database 
(whether sqlite or whatever) a while back, so you can see a more 
complex version of tracking this info:


http://article.gmane.org/gmane.comp.python.general/624448


Hope this gives you some ideas from which to choose an option 
that's best for your needs.


-tkc





--
http://mail.python.org/mailman/listinfo/python-list


Re: Finite state machine in python

2009-09-12 Thread CTO
On Sep 12, 4:39 pm, Peng Yu pengyu...@gmail.com wrote:
 Hi,

 I have see some discussion on the implementation of finite state
 machine in python. Can somebody point to me the best way in implenting
 an FSM in python?

 http://code.activestate.com/recipes/146262/

 Regards,
 Peng

I wrote an example of how to do it using Graphine a while back.
Probably not the most efficient in the world, but pretty easy
to read, and it allows you to add and remove states and transitions
easily.

URL: http://gitorious.org/graphine/pages/GraphineForPythonistas

Geremy Condra
-- 
http://mail.python.org/mailman/listinfo/python-list