I couldn't install pygraphviz on my Windows 10 system so as a workaround I am trying to store the states and transitions of the FSM in a separate graph. For example:
from transitions import Machine
from graphviz import Digraph
class Matter(object):
pass
# The states
states=['hungry', 'satisfied', 'full', 'sick']
# And some transitions between states.
transitions = [
{ 'trigger': 'eat', 'source': 'hungry', 'dest': 'satisfied' },
{ 'trigger': 'eat', 'source': 'satisfied', 'dest': 'full' },
{ 'trigger': 'eat', 'source': 'full', 'dest': 'sick' },
{ 'trigger': 'rest', 'source': ['satisfied', 'full', 'sick'], 'dest':
'hungry' }]
# Initialize
machine = Matter()
fsm = Machine(machine, states=states, transitions=transitions, initial=states[0])
dot = Digraph(comment='FSM')
src = machine.state
for event in transitions:
machine.trigger(event['trigger'])
dst = machine.state
dot.edge(src,dst,event['trigger'])
src = dst
print (dot)
Here my graph doesn't include all the possible transitions and includes only the sequential transitions.
Output:
digraph {
hungry -> satisfied [label=eat]
satisfied -> full [label=eat]
full -> sick [label=eat]
sick -> hungry [label=rest]
}
As you can see the multiple state transitions are not present in the graph. Is there a way I can trigger all the transitions and store it in the graph or do I have to write a custom code for all of this to work.