-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
State Transition Table #691
Comments
Hi @laniakea, Option A: Iterate over machine.events
If you iterate over events and transition you could collect a dictionary of trigger dictionaries. from transitions import Machine
from collections import defaultdict
from pprint import pprint
from pandas import DataFrame
states = ["A", "B", "C"]
transitions = [["go", "A", "B"], ["go", "B", "C"], ["reset", "*", "A"]]
data = defaultdict(lambda: defaultdict(list))
machine = Machine(states=states, transitions=transitions, initial="A")
for trigger, event in machine.events.items():
for source, trans in event.transitions.items():
for tran in trans:
data[source][tran.dest].append(trigger)
pprint(data) # [1]
print(DataFrame([[", ".join(data[source][dest]) for dest in states] for source in states],
columns=states, index=states)) # [2] pprint [1]defaultdict(<function <lambda> at 0x100b923e0>,
{'A': defaultdict(<class 'list'>,
{'A': ['to_A', 'reset'],
'B': ['to_B', 'go'],
'C': ['to_C']}),
'B': defaultdict(<class 'list'>,
{'A': ['to_A', 'reset'],
'B': ['to_B'],
'C': ['to_C', 'go']}),
'C': defaultdict(<class 'list'>,
{'A': ['to_A', 'reset'],
'B': ['to_B'],
'C': ['to_C']})}) Pandas [2]
Option B: Iterate over
|
Many thanks for the comprehensive answer |
Is it possible to fetch a state transition table in a matrix format? I was unable to find anything regarding this.
The text was updated successfully, but these errors were encountered: