-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrealsyn.py
executable file
·62 lines (53 loc) · 2.89 KB
/
realsyn.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
from util.util_z3.realsyn_z3 import *
from util.util_z3.safety_check_only import get_controller_nonincremental_z3
from util.util_yices.realsyn_yices import *
# from util.util_cvc4.realsyn_cvc4 import *
from benchmarks.benchmarks import get_benchmark, get_q_multiplier
import time
import util.cmd_opts as cmd_opts
def pretty_print_controller(K, trajectory_radius_controller_list, covered_list):
print('\n ############## Printing Controller ##############\n')
print("K (common to all trjaectories) = " + str(K))
# print(K)
print("\nSub-controllers:\n")
l = len(covered_list)
for i in range(l):
print('********* ' + str(i) + ' *********')
(trajectory, _, controller) = trajectory_radius_controller_list[i]
print('x_ref[0] = ' + str(trajectory[0]))
print('\ncontroller (control input for each time-step) = ')
steps = len(controller)
for j in range(steps):
print("Step# " + str(j) + ": " + str(controller[j]))
print('\nSubset of Theta covered by this controller = ')
cover = covered_list[i]
(cvr_flag, cvr_desc) = cover
print(('Rectangle: ' if cvr_flag else 'Polytope: ') + str(cvr_desc) )
print('************************* \n')
def run_realsyn(solver, benchmark, nonincremental):
K = None
trajectory_radius_controller_list = []
covered_list = []
num_iters = None
(initial_size, _, A, B, u_space, target, avoid_list, num_steps,u_dim, avoid_dynamic, Theta, safe_rec) = get_benchmark(benchmark)
q_multiplier = get_q_multiplier(benchmark)
if solver == 'z3':
if (benchmark in [22, 23, 24] and nonincremental):
(K, trajectory_radius_controller_list, covered_list, num_iters) = get_controller_nonincremental_z3(Theta, initial_size, A, B, u_dim, u_space, target, avoid_list, avoid_dynamic, safe_rec, num_steps, q_multiplier)
else:
(K, trajectory_radius_controller_list, covered_list, num_iters) = get_controller_z3(Theta, initial_size, A, B, u_dim, u_space, target, avoid_list, avoid_dynamic, safe_rec, num_steps, q_multiplier)
elif solver == 'yices':
(K, trajectory_radius_controller_list, covered_list, num_iters) = get_controller_yices(Theta, initial_size, A, B, u_dim, u_space, target, avoid_list, avoid_dynamic, safe_rec, num_steps, q_multiplier)
elif solver == 'cvc4':
(K, trajectory_radius_controller_list, covered_list, num_iters) = get_controller_cvc4(Theta, initial_size, A, B, u_dim, u_space, target, avoid_list, avoid_dynamic, safe_rec, num_steps, q_multiplier)
return (K, trajectory_radius_controller_list, covered_list, num_iters)
def main():
(solver, benchmark, printcontroller, nonincremental) = cmd_opts.get_cmd_opts()
t0 = time.time()
(K, trajectory_radius_controller_list, covered_list, num_iters) = run_realsyn(solver, benchmark, nonincremental)
if printcontroller:
pretty_print_controller(K, trajectory_radius_controller_list, covered_list)
t1 = time.time()
print("Time for benchmark #" + str(benchmark) + " is " + str(t1 - t0) + " seconds\n")
if __name__ == "__main__":
main()