Skip to content

Commit

Permalink
Merge pull request #398 from JuliaReach/397
Browse files Browse the repository at this point in the history
#397 - constrained_dimensions
  • Loading branch information
schillic authored Jan 22, 2019
2 parents 58a41d5 + c53677b commit 6340067
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/solve.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export solve
import LazySets.constrained_dimensions

function default_operator(system::InitialValueProblem{S}) where
{S<:Union{AbstractContinuousSystem, AbstractDiscreteSystem}}
Expand Down Expand Up @@ -117,6 +118,32 @@ function solve(system::InitialValueProblem{<:HybridSystem, <:LazySet{N}},
return solve!(sys_new, copy(options), opC, opD)
end


"""
constrained_dimensions(HS::HybridSystem)::Dict{Int,Vector{Int}}
Return all coordinates which appear in any guard or invariant constraint for each location.
### Input
- `HS` -- hybrid system
"""
function constrained_dimensions(HS::HybridSystem)::Dict{Int,Vector{Int}}
result = Dict{Int,Vector{Int}}()
sizehint!(result, nstates(HS))
for mode in states(HS)
vars = Vector{Int}()
append!(vars, constrained_dimensions(stateset(HS, mode)))
for transition in out_transitions(HS, mode)
append!(vars, constrained_dimensions(stateset(HS, transition)))
end
result[mode] = unique(vars)
end

return result
end


function init_states_sys_from_init_set_sys(
system::InitialValueProblem{<:HybridSystem, <:LazySet{N}}) where N<:Real
HS = system.s
Expand Down
7 changes: 6 additions & 1 deletion test/Reachability/solve_hybrid_bouncing_ball.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Reachability, HybridSystems, MathematicalSystems, LazySets, Polyhedra
import LazySets.HalfSpace
import Reachability.constrained_dimensions

# Transition graph (automaton)
a = LightAutomaton(1);
Expand Down Expand Up @@ -38,7 +39,11 @@ system = InitialValueProblem(HS, inits);
options = Options(:mode=>"reach", :vars=>[1, 2], :T=>5.0, =>0.1,
:plot_vars=>[1, 2], :max_jumps=>1, :verbosity=>1);

# # default algorithm

# test constrained_dimensions
@test constrained_dimensions(HS) == Dict{Int,Vector{Int}}(1=>[1, 2])

# default algorithm
sol = solve(system, options);

# specify lazy discrete post operator
Expand Down
4 changes: 4 additions & 0 deletions test/Reachability/solve_hybrid_thermostat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using Reachability, HybridSystems, MathematicalSystems, LazySets, Polyhedra
# fix namamespace conflicts with Polyhedra
import LazySets.HalfSpace
import Reachability.ReachSet
import Reachability.constrained_dimensions

c_a = 0.1;

Expand Down Expand Up @@ -58,6 +59,9 @@ system = InitialValueProblem(HS, X0);
options = Options(:mode=>"reach", :vars=>[1], :T=>5.0, =>0.1,
:max_jumps=>1, :verbosity=>1);

# test constrained_dimensions
@test constrained_dimensions(HS) == Dict{Int,Vector{Int}}(1=>[1], 2=>[1])

# default algorithm
sol = solve(system, options);

Expand Down

0 comments on commit 6340067

Please sign in to comment.