mirror of
https://git.cs.ou.nl/joshua.moerman/mealy-decompose.git
synced 2025-04-30 02:07:44 +02:00
More flags and optimisation
This commit is contained in:
parent
f53dceb6fb
commit
68a800829c
1 changed files with 53 additions and 18 deletions
|
@ -12,6 +12,8 @@ import argparse
|
|||
parser = argparse.ArgumentParser(description="Decomposes a FSM into smaller components by remapping its outputs. Uses a SAT solver.")
|
||||
parser.add_argument('-c', '--components', type=int, default=2, help='number of components')
|
||||
parser.add_argument('-n', '--total-size', type=int, help='total number of states of the components')
|
||||
parser.add_argument('--add-state-trans', default=False, action="store_true", help='adds state transitivity constraints')
|
||||
parser.add_argument('-v', '--verbose', default=False, action="store_true", help='prints more info')
|
||||
parser.add_argument('filename', help='path to .dot file')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -82,6 +84,7 @@ def parse_dot_file(lines):
|
|||
|
||||
with open(args.filename) as file:
|
||||
machine = parse_dot_file(file)
|
||||
if args.verbose:
|
||||
print(machine)
|
||||
|
||||
|
||||
|
@ -90,7 +93,7 @@ with open(args.filename) as file:
|
|||
|
||||
def print_table(cell, rs, cs):
|
||||
first_col_size = max([len(str(r)) for r in rs])
|
||||
col_size = 1 + max([len(str(c)) for c in cs])
|
||||
col_size = 1 + max([len(str(c)) for c in cs] + [len(cell(r, c)) for c in cs for r in rs])
|
||||
|
||||
print(''.rjust(first_col_size), end='')
|
||||
for c in cs:
|
||||
|
@ -154,8 +157,9 @@ for rid in rids:
|
|||
# als xo R yo en yo R zo dan xo R zo
|
||||
cnf.append([-var_rel(rid, xo, yo), -var_rel(rid, yo, zo), var_rel(rid, xo, zo)])
|
||||
|
||||
print('- transitivity (s)')
|
||||
for rid in rids:
|
||||
if args.add_state_trans:
|
||||
print('- transitivity (s)')
|
||||
for rid in rids:
|
||||
for sx in machine.states:
|
||||
for sy in machine.states:
|
||||
for sz in machine.states:
|
||||
|
@ -233,6 +237,7 @@ with Solver(bootstrap_with=cnf) as solver:
|
|||
if l < 0: model[-l] = False
|
||||
else: model[l] = True
|
||||
|
||||
if args.verbose:
|
||||
for rid in rids:
|
||||
print(f'Relation {rid}:')
|
||||
print_eqrel(lambda x, y: model[var_rel(rid, x, y)], os)
|
||||
|
@ -244,12 +249,42 @@ with Solver(bootstrap_with=cnf) as solver:
|
|||
# print equivalence classes
|
||||
count = 0
|
||||
for rid in rids:
|
||||
if args.verbose:
|
||||
print(f'component {rid}')
|
||||
# Eerst verzamelen we de representanten
|
||||
for s in machine.states:
|
||||
if model[var_state_rep(rid, s)]:
|
||||
count += 1
|
||||
if args.verbose:
|
||||
print(f'- representative state {s}')
|
||||
|
||||
# count moet gelijk zijn aan cost (of kleiner)
|
||||
print(f'total size = {count}')
|
||||
|
||||
projections = {}
|
||||
for rid in rids:
|
||||
local_outputs = machine.outputs.copy()
|
||||
projections[rid] = {}
|
||||
count = 0
|
||||
|
||||
while local_outputs:
|
||||
repr = local_outputs.pop()
|
||||
if repr in projections[rid]:
|
||||
continue
|
||||
|
||||
projections[rid][repr] = f'cls_{rid}_{count}'
|
||||
others = False
|
||||
|
||||
for o in local_outputs:
|
||||
if model[var_rel(rid, o, repr)]:
|
||||
others = True
|
||||
projections[rid][o] = f'cls_{rid}_{count}'
|
||||
|
||||
if not others:
|
||||
projections[rid][repr] = f'{repr}'
|
||||
|
||||
count += 1
|
||||
|
||||
# count moet gelijk zijn aan cost
|
||||
print(f'total size = {count}')
|
||||
print('===============')
|
||||
print('Output mapping:')
|
||||
print_table(lambda o, rid: projections[rid][o], machine.outputs, rids)
|
||||
|
|
Loading…
Add table
Reference in a new issue