-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset.jl
62 lines (53 loc) · 2.64 KB
/
dataset.jl
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
using DifferentialEquations
using LazySets
using ProgressBars
using JLD2
function find_ada_input_area(U::Hyperrectangle, random_point)
if length(random_point) != 4 || dim(U) != 2
println("only support 2D double-integrator")
return U
end
random_point[3] > 0 ? ux_min = low(U, 1) : ux_min = 0
random_point[3] > 0 ? ux_max = 0 : ux_max = high(U, 1)
random_point[4] > 0 ? uy_min = low(U, 2) : uy_min = 0
random_point[4] > 0 ? uy_max = 0 : uy_max = high(U, 2)
output = Hyperrectangle(low=[ux_min, uy_min], high=[ux_max, uy_max])
return output
end
function find_ada_non_admissible_area(non_admissible_area::Hyperrectangle, random_point, input_bound)
if length(random_point) != 4 || dim(non_admissible_area) != 4 || dim(input_bound) != 2
println("only support 2D double-integrator")
return non_admissible_area
end
x_min = low(non_admissible_area, 1) + max(0, random_point[3]) * random_point[3] / (2 * low(input_bound, 1))
x_max = high(non_admissible_area, 1) + max(0, -random_point[3]) * (-random_point[3]) / (2 * high(input_bound, 1))
y_min = low(non_admissible_area, 2) + max(0, random_point[4]) * random_point[4] / (2 * low(input_bound, 2))
y_max = high(non_admissible_area, 2) + max(0, -random_point[4]) * (-random_point[4]) / (2 * high(input_bound, 2))
# @show non_admissible_area
@assert x_min ≤ low(non_admissible_area, 1)
@assert y_min ≤ low(non_admissible_area, 2)
@assert x_max ≥ high(non_admissible_area, 1)
@assert y_max ≥ high(non_admissible_area, 2)
output = Hyperrectangle(low=[x_min, y_min, low(non_admissible_area, 3),low(non_admissible_area, 3)], high=[x_max, y_max, high(non_admissible_area,3), high(non_admissible_area,4)])
# @show random_point, output
return output
end
function random_point_in_hyperrectangle(hyperrectangle::Hyperrectangle, non_admissible_area=nothing, input_bound=nothing)
dimensions = dim(hyperrectangle)
# while true
random_point = Vector{Float32}(undef, dimensions)
for i in 1:dimensions
random_point[i] = rand() * (high(hyperrectangle, i)-low(hyperrectangle, i)) + low(hyperrectangle, i)
end
isnothing(non_admissible_area) && return random_point, true
# @show non_admissible_area, random_point, input_bound
ada_non_admissible_area = find_ada_non_admissible_area(non_admissible_area, random_point, input_bound)
(random_point ∉ ada_non_admissible_area) && return random_point, true
return random_point, false
# continue
# end
end
function affine_dyn(A::AbstractMatrix, x::AbstractArray, B::AbstractMatrix, u::AbstractArray)
ẋ = A * x + B * u
return ẋ
end