From 85e46226672bd130919cb84b5f0b93e2628a4753 Mon Sep 17 00:00:00 2001 From: mforets Date: Thu, 5 Apr 2018 19:26:23 -0300 Subject: [PATCH 1/5] remove add dimension for odd dim by default --- src/options.jl | 13 ++++++++----- src/solve.jl | 7 ++----- test/Reachability/unit_solve.jl | 9 +++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/options.jl b/src/options.jl index 173c8e3e..89d83052 100644 --- a/src/options.jl +++ b/src/options.jl @@ -478,11 +478,14 @@ 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 + block_types = nothing + if haskey(dict, :block_types) + block_types = convert(Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}, dict[:block_types]) + else + if haskey(dict, :set_type) + block_types = Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}(dict[:set_type] => copy(dict_copy[:partition])) + end + end check_aliases!(dict, dict_copy, [:block_types]) block_types_init = haskey(dict, :block_types_init) ? diff --git a/src/solve.jl b/src/solve.jl index 2bff1e65..f76c646d 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -83,11 +83,8 @@ function solve(system::AbstractSystem, # ========== # Dimensions # ========== - dimension = Systems.dim(system) - if isodd(dimension) - system = add_dimension(system) - end - options_input.dict[:n] = dimension + options_input.dict[:n] = Systems.dim(system) + # ======= # Options # ======= diff --git a/test/Reachability/unit_solve.jl b/test/Reachability/unit_solve.jl index e13dc256..415d3ae9 100644 --- a/test/Reachability/unit_solve.jl +++ b/test/Reachability/unit_solve.jl @@ -47,3 +47,12 @@ 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 add dimension +# =============================== + +A = randn(5, 5); X0 = BallInf(ones(5), 0.1) +s = solve(ContinuousSystem(A, X0), :T=>0.1, :partition=>[1:2, 3:4, 5], + :block_types=>Dict(HPolygon=>[1:2, 3:4], Interval=>[[5]]), + :vars=>[1,3]); From bb22169953eb129c3bdc5cc7708757f3ec2cc038 Mon Sep 17 00:00:00 2001 From: mforets Date: Sun, 15 Apr 2018 11:15:24 -0300 Subject: [PATCH 2/5] update branch --- src/ReachSets/reach.jl | 5 ----- src/options.jl | 14 ++++++++------ src/solve.jl | 2 +- test/Reachability/unit_solve.jl | 8 ++++---- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/ReachSets/reach.jl b/src/ReachSets/reach.jl index 9380166f..0b363b9c 100644 --- a/src/ReachSets/reach.jl +++ b/src/ReachSets/reach.jl @@ -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; diff --git a/src/options.jl b/src/options.jl index 89d83052..2d51b332 100644 --- a/src/options.jl +++ b/src/options.jl @@ -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 = Dict + #Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}} elseif key == :block_types_init expected_type = Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}} @@ -480,11 +480,13 @@ function check_and_add_partition_block_types!(dict::Dict{Symbol,Any}, block_types = nothing if haskey(dict, :block_types) - block_types = convert(Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}, dict[:block_types]) - else - if haskey(dict, :set_type) - block_types = Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}(dict[:set_type] => copy(dict_copy[:partition])) + 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!(dict, dict_copy, [:block_types]) diff --git a/src/solve.jl b/src/solve.jl index 515001bd..100761f8 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -83,7 +83,7 @@ function solve(system::AbstractSystem, # ========== # Dimensions # ========== - options_input.dict[:n] = Systems.dim(system) + options_input.dict[:n] = statedim(system) # ======= # Options diff --git a/test/Reachability/unit_solve.jl b/test/Reachability/unit_solve.jl index 415d3ae9..2d9b6fd7 100644 --- a/test/Reachability/unit_solve.jl +++ b/test/Reachability/unit_solve.jl @@ -49,10 +49,10 @@ s = solve(ContinuousSystem(sparse(A), X0), :T=>0.1, :partition=>[[i] for i in 1: :set_type=>Interval, :vars=>[1,3], :lazy_expm=>true); # =============================== -# System with an add dimension +# System with an odd dimension # =============================== A = randn(5, 5); X0 = BallInf(ones(5), 0.1) -s = solve(ContinuousSystem(A, X0), :T=>0.1, :partition=>[1:2, 3:4, 5], - :block_types=>Dict(HPolygon=>[1:2, 3:4], Interval=>[[5]]), - :vars=>[1,3]); +system = ContinuousSystem(A, X0) +options = Options(Dict(:T=>0.1, :partition=>AbstractVector{<:AbstractVector{Int}}[1:2, 3:4, [5]], :block_types=>Dict(HPolygon=>[1:2, 3:4], Interval=>[[5]]), :vars=>[1,3])) +s = solve(system, options) From 4e8fe1b9023e0d2cc936061c59b53b2eefd76f02 Mon Sep 17 00:00:00 2001 From: mforets Date: Sun, 15 Apr 2018 11:18:25 -0300 Subject: [PATCH 3/5] update test --- test/Reachability/unit_solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Reachability/unit_solve.jl b/test/Reachability/unit_solve.jl index 2d9b6fd7..55354c3a 100644 --- a/test/Reachability/unit_solve.jl +++ b/test/Reachability/unit_solve.jl @@ -54,5 +54,5 @@ s = solve(ContinuousSystem(sparse(A), X0), :T=>0.1, :partition=>[[i] for i in 1: A = randn(5, 5); X0 = BallInf(ones(5), 0.1) system = ContinuousSystem(A, X0) -options = Options(Dict(:T=>0.1, :partition=>AbstractVector{<:AbstractVector{Int}}[1:2, 3:4, [5]], :block_types=>Dict(HPolygon=>[1:2, 3:4], Interval=>[[5]]), :vars=>[1,3])) +options = Options(Dict(:T=>0.1, :partition=>convert(AbstractVector{<:AbstractVector{Int}}, [1:2, 3:4, [5]]), :block_types=>Dict(HPolygon=>[1:2, 3:4], Interval=>[[5]]), :vars=>[1,3])) s = solve(system, options) From 73f474106a9d79fc0b6e2cc2cd734aeaec6bc066 Mon Sep 17 00:00:00 2001 From: mforets Date: Sun, 15 Apr 2018 12:33:00 -0300 Subject: [PATCH 4/5] simplify test and strict expected type --- src/options.jl | 3 +-- test/Reachability/unit_solve.jl | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/options.jl b/src/options.jl index 2d51b332..531e139c 100644 --- a/src/options.jl +++ b/src/options.jl @@ -206,8 +206,7 @@ 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 - #Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}} + expected_type = Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}} elseif key == :block_types_init expected_type = Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}} diff --git a/test/Reachability/unit_solve.jl b/test/Reachability/unit_solve.jl index 55354c3a..a2616f4d 100644 --- a/test/Reachability/unit_solve.jl +++ b/test/Reachability/unit_solve.jl @@ -51,8 +51,7 @@ s = solve(ContinuousSystem(sparse(A), X0), :T=>0.1, :partition=>[[i] for i in 1: # =============================== # 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=>convert(AbstractVector{<:AbstractVector{Int}}, [1:2, 3:4, [5]]), :block_types=>Dict(HPolygon=>[1:2, 3:4], Interval=>[[5]]), :vars=>[1,3])) +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) From 76e15425143e6b208082bc5ca2a5f920660b1acb Mon Sep 17 00:00:00 2001 From: schillic Date: Sun, 15 Apr 2018 17:40:36 +0200 Subject: [PATCH 5/5] convert dictionary :block_types and allow Void type --- src/options.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/options.jl b/src/options.jl index 531e139c..431737f3 100644 --- a/src/options.jl +++ b/src/options.jl @@ -206,7 +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}}} @@ -487,7 +488,8 @@ function check_and_add_partition_block_types!(dict::Dict{Symbol,Any}, elseif haskey(dict, :set_type) block_types = Dict{Type{<:LazySet}, AbstractVector{<:AbstractVector{Int}}}(dict[:set_type] => copy(dict_copy[:partition])) end - check_aliases!(dict, dict_copy, [:block_types]) + 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] :