-
Notifications
You must be signed in to change notification settings - Fork 1
/
sepAutSetGen.py
44 lines (33 loc) · 1.18 KB
/
sepAutSetGen.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
import sys
import os
import json
import shutil
import pydot
from ltlf2dfa.parser.ltlf import LTLfParser
from ltlf2dfa.parser.pltlf import PLTLfParser
def main():
''' create a directory called automata
if such directory already exists,
delete it and its content and create it again '''
if(os.path.exists('automata')):
shutil.rmtree('automata')
os.mkdir('automata')
''' read the json file containing the matrix representation
of the SNF of the formula and for each row of the matrix create a directory '''
with open('matrix.json') as f:
matrix = json.load(f)
for i in range(len(matrix)):
os.mkdir('automata/{!s}'.format(i+1))
save_dfa(matrix[i][0], i+1, 'past')
save_dfa(matrix[i][1], i+1, 'present')
save_dfa(matrix[i][2], i+1, 'future')
def save_dfa(phi, row, time):
if(time == 'past'): parser = PLTLfParser()
else: parser = LTLfParser()
formula = parser(phi)
dfa = formula.to_dfa()
graphs = pydot.graph_from_dot_data(dfa)
graph = graphs[0]
graph.write_png('automata/{!s}/{}.png'.format(row, time))
if __name__ == "__main__":
main()