Skip to content

Commit c85d810

Browse files
Jc/remove general domain (#419)
* make periodic_domain working in UniformGrid solver * remove GeneralDomain * remove comments * remove comments from hierarchic * Fix format * Update src/domain/grid_domain/nested_domain.jl Co-authored-by: Benoît Legat <[email protected]> * Update src/domain/grid_domain/nested_domain.jl Co-authored-by: Benoît Legat <[email protected]> --------- Co-authored-by: Benoît Legat <[email protected]>
1 parent 8f6df16 commit c85d810

39 files changed

+1409
-1217
lines changed

docs/src/examples/solvers/Hierarchical-abstraction.jl

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ include(joinpath(dirname(dirname(pathof(Dionysos))), "problems", "simple_problem
2222
## specific functions
2323
function post_image(abstract_system, concrete_system, xpos, u)
2424
Xdom = abstract_system.Xdom
25-
x = DO.get_coord_by_pos(Xdom.grid, xpos)
25+
x = DO.get_coord_by_pos(Xdom, xpos)
2626
Fx = concrete_system.f_eval(x, u)
27-
r = Xdom.grid.h / 2.0 + concrete_system.measnoise
27+
r = DO.get_grid(Xdom).h / 2.0 + concrete_system.measnoise
2828
Fr = r
2929

30-
rectI = DO.get_pos_lims_outer(Xdom.grid, UT.HyperRectangle(Fx .- Fr, Fx .+ Fr))
30+
rectI = DO.get_pos_lims_outer(DO.get_grid(Xdom), UT.HyperRectangle(Fx .- Fr, Fx .+ Fr))
3131
ypos_iter = Iterators.product(DO._ranges(rectI)...)
3232
over_approx = []
3333
allin = true
3434
for ypos in ypos_iter
35-
ypos = DO.set_in_period_pos(Xdom, ypos)
36-
if !(ypos in Xdom)
35+
if !(ypos in abstract_system)
3736
allin = false
3837
break
3938
end
@@ -44,17 +43,16 @@ function post_image(abstract_system, concrete_system, xpos, u)
4443
end
4544

4645
function pre_image(abstract_system, concrete_system, xpos, u)
47-
grid = abstract_system.Xdom.grid
48-
x = DO.get_coord_by_pos(grid, xpos)
46+
Xdom = abstract_system.Xdom
47+
x = DO.get_coord_by_pos(Xdom, xpos)
4948
potential = Int[]
5049
x_prev = concrete_system.f_backward(x, u)
51-
xpos_cell = DO.get_pos_by_coord(grid, x_prev)
50+
xpos_cell = DO.get_pos_by_coord(Xdom, x_prev)
5251
n = 2
5352
for i in (-n):n
5453
for j in (-n):n
5554
x_n = (xpos_cell[1] + i, xpos_cell[2] + j)
56-
x_n = DO.set_in_period_pos(abstract_system.Xdom, x_n)
57-
if x_n in abstract_system.Xdom
55+
if x_n in abstract_system
5856
cell = SY.get_state_by_xpos(abstract_system, x_n)[1]
5957
if !(cell in potential)
6058
push!(potential, cell)
@@ -87,9 +85,9 @@ minimum_transition_cost(symmodel, contsys, source, target) = 1.0
8785
concrete_problem = SimpleProblem.problem(;
8886
rectX = UT.HyperRectangle(SVector(0.0, 0.0), SVector(60.0, 60.0)),
8987
obstacles = [UT.HyperRectangle(SVector(22.0, 21.0), SVector(25.0, 32.0))],
90-
periodic = Int[],
91-
periods = [30.0, 30.0],
92-
T0 = [0.0, 0.0],
88+
periodic = SVector{0, Int}(),
89+
periods = SVector{0, Float64}(),
90+
T0 = SVector{0, Float64}(),
9391
rectU = UT.HyperRectangle(SVector(-2.0, -2.0), SVector(2.0, 2.0)),
9492
Uobstacles = [UT.HyperRectangle(SVector(-0.5, -0.5), SVector(0.5, 0.5))],
9593
_I_ = UT.HyperRectangle(SVector(6.5, 6.5), SVector(7.5, 7.5)),
@@ -103,8 +101,8 @@ concrete_problem = SimpleProblem.problem(;
103101
concrete_system = concrete_problem.system;
104102

105103
# Local optimizer parameters
106-
hx_local = [0.5, 0.5]
107-
hx_heuristic = [1.0, 1.0]
104+
hx_local = SVector(0.5, 0.5)
105+
hx_heuristic = SVector(1.0, 1.0)
108106
u0 = SVector(0.0, 0.0)
109107
hu = SVector(0.5, 0.5)
110108
Ugrid = DO.GridFree(u0, hu)
@@ -124,7 +122,7 @@ AB.LazyAbstraction.set_optimizer_parameters!(
124122
)
125123

126124
# Global optimizer parameters
127-
hx_global = [10.0, 10.0]
125+
hx_global = SVector(10.0, 10.0)
128126
u0 = SVector(0.0, 0.0)
129127
hu = SVector(0.5, 0.5)
130128
Ugrid = DO.GridFree(u0, hu)
@@ -168,7 +166,7 @@ println("Cost:\t $(cost)")
168166

169167
# ## Display the results
170168
# # Display the specifications, domains and trajectory
171-
fig = plot(; aspect_ratio = :equal);
169+
fig1 = plot(; aspect_ratio = :equal);
172170

173171
#We display the concrete domain
174172
plot!(concrete_system.X; color = :grey, opacity = 0.5, label = "");
@@ -184,7 +182,7 @@ plot!(concrete_problem.target_set; dims = [1, 2], color = :red, opacity = 0.8);
184182
plot!(cost_control_trajectory; ms = 0.5)
185183

186184
# # Display the lazy abstraction
187-
fig = plot(; aspect_ratio = :equal);
185+
fig2 = plot(; aspect_ratio = :equal);
188186

189187
plot!(
190188
optimizer.hierarchical_problem;

docs/src/examples/solvers/Lazy-abstraction-reachability.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@ include(joinpath(dirname(dirname(pathof(Dionysos))), "problems", "simple_problem
3434
## specific functions
3535
function post_image(abstract_system, concrete_system, xpos, u)
3636
Xdom = abstract_system.Xdom
37-
x = DO.get_coord_by_pos(Xdom.grid, xpos)
37+
x = DO.get_coord_by_pos(Xdom, xpos)
3838
Fx = concrete_system.f_eval(x, u)
39-
r = Xdom.grid.h / 2.0 + concrete_system.measnoise
39+
r = DO.get_grid(Xdom).h / 2.0 + concrete_system.measnoise
4040
Fr = r
4141

42-
rectI = DO.get_pos_lims_outer(Xdom.grid, UT.HyperRectangle(Fx .- Fr, Fx .+ Fr))
42+
rectI = DO.get_pos_lims_outer(DO.get_grid(Xdom), UT.HyperRectangle(Fx .- Fr, Fx .+ Fr))
4343
ypos_iter = Iterators.product(DO._ranges(rectI)...)
4444
over_approx = []
4545
allin = true
4646
for ypos in ypos_iter
47-
ypos = DO.set_in_period_pos(Xdom, ypos)
48-
if !(ypos in Xdom)
47+
if !(ypos in abstract_system)
4948
allin = false
5049
break
5150
end
@@ -56,17 +55,16 @@ function post_image(abstract_system, concrete_system, xpos, u)
5655
end
5756

5857
function pre_image(abstract_system, concrete_system, xpos, u)
59-
grid = abstract_system.Xdom.grid
60-
x = DO.get_coord_by_pos(grid, xpos)
58+
Xdom = abstract_system.Xdom
59+
x = DO.get_coord_by_pos(Xdom, xpos)
6160
potential = Int[]
6261
x_prev = concrete_system.f_backward(x, u)
63-
xpos_cell = DO.get_pos_by_coord(grid, x_prev)
62+
xpos_cell = DO.get_pos_by_coord(Xdom, x_prev)
6463
n = 2
6564
for i in (-n):n
6665
for j in (-n):n
6766
x_n = (xpos_cell[1] + i, xpos_cell[2] + j)
68-
x_n = DO.set_in_period_pos(abstract_system.Xdom, x_n)
69-
if x_n in abstract_system.Xdom
67+
if x_n in abstract_system
7068
cell = SY.get_state_by_xpos(abstract_system, x_n)[1]
7169
if !(cell in potential)
7270
push!(potential, cell)
@@ -98,11 +96,11 @@ minimum_transition_cost(symmodel, contsys, source, target) = 1.0
9896
concrete_problem = SimpleProblem.problem()
9997
concrete_system = concrete_problem.system
10098

101-
hx = [0.5, 0.5]
99+
hx = SVector(0.5, 0.5)
102100
u0 = SVector(0.0, 0.0)
103101
hu = SVector(0.5, 0.5)
104102
Ugrid = DO.GridFree(u0, hu)
105-
hx_heuristic = [1.0, 1.0] * 1.5
103+
hx_heuristic = SVector(1.5, 1.5)
106104
maxIter = 100
107105

108106
optimizer = MOI.instantiate(AB.LazyAbstraction.Optimizer)

docs/src/examples/solvers/Path planning.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Test #src
21
# # Example: Path planning problem solved by [Uniform grid abstraction](https://github.com/dionysos-dev/Dionysos.jl/blob/master/docs/src/manual/manual.md#solvers).
32
#
43
#md # [![Binder](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/generated/Path planning.ipynb)
@@ -97,13 +96,13 @@ set_attribute(
9796
set_attribute(model, "efficient", true)
9897

9998
x0 = SVector(0.0, 0.0, 0.0);
100-
h = SVector(0.2, 0.2, 0.2);
101-
set_attribute(model, "state_grid", Dionysos.Domain.GridFree(x0, h))
99+
hx = SVector(0.2, 0.2, 0.2);
100+
set_attribute(model, "state_grid", Dionysos.Domain.GridFree(x0, hx))
102101

103102
# Definition of the grid of the input-space on which the abstraction is based (origin `u0` and input-space discretization `h`):
104103
u0 = SVector(0.0, 0.0);
105-
h = SVector(0.3, 0.3);
106-
set_attribute(model, "input_grid", Dionysos.Domain.GridFree(u0, h))
104+
hu = SVector(0.3, 0.3);
105+
set_attribute(model, "input_grid", Dionysos.Domain.GridFree(u0, hu))
107106

108107
optimize!(model);
109108

@@ -124,8 +123,6 @@ println("Time to solve the abstract problem: $(abstract_problem_time)")
124123
total_time = MOI.get(model, MOI.RawOptimizerAttribute("solve_time_sec"))
125124
println("Total time: $(total_time)")
126125

127-
@test length(abstract_controller.data) == 19400 #src
128-
129126
# ### Trajectory display
130127
# We choose a stopping criterion `reached` and the maximal number of steps `nsteps` for the sampled system, i.e. the total elapsed time: `nstep`*`tstep`
131128
# as well as the true initial state `x0` which is contained in the initial state-space `_I_` defined previously.

docs/src/examples/utils/Grid.jl

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ function plot_deformed_grid_with_DomainList(f, fi)
6767
return plot!(dom; show = true, color = :grey, efficient = false)
6868
end
6969

70-
function plot_deformed_grid_with_GeneralDomain(f, fi)
71-
X = UT.HyperRectangle(SVector(0.0, 0.0), SVector(30.0, 10.0))
72-
obstacle = UT.HyperRectangle(SVector(10.0, 10.0), SVector(15.0, 15.0))
73-
hx = [2.5, 2.5]
74-
d = DO.RectangularObstacles(X, [obstacle])
75-
dom = DO.GeneralDomainList(hx; elems = d, f = f, fi = fi, fit = true)
76-
plot(; aspect_ratio = :equal)
77-
return plot!(dom; show = true, color = :grey, efficient = false)
78-
end
79-
8070
rect = UT.HyperRectangle(SVector(0.0, 0.0), SVector(2.0, 2.0))
8171
shape = UT.DeformedRectangle(rect, f2)
8272
plot(; aspect_ratio = :equal)
@@ -85,53 +75,66 @@ plot!(shape; color = :red, efficient = false, label = "Deformed")
8575

8676
# Display some deformed Grids
8777
plot_deformed_grid_with_DomainList(f1, fi1)
88-
plot_deformed_grid_with_GeneralDomain(f1, fi1)
8978

9079
plot_deformed_grid_with_DomainList(f2, fi2)
91-
plot_deformed_grid_with_GeneralDomain(f2, fi2)
9280

9381
plot_deformed_grid_with_DomainList(f3, fi3)
94-
plot_deformed_grid_with_GeneralDomain(f3, fi3)
9582

9683
plot_deformed_grid_with_DomainList(f4, fi4)
97-
plot_deformed_grid_with_GeneralDomain(f4, fi4)
9884

9985
f, fi = build_f_rotation/ 3.0)
10086
plot_deformed_grid_with_DomainList(f, fi)
10187

102-
# ### Nested classical grid
88+
# ### Nested domain
89+
# --- Base domain and obstacle ---
10390
X = UT.HyperRectangle(SVector(0.0, 0.0), SVector(30.0, 30.0))
10491
obstacle = UT.HyperRectangle(SVector(15.0, 15.0), SVector(20.0, 20.0))
105-
hx = [3.0, 1.0] * 2.0
106-
periodic = Int[1]
107-
periods = [30.0, 30.0]
108-
T0 = [0.0, 0.0]
109-
d = DO.RectangularObstacles(X, [obstacle])
110-
dom = DO.GeneralDomainList(
111-
hx;
112-
elems = d,
113-
periodic = periodic,
114-
periods = periods,
115-
T0 = T0,
116-
fit = true,
117-
)
118-
Ndomain = DO.NestedDomain(dom)
119-
DO.cut_pos!(Ndomain, (2, 2), 1)
120-
DO.cut_pos!(Ndomain, (2, 3), 1)
121-
DO.cut_pos!(Ndomain, (4, 4), 2)
122-
123-
fig = plot(; aspect_ratio = :equal, legend = false);
92+
93+
# Grid settings
94+
hx = SVector(6.0, 2.0)
95+
periodic_dims = SVector(1)
96+
periods = SVector(30.0)
97+
start = SVector(0.0)
98+
99+
# Create a LazySetMinus: free space = X minus obstacle
100+
free_space = UT.LazySetMinus(X, UT.LazyUnionSetArray([obstacle]))
101+
102+
# Create periodic grid domain
103+
domain = DO.PeriodicDomainList(periodic_dims, periods, start, hx)
104+
# domain = DO.DomainList(hx)
105+
106+
DO.add_set!(domain, free_space, DO.INNER)
107+
108+
# Create the NestedDomain
109+
Ndomain = DO.NestedDomain(domain)
110+
111+
# --- Refinement ---
112+
# Refine certain cells
113+
div = 3
114+
DO.cut_pos!(Ndomain, (2, 2), 1; div = div)
115+
DO.cut_pos!(Ndomain, (2, 3), 1; div = div)
116+
DO.cut_pos!(Ndomain, (4, 4), 2; div = div)
117+
118+
# --- Plotting ---
119+
fig = plot(; aspect_ratio = :equal, legend = false)
120+
plot!(free_space; color = :blue, label = "Base domain", efficient = false)
124121
plot!(Ndomain; color = :grey, efficient = false)
125122

126-
# ### Ellipsoidal partition based on a grid
123+
# ----------------------------------------------------------------------
124+
# 2D Example: Ellipsoidal partition using a grid
125+
127126
x0 = SVector(0.0, 0.0)
128127
n_step = 2
129128
h = SVector(1.0 / n_step, 1.0 / n_step)
130129
P = 0.5 * diagm((h ./ 2) .^ (-2))
131-
rectX = UT.HyperRectangle(SVector(-2, -2), SVector(2, 2))
132130

133-
grid = DO.GridEllipsoidalRectangular(x0, h, P)
134-
domain = DO.DomainList(grid)
135-
DO.add_set!(domain, rectX, DO.OUTER)
136-
plot(; aspect_ratio = :equal);
137-
plot!(domain; color = :grey, opacity = 0.5, efficient = false)
131+
rectX = UT.HyperRectangle(SVector(-2.0, -2.0), SVector(2.0, 2.0))
132+
133+
# Create an ellipsoidal grid domain
134+
ellip_grid = DO.GridEllipsoidalRectangular(x0, h, P)
135+
ellip_domain = DO.DomainList(ellip_grid)
136+
DO.add_set!(ellip_domain, rectX, DO.OUTER)
137+
138+
# Plot
139+
fig2 = plot(; aspect_ratio = :equal)
140+
plot!(ellip_domain; color = :grey, opacity = 0.5, efficient = false)

docs/src/reference/Domain.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,32 @@ Dionysos.Domain.get_volume
2323
```@docs
2424
Dionysos.Domain.DomainType
2525
Dionysos.Domain.GridDomainType
26+
```
27+
28+
```@docs
2629
Dionysos.Domain.merge_to_hyperrectangles_pos
2730
Dionysos.Domain.merge_to_hyperrectangles_real
31+
```
32+
33+
## Concrete domains
34+
35+
### Classical domains
36+
```@docs
2837
Dionysos.Domain.DomainList
38+
Dionysos.Domain.CustomList
39+
```
40+
41+
### Periodic domain
42+
```@docs
2943
Dionysos.Domain.PeriodicDomainList
44+
Dionysos.Domain.is_periodic
3045
Dionysos.Domain.has_same_periodicity
3146
Dionysos.Domain.wrap_pos
3247
Dionysos.Domain.wrap_coord
33-
Dionysos.Domain.GeneralDomainList
34-
Dionysos.Domain.RectangularObstacles
35-
Dionysos.Domain.CustomList
48+
Dionysos.Domain._make_periodic_index_map
49+
```
50+
51+
### Nested domain
52+
```@docs
53+
Dionysos.Domain.NestedDomain
3654
```

docs/src/reference/System.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Dionysos.System.AffineController
114114

115115
## Trajectories
116116
```@docs
117+
Dionysos.System.wrap_coord
117118
Dionysos.System.DiscreteTrajectory
118119
Dionysos.System.ContinuousTrajectory
119120
Dionysos.System.HybridTrajectory

docs/src/reference/Utils.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Dionysos.Utils.Tree
4646
## Geometric shapes
4747

4848
```@docs
49+
Dionysos.Utils.set_in_period
4950
Dionysos.Utils.HyperRectangle
5051
Dionysos.Utils.DeformedRectangle
5152
```

problems/simple_problem.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ end
6666
function problem(;
6767
rectX = UT.HyperRectangle(SVector(0.0, 0.0), SVector(30.0, 30.0)),
6868
obstacles = [UT.HyperRectangle(SVector(15.0, 15.0), SVector(20.0, 20.0))],
69-
periodic = Int[],
70-
periods = [30.0, 30.0],
71-
T0 = [0.0, 0.0],
69+
periodic = SVector{0, Int}(),
70+
periods = SVector{0, Float64}(),
71+
T0 = SVector{0, Float64}(),
7272
rectU = UT.HyperRectangle(SVector(-2.0, -2.0), SVector(2.0, 2.0)),
7373
Uobstacles = [UT.HyperRectangle(SVector(-0.5, -0.5), SVector(0.5, 0.5))],
7474
_I_ = UT.HyperRectangle(SVector(5.0, 5.0), SVector(6.0, 6.0)),

src/domain/domain.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ include("grid_domain/grid.jl")
2020
include("grid_domain/grid_domain.jl")
2121
include("grid_domain/domain_list.jl")
2222
include("grid_domain/periodic_domain.jl")
23-
include("grid_domain/general_domain.jl")
2423
include("grid_domain/nested_domain.jl")
2524

2625
include("continuous_domain.jl")

0 commit comments

Comments
 (0)