Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#397 - constrained_dimensions #398

Merged
merged 7 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -119,6 +120,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}}()
schillic marked this conversation as resolved.
Show resolved Hide resolved
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