JuliaReach/Reachability.jl

MethodError in hybrid system flowpipe construction

mforets opened this issue · 2 comments

MWE:

using TaylorIntegration, MathematicalSystems, HybridSystems, SparseArrays
using Revise, Reachability

function EMBrake_hibrid()
    # the state variables are:
    # [I, x, T, xe, xc]

    # model's constants
    L       = 1.e-3;
    KP      = 10000.;
    KI      = 1000.;
    R       = 0.3;
    K       = 0.02;
    drot    = 0.1;
    i       = 113.1167;
    Tsample = 1.E-4;
    
    EMbrake = LightAutomaton(1)

    # Braking mode: x' =  Ax + b
    A = [-(R+K^2/drot)/L 0   0   KP/L  KI/L; 
           K/i/drot      0   0   0      0;
           0             0   0   0      0;
           0             0   0   0      0;
           0             0   0   0      0]
    A = sparse(A)
    b = [0, 0, 1.0, 0, 0]
    b = sparse(b)
    X = HalfSpace([0.0, 0.0, 1.0, 0.0, 0.0], Tsample) # invariant
    brake = ConstrainedAffineContinuousSystem(A, b, X)
    modes = [brake]

    # transition (self-loop)
    add_transition!(EMbrake, 1, 1, 1)
    x0 = 0.05
    A = sparse([1, 2, 4, 5, 5], [1, 2, 2, 2, 5], [1., 1., -1., -Tsample, 1.], 5, 5);
    b = sparsevec([4, 5], [x0, Tsample*x0], 5)
    guard = HalfSpace([0.0, 0.0, -1.0, 0.0, 0.0], -Tsample); # T >= Tsample
    resetmaps = [ConstrainedAffineMap(A, b, guard)]
    switchings = [AutonomousSwitching()]

    H = HybridSystem(EMbrake, modes, resetmaps, switchings)
end

I₀  = Singleton([0.0])
x₀  = Singleton([0.0])
T₀  = Singleton([0.0])
xe₀ = Singleton([0.0]);
xc₀ = Singleton([0.0])

X₀ = I₀ × x₀ × T₀ × xe₀ × xc₀;

H = EMBrake_hibrid()
P = InitialValueProblem(H, [(1, X₀)]);

alg = BFFPSV18(=>1e-4)
# opD = LazyDiscretePost(:check_invariant_intersection => true)
sol = solve(P, Options(:T=>0.4, :verbosity=>2, :max_jumps=>3), alg);

returns

[info] Reachable States Computation...
[info] Time discretization...
[info] elapsed time: 3.242e+00 seconds
[info] - Decomposing X0
[info] elapsed time: 1.707e-01 seconds
[info] - Computing successors
[info] elapsed time: 7.210e-01 seconds
[info] termination after only 3 of 4000 steps
[info] - Total
[info] elapsed time: 4.578e+00 seconds
[info] Considering transition: HybridSystems.LightTransition{LightGraphs.SimpleGraphs.SimpleEdge{Int64}}(Edge 1 => 1, 1)
Array{SparseReachSet,1}
MethodError: no method matching Flowpipe(::Array{SparseReachSet,1})
Closest candidates are:
  Flowpipe(!Matched::Array{RSN<:AbstractReachSet{SN},1}) where {SN, RSN<:AbstractReachSet{SN}} at /home/mforets/.julia/dev/Reachability/src/ReachSets/Flowpipe.jl:11

Stacktrace:
 [1] solve!(::InitialValueProblem{HybridSystem{LightAutomaton{LightGraphs.SimpleGraphs.SimpleDiGraph{Int64},LightGraphs.SimpleGraphs.SimpleEdge{Int64}},ConstrainedAffineContinuousSystem{Float64,SparseMatrixCSC{Float64,Int64},SparseVector{Float64,Int64},HalfSpace{Float64,Array{Float64,1}}},ConstrainedAffineMap{Float64,SparseMatrixCSC{Float64,Int64},SparseVector{Float64,Int64},HalfSpace{Float64,Array{Float64,1}}},AutonomousSwitching,Array{ConstrainedAffineContinuousSystem{Float64,SparseMatrixCSC{Float64,Int64},SparseVector{Float64,Int64},HalfSpace{Float64,Array{Float64,1}}},1},Array{ConstrainedAffineMap{Float64,SparseMatrixCSC{Float64,Int64},SparseVector{Float64,Int64},HalfSpace{Float64,Array{Float64,1}}},1},Array{AutonomousSwitching,1}},Array{Tuple{Int64,CartesianProduct{Float64,CartesianProduct{Float64,CartesianProduct{Float64,CartesianProduct{Float64,Singleton{Float64,Array{Float64,1}},Singleton{Float64,Array{Float64,1}}},Singleton{Float64,Array{Float64,1}}},Singleton{Float64,Array{Float64,1}}},Singleton{Float64,Array{Float64,1}}}},1}}, ::Options, ::BFFPSV18, ::LazyDiscretePost) at /home/mforets/.julia/dev/Reachability/src/solve.jl:233
 [2] solve at /home/mforets/.julia/dev/Reachability/src/solve.jl:107 [inlined] (repeats 2 times)
 [3] top-level scope at In[5]:2

The problem seems to be that there is an empty set in Rsets, so it's not concretely typed.