mirror of
https://git.cs.ou.nl/joshua.moerman/mealy-decompose.git
synced 2025-04-30 02:07:44 +02:00
installed a linter and formatter for python
This commit is contained in:
parent
cf63613836
commit
353d191c0c
1 changed files with 19 additions and 17 deletions
|
@ -1,7 +1,6 @@
|
|||
from pysat.solvers import Solver
|
||||
from pysat.card import ITotalizer
|
||||
from pysat.formula import IDPool
|
||||
from pysat.formula import CNF
|
||||
|
||||
import signal
|
||||
import math
|
||||
|
@ -13,14 +12,15 @@ import argparse
|
|||
|
||||
keep_log = True
|
||||
|
||||
|
||||
def main():
|
||||
record_file = './results/log.txt' if keep_log else None
|
||||
|
||||
parser = argparse.ArgumentParser(description="Decomposes a FSM into smaller components by remapping its outputs. Uses a SAT solver.")
|
||||
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('-w', '--weak', default=False, action="store_true", help='look for weak decomposition')
|
||||
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('-w', '--weak', default=False, action='store_true', help='look for weak decomposition')
|
||||
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('-t', '--timeout', type=int, default=None, help='timeout (in seconds)')
|
||||
parser.add_argument('filename', help='path to .dot file')
|
||||
args = parser.parse_args()
|
||||
|
@ -36,7 +36,8 @@ def main():
|
|||
|
||||
print(f'Input FSM: {len(machine.states)} states, {len(machine.inputs)} inputs, and {len(machine.outputs)} outputs')
|
||||
|
||||
if args.timeout != None:
|
||||
if args.timeout:
|
||||
|
||||
def timeout_handler(*_):
|
||||
with open(record_file, 'a') as file:
|
||||
last_two_comps = '/'.join(args.filename.split('/')[-2:])
|
||||
|
@ -71,6 +72,7 @@ class FSM:
|
|||
def output(self, s, a):
|
||||
return self.output_map[(s, a)]
|
||||
|
||||
|
||||
def parse_dot_file(lines):
|
||||
def parse_transition(line):
|
||||
(l, _, r) = line.partition('->')
|
||||
|
@ -126,6 +128,7 @@ def print_table(cell, rs, cs):
|
|||
print(cell(r, c).rjust(col_size), end='')
|
||||
print('')
|
||||
|
||||
|
||||
def print_eqrel(rel, xs):
|
||||
print_table(lambda r, c: 'Y' if rel(r, c) else '·', xs, xs)
|
||||
|
||||
|
@ -179,7 +182,7 @@ class Encoder:
|
|||
|
||||
# Een hulp variabele voor False en True, maakt de andere variabelen eenvoudiger
|
||||
def var_const(self, b):
|
||||
return(self.vpool.id(('const', b)))
|
||||
return self.vpool.id(('const', b))
|
||||
|
||||
# Voor elke relatie en elke twee elementen o1 en o2, is er een variabele die
|
||||
# aangeeft of o1 en o2 gerelateerd zijn. Er is 1 variabele voor xRy en yRx, dus
|
||||
|
@ -334,8 +337,7 @@ class Encoder:
|
|||
m = self.solver.get_model()
|
||||
model = {}
|
||||
for l in m:
|
||||
if l < 0: model[-l] = False
|
||||
else: model[l] = True
|
||||
model[abs(l)] = l > 0
|
||||
|
||||
if self.args.verbose:
|
||||
for rid in self.rids:
|
||||
|
@ -359,7 +361,7 @@ class Encoder:
|
|||
counts.append(count)
|
||||
|
||||
print(f'Reduced sizes = {counts} = {sum(counts)}')
|
||||
if self.record_file != None:
|
||||
if self.record_file:
|
||||
with open(self.record_file, 'a') as file:
|
||||
last_two_comps = '/'.join(self.args.filename.split('/')[-2:])
|
||||
file.write(f'{last_two_comps}\t{self.N}\t{len(self.machine.inputs)}\t{len(self.machine.outputs)}\t{self.args.weak}\t{self.c}\t{sum(counts)}\t{sorted(counts, reverse=True)}\n')
|
||||
|
@ -396,5 +398,5 @@ class Encoder:
|
|||
|
||||
###################################
|
||||
# Run script
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Reference in a new issue