Skip to content

Commit f433d91

Browse files
committed
add submission and fix bug about realpaver
1 parent 26f5f2d commit f433d91

17 files changed

Lines changed: 514 additions & 75 deletions
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import numpy as np
2+
3+
from pybdr.algorithm import ASB2008CDC,ASB2008CDCParallel
4+
from pybdr.util.functional import performance_counter, performance_counter_start
5+
from pybdr.geometry import Zonotope, Interval, Geometry
6+
from pybdr.geometry.operation import boundary
7+
from pybdr.model import *
8+
from pybdr.util.visualization import plot
9+
from save_results import save_result
10+
from pybdr.geometry.operation.convert import cvt2
11+
12+
if __name__ == '__main__':
13+
# settings for the computation
14+
options = ASB2008CDCParallel.Options()
15+
options.t_end = 5.0
16+
options.step = 0.01
17+
options.tensor_order = 3
18+
options.taylor_terms = 4
19+
options.u = Zonotope.zero(1, 1)
20+
options.u_trans = np.zeros(1)
21+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
22+
Zonotope.ORDER = 50
23+
24+
Z = Interval([-0.1, 3.9], [0.1, 4.1])
25+
cell_nums = {12: 0.05, 16: 0.06, 20: 0.045}
26+
# Reachable sets computed with boundary analysis
27+
options.r0 = boundary(Z, cell_nums[20], Geometry.TYPE.ZONOTOPE)
28+
# Reachable sets computed without boundary analysis
29+
# options.r0 = [cvt2(Z, Geometry.TYPE.ZONOTOPE)]
30+
print("The number of divided sets: ", len(options.r0))
31+
32+
33+
time_tag = performance_counter_start()
34+
ri, rp = ASB2008CDCParallel.reach_parallel(brusselator, [2, 1], options, options.r0)
35+
performance_counter(time_tag, "ASB2008CDCParallel")
36+
37+
# save the results
38+
save_result(ri, "brusselator_" + str(len(options.r0)))
39+
40+
# visualize the results
41+
# plot(ri, [0, 1])

example/submission/lorentz_test.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import numpy as np
2+
from pybdr.algorithm import ASB2008CDC,ASB2008CDCParallel
3+
from pybdr.util.functional import performance_counter, performance_counter_start
4+
from pybdr.geometry import Zonotope, Interval, Geometry
5+
from pybdr.geometry.operation import boundary
6+
from pybdr.model import *
7+
from pybdr.util.visualization import plot
8+
from save_results import save_result
9+
from pybdr.geometry.operation.convert import cvt2
10+
11+
if __name__ == '__main__':
12+
13+
options = ASB2008CDCParallel.Options()
14+
options.t_end = 1.0
15+
options.step = 0.02
16+
options.tensor_order = 3
17+
options.taylor_terms = 4
18+
options.u = Zonotope.zero(1, 1)
19+
options.u_trans = np.zeros(1)
20+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
21+
Zonotope.ORDER = 50
22+
23+
Z = Interval([-11, -3, -3], [3, 11, 11])
24+
cell_nums = {216: 2.5, 294: 2.3, 384: 2}
25+
# Reachable sets computed with boundary analysis
26+
options.r0 = boundary(Z, cell_nums[384], Geometry.TYPE.ZONOTOPE)
27+
# Reachable sets computed without boundary analysis
28+
# options.r0 = [cvt2(Z, Geometry.TYPE.ZONOTOPE)]
29+
print("The number of divided sets: ", len(options.r0))
30+
31+
time_tag = performance_counter_start()
32+
ri, rp = ASB2008CDCParallel.reach_parallel(lorentz, [3, 1], options, options.r0)
33+
performance_counter(time_tag, "ASB2008CDCParallel")
34+
35+
# save the results
36+
save_result(ri, "lorentz_" + str(len(options.r0)))
37+
38+
# visualize the results
39+
plot(ri, [0, 1])
40+
plot(ri, [1, 2])

example/submission/plot_results.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import numpy as np
2+
from pybdr.geometry import Zonotope, Interval, Geometry
3+
from pybdr.util.visualization import plot
4+
5+
name = 'synchronous_16_20240116_154622'
6+
with open('.\\results\\' + name + '.txt', 'r') as file:
7+
lines = file.readlines()
8+
9+
all_results = []
10+
zono = []
11+
current_zono = []
12+
13+
for line in lines:
14+
if line.startswith('Result:'):
15+
if zono:
16+
all_results.append(zono)
17+
zono = []
18+
else:
19+
if line.strip():
20+
current_zono.append([float(x) for x in line.split()])
21+
dim = 0
22+
if current_zono:
23+
dim = len(current_zono[0])
24+
if len(current_zono) == dim + 1:
25+
gen = []
26+
for di in range(1, dim+1):
27+
gen.append(current_zono[di])
28+
z = Zonotope(current_zono[0], np.array(gen))
29+
current_zono = []
30+
zono.append(z)
31+
all_results.append(zono)
32+
# all_results = [list(group) for group in zip(*all_results)]
33+
34+
print("Start drawing")
35+
plot(all_results, [0, 1])

example/submission/save_results.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import numpy as np
2+
from datetime import datetime
3+
4+
def save_result(R_list, name):
5+
currentDateTime = datetime.now().strftime('%Y%m%d_%H%M%S')
6+
7+
fileName = f'./results/{name}_{currentDateTime}.txt'
8+
9+
with open(fileName, 'w') as fileID:
10+
fileID.write('Result:\n')
11+
12+
for ri_index in range(len(R_list)):
13+
ri = R_list[ri_index]
14+
15+
for zi in ri:
16+
dim = len(zi.c)
17+
for di in range(dim):
18+
fileID.write(f'{zi.c[di]} ')
19+
fileID.write('\n')
20+
21+
for di in range(dim):
22+
for j in range(len(zi.gen[0])):
23+
fileID.write(f'{zi.gen[di][j]} ')
24+
fileID.write('\n')
25+
fileID.write('\n')
26+
27+
if ri_index != len(R_list) - 1:
28+
fileID.write('Result:\n')

example/submission/spiral1_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import numpy as np
2+
np.seterr(divide='ignore', invalid='ignore')
3+
# sys.path.append("./../../") uncomment this line if you need to add path manually
4+
from pybdr.algorithm import ASB2008CDC,ASB2008CDCParallel
5+
from pybdr.geometry import Zonotope, Interval, Geometry
6+
from pybdr.model import *
7+
from pybdr.util.visualization import plot
8+
from pybdr.geometry.operation import boundary
9+
from pybdr.util.functional import performance_counter, performance_counter_start
10+
from pybdr.geometry.operation.convert import cvt2
11+
from save_results import save_result
12+
13+
if __name__ == '__main__':
14+
# settings for the computation
15+
options = ASB2008CDCParallel.Options()
16+
options.t_end = 7
17+
options.step = 0.1
18+
options.tensor_order = 3
19+
options.taylor_terms = 4
20+
options.u = Zonotope.zero(1, 1)
21+
options.u_trans = np.zeros(1)
22+
# settings for the using geometry
23+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
24+
Zonotope.ORDER = 50
25+
26+
Z = Interval([0.0, -2.0], [4.0, 2.0])
27+
cell_nums = {16: 1.1, 20: 1.0, 24: 0.7, 28: 0.6, 32: 0.55}
28+
# Reachable sets computed with boundary analysis
29+
options.r0 = boundary(Z, cell_nums[20], Geometry.TYPE.ZONOTOPE)
30+
# Reachable sets computed without boundary analysis
31+
# options.r0 = [cvt2(Z, Geometry.TYPE.ZONOTOPE)]
32+
print("The number of Cells number: ", len(options.r0))
33+
34+
# reachable sets computation
35+
time_tag = performance_counter_start()
36+
ri, rp = ASB2008CDCParallel.reach_parallel(spiral1, [2,1], options, options.r0)
37+
performance_counter(time_tag, "ASB2008CDCParallel")
38+
39+
# save the results
40+
save_result(ri, "spiral1_"+str(len(options.r0)))
41+
42+
# visualize the results
43+
plot(rp, [0, 1])

example/submission/spiral2_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import numpy as np
2+
np.seterr(divide='ignore', invalid='ignore')
3+
# sys.path.append("./../../") uncomment this line if you need to add path manually
4+
from pybdr.algorithm import ASB2008CDC,ASB2008CDCParallel
5+
from pybdr.geometry import Zonotope, Interval, Geometry
6+
from pybdr.model import *
7+
from pybdr.util.visualization import plot
8+
from pybdr.geometry.operation import boundary
9+
from pybdr.util.functional import performance_counter, performance_counter_start
10+
from pybdr.geometry.operation.convert import cvt2
11+
from save_results import save_result
12+
13+
if __name__ == '__main__':
14+
# settings for the computation
15+
options = ASB2008CDCParallel.Options()
16+
options.t_end = 7.0
17+
options.step = 0.1
18+
options.tensor_order = 3
19+
options.taylor_terms = 4
20+
options.u = Zonotope.zero(1, 1)
21+
options.u_trans = np.zeros(1)
22+
# settings for the using geometry
23+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
24+
Zonotope.ORDER = 50
25+
26+
Z = Interval([-4.0, -4.0], [-2.0, -2.0])
27+
cell_nums = {16: 1.1, 20: 1.0, 24: 0.7, 28: 0.65, 32: 0.52}
28+
# Reachable sets computed with boundary analysis
29+
options.r0 = boundary(Z, cell_nums[32], Geometry.TYPE.ZONOTOPE)
30+
# Reachable sets computed without boundary analysis
31+
# options.r0 = [cvt2(Z, Geometry.TYPE.ZONOTOPE)]
32+
print("The number of divided sets: ", len(options.r0))
33+
34+
# reachable sets computation
35+
time_tag = performance_counter_start()
36+
ri, rp = ASB2008CDCParallel.reach_parallel(spiral2, [2,1], options, options.r0)
37+
performance_counter(time_tag, "ASB2008CDCParallel")
38+
39+
# save the results
40+
save_result(ri, "spiral2_"+str(len(options.r0)))
41+
42+
# visualize the results
43+
plot(ri, [0, 1])
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import numpy as np
2+
from pybdr.algorithm import ASB2008CDC,ASB2008CDCParallel
3+
from pybdr.util.functional import performance_counter, performance_counter_start
4+
from pybdr.geometry import Zonotope, Interval, Geometry
5+
from pybdr.geometry.operation import boundary
6+
from pybdr.model import *
7+
from pybdr.util.visualization import plot
8+
from pybdr.geometry.operation.convert import cvt2
9+
from save_results import save_result
10+
11+
if __name__ == '__main__':
12+
13+
options = ASB2008CDCParallel.Options()
14+
options.t_end = 7.0
15+
options.step = 0.01
16+
options.tensor_order = 3
17+
options.taylor_terms = 4
18+
options.u = Zonotope.zero(1, 1)
19+
options.u_trans = np.zeros(1)
20+
# settings for the using geometry
21+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
22+
Zonotope.ORDER = 50
23+
24+
Z = Interval([-0.7, 2.3], [0.7, 3.7])
25+
cell_nums = {12: 0.5, 16: 0.4, 20: 0.3, 24: 0.25}
26+
# Reachable sets computed with boundary analysis
27+
options.r0 = boundary(Z, cell_nums[24], Geometry.TYPE.ZONOTOPE)
28+
# Reachable sets computed without boundary analysis
29+
# options.r0 = [cvt2(Z, Geometry.TYPE.ZONOTOPE)]
30+
print("The number of divided sets: ", len(options.r0))
31+
32+
time_tag = performance_counter_start()
33+
ri, rp = ASB2008CDCParallel.reach_parallel(synchronous_machine, [2, 1], options, options.r0)
34+
performance_counter(time_tag, "ASB2008CDCParallel")
35+
36+
# save the results
37+
save_result(ri, "synchronous_" + str(len(options.r0)))
38+
39+
# visualize the results
40+
plot(ri, [0, 1])
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import numpy as np
2+
from pybdr.algorithm import ASB2008CDC,ASB2008CDCParallel
3+
from pybdr.util.functional import performance_counter, performance_counter_start
4+
from pybdr.dynamic_system import NonLinSys
5+
from pybdr.geometry import Zonotope, Interval, Geometry
6+
from pybdr.geometry.operation import boundary
7+
from pybdr.model import *
8+
from pybdr.util.visualization import plot
9+
from save_results import save_result
10+
from pybdr.geometry.operation.convert import cvt2
11+
12+
if __name__ == '__main__':
13+
# settings for the computation
14+
options = ASB2008CDCParallel.Options()
15+
options.step = 0.01
16+
options.tensor_order = 3
17+
options.taylor_terms = 4
18+
options.u = Zonotope.zero(1, 1)
19+
options.u_trans = np.zeros(1)
20+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
21+
Zonotope.ORDER = 50
22+
23+
options.t_end = 5.0
24+
# options.t_end = 7.0
25+
# options.t_end = 9.0
26+
# Z = Interval([1.0, 2.0], [1.8, 2.8])
27+
# Z = Interval([0.9, 1.9], [1.9, 2.9])
28+
Z = Interval([0.8, 1.8], [2.0, 3.0])
29+
30+
cell_nums_s = {12: 0.3, 16: 0.25, 20: 0.18}
31+
cell_nums_m = {8: 0.6, 12: 0.4, 16: 0.3, 20: 0.22, 24: 0.18, 28: 0.16, 32: 0.14, 36: 0.12}
32+
cell_nums_l = {20: 0.3, 24: 0.2, 28: 0.18, 32: 0.16, 36: 0.15}
33+
# Reachable sets computed with boundary analysis
34+
options.r0 = boundary(Z, cell_nums_l[36], Geometry.TYPE.ZONOTOPE)
35+
# Reachable sets computed without boundary analysis
36+
# options.r0 = [cvt2(Z, Geometry.TYPE.ZONOTOPE)]
37+
print("The number of divided sets: ", len(options.r0))
38+
39+
time_tag = performance_counter_start()
40+
ri, rp = ASB2008CDCParallel.reach_parallel(vanderpol, [2, 1], options, options.r0)
41+
performance_counter(time_tag, "ASB2008CDCParallel")
42+
43+
# save the results
44+
save_result(ri, "vanderpol_" + str(len(options.r0)))
45+
46+
# visualize the results
47+
plot(ri, [0, 1])

pybdr/model/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from .pi_controller_with_disturbance import pi_controller_with_disturbance
1616
from .jet_engine import jet_engine
1717
from .brusselator import brusselator
18+
from .neural_ode.spiral1 import spiral1
19+
from .neural_ode.spiral2 import spiral2
1820

1921
__all__ = [
2022
"Model",
@@ -33,5 +35,7 @@
3335
"rossler_attractor",
3436
'pi_controller_with_disturbance',
3537
'jet_engine',
36-
'brusselator'
38+
'brusselator',
39+
'spiral1',
40+
'spiral2',
3741
]

pybdr/model/neural_ode/neural_ode_model1.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)