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

[WIP #93] - Revise add-dimension #148

Merged
merged 7 commits into from
Apr 15, 2018
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
5 changes: 0 additions & 5 deletions src/ReachSets/reach.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ Interface to reachability algorithms for an LTI system.

A dictionary with available algorithms is available via
`Reachability.available_algorithms`.

WARNING:

Only systems of even dimension are parsed; for odd dimension, manually add an
extra variable with no dynamics.
"""
function reach(S::AbstractSystem,
N::Int;
Expand Down
22 changes: 14 additions & 8 deletions src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ function validate_solver_options_and_add_default_values!(options::Options)::Opti
elseif key == :partition
expected_type = AbstractVector{<:AbstractVector{Int}}
elseif key == :block_types
expected_type =
Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}
expected_type = Union{Void,
Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}}
elseif key == :block_types_init
expected_type =
Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}
Expand Down Expand Up @@ -478,12 +478,18 @@ function check_and_add_partition_block_types!(dict::Dict{Symbol,Any},
error("need option :partition specified")
end

block_types = haskey(dict, :block_types) ? dict[:block_types] :
haskey(dict, :set_type) ?
Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}(
dict[:set_type] => copy(dict_copy[:partition])
) : nothing
check_aliases!(dict, dict_copy, [:block_types])
block_types = nothing
if haskey(dict, :block_types)
for (key, value) in dict[:block_types]
@assert key <: LazySet "the keys of the `partition` dictionary should be lazy sets"
@assert typeof(value) <: AbstractVector{<:AbstractVector{Int}} "the keys of the `partition` dictionary should be vectors of vectors"
end
block_types = convert(Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}, dict[:block_types])
elseif haskey(dict, :set_type)
block_types = Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}(dict[:set_type] => copy(dict_copy[:partition]))
end
check_aliases_and_add_default_value!(dict, dict_copy, [:block_types], block_types)
dict_copy[:block_types] = block_types

block_types_init = haskey(dict, :block_types_init) ?
dict[:block_types_init] :
Expand Down
7 changes: 2 additions & 5 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,8 @@ function solve(system::AbstractSystem,
# ==========
# Dimensions
# ==========
dimension = statedim(system)
if isodd(dimension)
system = add_dimension(system)
end
options_input.dict[:n] = dimension
options_input.dict[:n] = statedim(system)

# =======
# Options
# =======
Expand Down
8 changes: 8 additions & 0 deletions test/Reachability/unit_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ s = solve(ContinuousSystem(sparse(A), X0), :T=>0.1, :partition=>[1:2, 3:4],

s = solve(ContinuousSystem(sparse(A), X0), :T=>0.1, :partition=>[[i] for i in 1:4],
:set_type=>Interval, :vars=>[1,3], :lazy_expm=>true);

# ===============================
# System with an odd dimension
# ===============================
A = randn(5, 5); X0 = BallInf(ones(5), 0.1)
system = ContinuousSystem(A, X0)
options = Options(Dict(:T=>0.1, :partition=>[1:2, 3:4, [5]], :block_types=>Dict(HPolygon=>[1:2, 3:4], Interval=>[[5]]), :vars=>[1,3]))
s = solve(system, options)