From 44614e6a88a71fb09d7e5cd5e3bf866aefc1f29c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 19 Apr 2018 17:02:12 +0200 Subject: Implement PTA DFS as generator --- lib/automata.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib/automata.py') diff --git a/lib/automata.py b/lib/automata.py index be91cd4..0e6cc28 100755 --- a/lib/automata.py +++ b/lib/automata.py @@ -15,15 +15,14 @@ class State: def dfs(self, depth): if depth == 0: - return [[trans.name] for trans in self.outgoing_transitions] - - ret = [] - for trans in self.outgoing_transitions: - for suffix in trans.destination.dfs(depth - 1): - new_suffix = [trans.name] - new_suffix.extend(suffix) - ret.append(new_suffix) - return ret + for trans in self.outgoing_transitions: + yield [trans.name] + else: + for trans in self.outgoing_transitions: + for suffix in trans.destination.dfs(depth - 1): + new_suffix = [trans.name] + new_suffix.extend(suffix) + yield new_suffix class PTA: def __init__(self, state_names, parameters): -- cgit v1.2.3