summaryrefslogtreecommitdiff
path: root/lib/automata.py
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-02-21 16:58:12 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-02-21 16:58:12 +0100
commitcf48fc7cc6b49cf2231aeb9254808f129e0ba7b3 (patch)
tree5732d8382d0494cf49c5913c7a064b6a352084f9 /lib/automata.py
parent6357bd51859bb29629d360309b2b4134b6ae766d (diff)
add support for accepting states
Diffstat (limited to 'lib/automata.py')
-rwxr-xr-xlib/automata.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/automata.py b/lib/automata.py
index f9c8ad6..379b4dc 100755
--- a/lib/automata.py
+++ b/lib/automata.py
@@ -257,6 +257,7 @@ class PTA:
"""
def __init__(self, state_names: list = [],
+ accepting_states: list = None,
parameters: list = [], initial_param_values: list = None):
"""
Return a new PTA object.
@@ -264,10 +265,12 @@ class PTA:
arguments:
state_names -- names of PTA states. Note that the PTA always contains
an initial UNINITIALIZED state, regardless of the content of state_names.
+ accepting_states -- names of accepting states. By default, all states are accepting
parameters -- names of PTA parameters
initial_param_values -- initial value for each parameter
"""
self.state = dict([[state_name, State(state_name)] for state_name in state_names])
+ self.accepting_states = accepting_states.copy() if accepting_states else None
self.parameters = parameters.copy()
if initial_param_values:
self.initial_param_values = initial_param_values.copy()
@@ -415,7 +418,11 @@ class PTA:
depth -- search depth
orig_state -- initial state for depth-first search
"""
- return self.state[orig_state].dfs(depth, **kwargs)
+ if self.accepting_states:
+ return filter(lambda x: x[-1][0].destination.name in self.accepting_states,
+ self.state[orig_state].dfs(depth, **kwargs))
+ else:
+ return self.state[orig_state].dfs(depth, **kwargs)
def simulate(self, trace: list, orig_state: str = 'UNINITIALIZED'):
total_duration = 0.