-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
88 lines (67 loc) · 2.44 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from src import automate
import argparse
import pandas as pd
# Create the parser
parser = argparse.ArgumentParser(description="A program that converts a given statemachine to a semigroup")
# Add arguments
parser.add_argument(
"-d", "--dot",
type=str,
help = "Specyfing this flag will generate a .dot file of the automata, pelase specify a filename",
required=False # Makes this argument mandatory
)
parser.add_argument(
"-n", "--no-print-semig",
action="store_true",
help = "Specyfing this flag will prevent the program from printing the semigroup",
required=False
)
parser.add_argument(
"-t", "--table",
action="store_false",
help = "Specyfing this flag will prevent the program from printing the table",
required=False
)
parser.add_argument(
"-a", "--aut",
type=str,
help = "Path to the an automate file (a comma seperated file with states, transitions and final states)",
required=False # Makes this argument mandatory
)
parser.add_argument(
"-N",
type=int,
help = "The length on the longest workd-1 that will be simulated",
default = 3,
required=False # Makes this argument mandatory
)
# Parse the arguments
args = parser.parse_args()
if __name__ == "__main__":
automaton = {}
if args.aut:
print(f'Loading automaton from {args.aut}')
df = pd.read_csv(args.aut, header = None)
automaton = {(row[0], row[1]) : row[2] for row in df.values }
else:
print(f'Loading automaton from examples/lecture_1.csv')
df = pd.read_csv("examples/lecture_1.csv", header = None)
automaton = {(row[0], row[1]) : row[2] for row in df.values }
# TODDO Fix hardcoded alphabet
eqv_classes = automate.create_table(automaton, automate.get_alphabet(automaton), N = args.N)
if args.table:
print(f'Printing eqv. classes')
print(eqv_classes)
eqv_with_rep = automate.add_representatives(automaton, eqv_classes)
print(eqv_with_rep[1])
print("\n\n\n")
print("Are are eqv. of length n duplicate?\nIf one of the last columns entries are true your specied work length is long enough.")
print(eqv_with_rep[2])
print("\n\n\n")
if args.dot:
automate.plot(automaton, args.dot)
if not args.no_print_semig:
print(f'Printing semigroup')
u, class_, _ = automate.add_representatives(automaton, eqv_classes)
r = automate.eqv_class_to_semigroup(automaton,automate.get_alphabet(automaton), u)
print(automate.format_semitable(r))