-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrad.py
More file actions
197 lines (166 loc) · 5.38 KB
/
Copy pathtrad.py
File metadata and controls
197 lines (166 loc) · 5.38 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import re,sys,os
from synthNK import *
from writing import *
############### Si on veut voir plusieurs formats de sorties il faut rajouter des options à la getopt
############### IL faut faire un fichier séparé
#TODO
#ce n'est psa du python il va falloir le mettre en vrai python pour que ça marche quelque soit la machine qui appelle ce code
#os.system("rm -rf Conf*")
#os.system("rm RBTfile*")
#os.system("rm newxml*")
def isThereAStrategy(stratFileName):
myboolean = False
with open(stratFileName,'r')as stratFile:
for line in stratFile:
if "Property is satisfied" in line:
return True
return myboolean
def getconf(config):
conf = []
for gp in config.groups():
conf.append(gp)
return conf
def getFirst(n,k,stratFileName,filename):
"""write the strategy stratFileName as a dve model for k robots in a n node ring"""
maLigne = 0
nbConfig = 0
config = ""
for i in range(k):
newString = "conf\[{0}\]=(\d+) ".format(i)
config += newString
nobodyMove = noMoves(k)
stratPy = []
with open(stratFileName, 'r') as file:
for line in file :
if line.startswith("State: ( Process.Player )") :
maLigne = 1
nbConfig += 1
#print("config numero = {0} \n à la ligne {1}".format(nbConfig, line))
#remplissage de la conf avec maConfig.group
conf = getconf(re.search(config,line))
elif maLigne == 1 : #On ne veut récupérer que la première règle
#print("CCCCConfig{0}".format(nbConfig))
if re.search("Process.goal",line) is None:
strat = int(re.search("get_confuse_strat\((\d+)\)",line).group(1))
add_rules(nbConfig, strat, conf,n,k, filename)#fais tout le boulot
stratPy.append((conf, strat))
else:#goal reached -> nobody move
add_rules(nbConfig,noMoves(k),conf,n,k,filename)#idle pour tout le monde
maLigne = 2
return stratPy
#print("blaaaaaaaaaaaa")
def traduction(n,k,filename):
"""fais la traduction de la strategie contenue dans filename et l'écrit dans le fichier filen_k.dve"""
if not isThereAStrategy(filename):
return (False, ())
config = ""
for i in range(k):
newString = "conf\[{0}\]=(\d+) ".format(i)
config += newString
dveFileString = "strat.dve"
dveFile = open(dveFileString, "w")
dveFile.write("byte n = {0};\n".format(n))
dveFile.write("byte k = {0};\n".format(k))
tabString = "byte pos[{0}] = ".format(k) + "{"
for i in range(k-1):
tabString += "0,"
tabString+= "0};\n"
dveFile.write(tabString)
tabString = "byte conf[{0}] = ".format(n) +"{"
for i in range(n-1):
tabString += "0,"
tabString+= "0};\n"
dveFile.write(tabString)
dveFile.write("byte initialized = -1;\n\n")
dveFile.write("""process P_Initializer{
state start, end;
init start;
trans""")
#1 first read of the stretgies file
# we obtain all possible initial configurations -> we obtain the initializerProcess transitions
step = 1
previousConf=False
nbConfig =0
confListe=[]
with open(filename,'r')as stratFile:
for line in stratFile:
if line.startswith("State: ( Process.Player ) "):
step = 1
nbConfig+=1
#remplissage de la conf avec maConfig.group
conf = getconf(re.search(config,line))
#for elem in conf:
# pprint(elem)
# elem = int(elem)
#print("bouh")
maConf = conf_to_confpos(conf,n,k)
#print(maConf)
if previousConf:
dveFile.write(",\n")
dveFile.write("""
start -> end{effect """)
for pos in range(n):
#print(type(pos))
#print(type(str(pos)))
str = "conf[{0}]={1}, ".format(pos, maConf[pos])
#print(str)
dveFile.write(str)
tabPos= [0]*k
tabPos = getPos(maConf,n,k)
str = ""
for i in range(k):
str = "pos[{0}]={1}, ".format(i,tabPos[i])
dveFile.write(str)
dveFile.write("""initialized = 0;}""")
previousConf=True
confListe.append(conf)#) quelle indentation
# else:
# print(line)
#2 on recupère les configurations qui n'ont pas été vues interressant que lorsque dans uppall on a enlevé des configuration avec k = 4 ça n'arrive que si le nombre n paircomme on s'interrresse à SP4 pas besoin
nb = 0
RbtDveFile = "RbtFile.dve"
os.system("rm RbtFile.dve")
#print("la synthese renvoit {0} configurations différentes".format(Liste)))
#noMouvFile = open("noMouvRbtFile.dve","w")
"""print("les conf initiales sont :")
for c in confListe:
print(c)
print("\n\net donc il n'ya pas les confs .....")
for c in notHere(confListe,n,k):
print(c)"""
for anyConfig in notHere(confListe,n,k):
nb += 1
add_rule0(len(confListe)+nb,anyConfig,n,k,RbtDveFile)
#print(nb)
#get the first strategy
stratPy = getFirst(n,k,filename,RbtDveFile);
for i in range(k):
rbtString = """;
}
process P_Rbt"""
rbtString += "{0}".format(i)
rbtString += "{\n"
#print(rbtString)
dveFile.write(rbtString)
dveFile.write("\tbyte num={0};\n".format(i))
dveFile.write(""" state wait, RLC, Front, Back, Idle;
init wait;
trans
wait -> RLC{guard initialized == 0;},
Idle -> RLC{},
Front -> RLC{effect conf[pos[num]]=conf[pos[num]]-1,
conf[(pos[num]+1)%n]=conf[(pos[num]+1)%n]+1,
pos[num]=(pos[num]+1)%n;},
Back -> RLC{effect conf[pos[num]]=conf[pos[num]]-1,
conf[(pos[num]+n-1)%n]=conf[(pos[num]+n-1)%n]+1,
pos[num]=(pos[num]+n-1)%n;}""")
#recupere les configurations pour mettre les positions des robots
with open(RbtDveFile,'r')as rbtFile:
for line in rbtFile:
dveFile.write(line)
#os.remove(RbtDveFile)
dveFile.write(""";
}
system async;""")
dveFile.close()
return (True, stratPy)