Skip to content

Commit 7945a1c

Browse files
author
Edi Muskardin
committed
Merge remote-tracking branch 'origin/master'
2 parents 71a3c0e + cb7c8ff commit 7945a1c

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

aalpy/learning_algs/general_passive/GsmNode.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,20 @@ def node_naming(node: GsmNode):
375375
file_ext = 'dot'
376376
graph.write(path=str(path) + "." + file_ext, prog=engine, format=format)
377377

378+
def make_input_complete(self) -> List[Tuple['GsmNode', Any, Any]]:
379+
all_nodes = self.get_all_nodes()
380+
inputs = {in_sym for node in all_nodes for in_sym in node.transitions}
381+
missing_trans = []
382+
for node in all_nodes:
383+
for in_sym in inputs:
384+
transitions = node.transitions[in_sym]
385+
if len(transitions) == 0:
386+
out_sym = node.prefix_access_pair[1]
387+
missing_trans.append((node, in_sym, out_sym))
388+
t_info = TransitionInfo(node, 1, None, None)
389+
transitions[out_sym] = t_info
390+
return missing_trans
391+
378392
def add_trace(self, trace: IOTrace):
379393
curr_node: GsmNode = self
380394
for in_sym, out_sym in trace:

aalpy/learning_algs/general_passive/Instrumentation.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def __init__(self, lvl):
1919
self.nr_merged_states = 0
2020
self.nr_red_states = 0
2121

22+
self.stats = dict()
23+
2224
self.previous_time = None
2325

2426
def reset(self, gsm: GeneralizedStateMerging):
@@ -29,23 +31,27 @@ def reset(self, gsm: GeneralizedStateMerging):
2931
self.nr_merged_states = 0
3032
self.nr_red_states = 0
3133

34+
self.stats = dict()
3235
self.previous_time = perf_counter()
3336

3437
def pta_construction_done(self, root):
35-
print(f'PTA Construction Time: {round(perf_counter() - self.previous_time, 2)} s')
36-
if 1 < self.lvl:
38+
pta_const_time = perf_counter() - self.previous_time
39+
self.stats["pta creation time"] = pta_const_time
40+
print(f'PTA Construction Time: {round(pta_const_time, 2)} s')
41+
if 0 < self.lvl:
3742
states = root.get_all_nodes()
3843
leafs = [state for state in states if len(state.transitions.keys()) == 0]
3944
depth = [state.get_prefix_length() for state in leafs]
4045
self.pta_size = len(states)
41-
print(f'PTA has {len(states)} states leading to {len(leafs)} leafs')
42-
print(f'min / avg / max depth : {min(depth)} / {sum(depth) / len(depth)} / {max(depth)}')
46+
if 1 < self.lvl:
47+
print(f'PTA has {len(states)} states leading to {len(leafs)} leafs')
48+
print(f'min / avg / max depth : {min(depth)} / {sum(depth) / len(depth)} / {max(depth)}')
4349
self.previous_time = perf_counter()
4450

4551
def print_status(self):
4652
reset_char = "\33[2K\r"
4753
print_str = reset_char + f'Current automaton size: {self.nr_red_states}'
48-
if 1 < self.lvl and not self.gsm.compatibility_on_futures:
54+
if 0 < self.lvl and not self.gsm.compatibility_on_futures:
4955
print_str += f' Merged: {self.nr_merged_states_total} Remaining: {self.pta_size - self.nr_red_states - self.nr_merged_states_total}'
5056
print(print_str, end="")
5157

@@ -61,7 +67,10 @@ def log_merge(self, part: Partitioning):
6167
self.print_status()
6268

6369
def learning_done(self, root: GsmNode):
64-
print(f'\nLearning Time: {round(perf_counter() - self.previous_time, 2)} s')
70+
learning_time = perf_counter() - self.previous_time
71+
self.stats["learning time"] = learning_time
72+
self.stats["total time"] = learning_time + self.stats["pta creation time"]
73+
print(f'\nLearning Time: {round(learning_time, 2)} s')
6574
print(f'Learned {self.nr_red_states} state automaton via {self.nr_merged_states} merges.')
6675
if 2 < self.lvl:
6776
root.visualize("model", self.gsm.output_behavior)

0 commit comments

Comments
 (0)