-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_examples.py
170 lines (154 loc) · 8.57 KB
/
run_examples.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
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
import argparse
import os
import signal
import time
from subprocess import PIPE, Popen, TimeoutExpired
from uppaalHelpers import path_analysis, xml_to_imi
from . import tamus
if __name__ == '__main__':
parser = argparse.ArgumentParser(
"TAMUS - a tool for relaxing reachability properties in Time Automatas based on Minimal Sufficinet Reductions (MRS) and linear programming.")
parser.add_argument("--task", choices=["msr", "mmsr", "mg", "mmg", "amsr", "amg", "amsramg"],
help="Choose the computation taks: msr - an MSR, mmsr - a minimum MSR, mg - an MG, mmg - a minimum MG, amsr - all MSRs, amg - all MGs, amsramg - all MSRs and MGs.",
default="mmsr")
parser.add_argument("--run_imitator_on_mg", action='store_true',
help="After fnding minimal guarantee, runs imitator on it. This value does not have effect if any task other than mmg is selected.")
args = parser.parse_args()
fis = [("examples/paper_benchmarks/literature_benchmarks/accel/accel_1000-uppaal_fixed_mutated.xml",
"examples/paper_benchmarks/literature_benchmarks/accel/accel_1000-uppaal.q", "pta"),
("examples/paper_benchmarks/literature_benchmarks/rcp/RCP-uppaal_fixed_mutated.xml",
"examples/paper_benchmarks/literature_benchmarks/rcp/RCP-uppaal.q", "All"),
("examples/paper_benchmarks/literature_benchmarks/jlr/JLR13-3tasks-npfp-100-2-uppaal_fixed.xml",
"examples/paper_benchmarks/literature_benchmarks/jlr/JLR13-3tasks-npfp-100-2-uppaal.q", "sched"),
("examples/paper_benchmarks/literature_benchmarks/CAS/CAS_mutated.xml",
"examples/paper_benchmarks/literature_benchmarks/CAS/cas.q", "System"),
("examples/paper_benchmarks/literature_benchmarks/coffee/coffee-uppaal_mutated.xml",
"examples/paper_benchmarks/literature_benchmarks/coffee/coffee-uppaal.q", "All"),
("examples/paper_benchmarks/literature_benchmarks/jobshop/maler_4_4-uppaal_fixed_mutated.xml",
"examples/paper_benchmarks/literature_benchmarks/jobshop/maler_4_4-uppaal.q", "All"),
("examples/paper_benchmarks/literature_benchmarks/pipeline/Pipeline-KP12-3-3-uppaal_fixed_mutated.xml",
"examples/paper_benchmarks/literature_benchmarks/pipeline/Pipeline-KP12-3-3-uppaal.q", "All"),
("examples/paper_benchmarks/literature_benchmarks/simop/simop3-uppaal_fixed_mutated.xml",
"examples/paper_benchmarks/literature_benchmarks/simop/simop3-uppaal.q", "All"),
("examples/paper_benchmarks/literature_benchmarks/fischer/fischerHRSV02-2-uppaal_fixed.xml",
"examples/paper_benchmarks/literature_benchmarks/fischer/fischerHRSV02.q", "All"),
("examples/paper_benchmarks/literature_benchmarks/wfas/WFAS-BBLS15-uppaal_fixed.xml",
"examples/paper_benchmarks/literature_benchmarks/wfas/WFAS-BBLS15-uppaal.q", "controller")]
if args.task == "mmsr":
f = open(
"examples/paper_benchmarks/literature_benchmarks_msr_results.txt", "w")
for fi in fis:
print(fi[0])
f.write("Model: ")
f.write(fi[0] + "\n")
f.write("Query: ")
f.write(fi[1] + "\n")
f.write("TA: ")
f.write(fi[2] + "\n")
args = argparse.Namespace()
args.run_imitator_on_mg = False
t = tamus.Tamus(fi[0], fi[1], fi[2], args)
t.timelimit = 1000000
t.verbosity = 0
f.write("is the target location reachable?" +
str(t.is_sufficient([])[0]) + "\n")
start_time = time.clock()
try:
t.run()
except:
f.write("excexption" + "\n")
f.write("MSR computation time: " +
str(time.clock()-start_time) + "\n")
f.write("Constraint count: " +
str(len(t.TA.constraint_registry)) + "\n")
f.write('Number of checks ' + str(t.stats['checks']) + "\n")
start_time = time.clock()
msres, constraints, traces = t.get_MSRes()
msres_size = [len(m) for m in msres]
min_size = min(msres_size)
min_msres_indexes = [i for i in range(
len(msres_size)) if msres_size[i] == min_size]
# MILP analysis for one of them.
ind = min_msres_indexes[0]
delays, parameters = path_analysis.find_parameters(
t.TA, traces[ind], msres[ind])
milp_time = time.clock() - start_time
sum_param = sum(parameters)
if not ("coffee" in fi[0] or "CAS" in fi[0]):
milp_time = "-"
sum_param = "-"
f.write("MILP computation time: " + str(milp_time) + "\n")
f.write("Optimal MILP cost: " + str(sum_param) + "\n")
f.write("Min MSR size: " + str(min_size) + "\n")
print("")
f.write("\n")
else:
f = open(
"examples/paper_benchmarks/literature_benchmarks_mg_results.txt", "w")
for fi in fis:
print(fi[0])
f.write("Model: ")
f.write(fi[0] + "\n")
f.write("Query: ")
f.write(fi[1] + "\n")
f.write("TA: ")
f.write(fi[2] + "\n")
t = tamus.Tamus(fi[0], fi[1], fi[2], args)
t.task = "mmg"
t.timelimit = 1000000
t.verbosity = 0
f.write("is the target location reachable?" +
str(t.is_sufficient([])[0]) + "\n")
start_time = time.clock()
try:
t.minimumMG(allMGs=False)
except:
f.write("excexption" + "\n")
f.write("MG computation time: " +
str(time.clock() - start_time) + "\n")
f.write("Constraint count: " +
str(len(t.TA.constraint_registry)) + "\n")
f.write('Number of checks ' + str(t.stats['checks']) + "\n")
mgs, constraints = t.get_MGs()
# Minimal mgs:
mgs_size = [len(m) for m in mgs]
min_size = min(mgs_size)
min_mgs_indexes = [i for i in range(
len(mgs_size)) if mgs_size[i] == min_size]
mg = mgs[min_mgs_indexes[0]]
f.write("Min MG size: " + str(len(mg)) + "\n")
relax_list = [c for c in t.clist]
if args.run_imitator_on_mg:
for c in mg: # create the list that will be removed from the model
relax_list.remove(c)
new_templates, parameter_count = t.TA.generate_relaxed_and_parametrized_templates(
relax_list, mg)
declaraion_of_the_system = t.model.declaration
process_template_pair_of_the_system = t.model.system
# print set(constraints[0])
imi_name, imiporp_name = xml_to_imi.create_imitator_on_mg(new_templates,
declaraion_of_the_system,
process_template_pair_of_the_system,
t.model_file,
# 1)
t.query_file,
parameter_count)
output_file = imi_name.split(".imi")[0]
command = "imitator " + imi_name + " " + imiporp_name + \
" -output-prefix " + output_file + " -verbose mute"
f.write("running " + command + "\n")
start_time = time.clock()
with Popen(command, shell=True, stdout=PIPE, preexec_fn=os.setsid) as process:
try:
output = process.communicate(timeout=30)[0]
parameter_vals, total_sum, total_time = xml_to_imi.find_maximum_parameter_values(
output_file + ".res", parameter_count)
f.write(
"Total sum for maximum parameter valuations: "+str(total_sum)+"\n")
f.write("Imitator Time: " + total_time + "\n")
except TimeoutExpired:
# send signal to the process group
os.killpg(process.pid, signal.SIGINT)
output = process.communicate()[0]
f.write("Timeout at 20 minutes\n")
f.write("\n")