Skip to content

Commit

Permalink
small fixes and added intersection between Cartesian products
Browse files Browse the repository at this point in the history
  • Loading branch information
kpotomkin committed Jun 4, 2019
1 parent 7e2891f commit 16521c3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/CartesianProduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export CartesianProduct,
array,
block_indices,
variable_indices,
block_structure
block_structure,
same_block_structure

"""
CartesianProduct{N<:Real, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N}
Expand Down
51 changes: 42 additions & 9 deletions src/concrete_intersection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ function intersection(rm::ResetMap{N, <:AbstractPolytope},
end

"""
function intersection(X::CartesianProductArray{N},
intersection(X::CartesianProductArray{N},
Y::AbstractPolyhedron{N}) where {N}
Return the intersection of the cartesian product of a finite number of convex sets and a polyhedron.
Expand All @@ -800,26 +800,29 @@ This function takes into account that if the polyhedron is unbounded, the inters
is only needed to be taken in the elements of the cartesian product array (subsets of
variables, or "blocks") which are constrained; those which are not constrained do not need to be intersected.
"""
function intersection_combine(X::CartesianProductArray{N},
function intersection(X::CartesianProductArray{N},
Y::AbstractPolyhedron{N},
blocks::Dict{Int,Int},
oa=Hyperrectangle) where {N}

low_set, vars, block_structure = initialize_vars(X, blocks)

low_intersection = intersection(approx_low_set, Approximations.project(Y,vars, LinearMap))
low_intersection = intersection(low_set, Approximations.project(Y, vars, LinearMap))

if isempty(low_intersection)
return EmptySet()
end

println(block_structure)
decomposed_low_set = Approximations.decompose(low_intersection, block_structure, oa)

return combine_resulted_cpa(decomposed_low_set, X)
return combine_resulted_cpa(decomposed_low_set, X, blocks)
end

function combine_resulted_cpa(l_cpa::CartesianProductArray{N}, o_cpa::CartesianProductArray{N}) where {N}
result = CartesianProductArray(length(X.array), N)
function combine_resulted_cpa(l_cpa::CartesianProductArray{N},
o_cpa::CartesianProductArray{N},
blocks::Dict{Int,Int}) where {N}
result = CartesianProductArray(length(l_cpa.array), N)

index = 1
for bi in 1:length(o_cpa.array)
Expand All @@ -842,7 +845,7 @@ function initialize_vars(X::CartesianProductArray{N}, blocks::Dict{Int,Int}) whe
n = dim(X.array[bi])
push!(low_set.array, X.array[bi])
append!(vars, variable_indices(X, bi, blocks[bi]))
push!(block_structure, start_index:(start_index + n))
push!(block_structure, start_index:(start_index + n - 1))
start_index += n
end

Expand All @@ -854,7 +857,7 @@ end

function intersection(X::CartesianProductArray{N},
Y::AbstractPolyhedron{N},
oa::Union{Type{<:Approximations.AbstractDirections},Type{<:Hyperrectangle}, Type{<:Interval}}=Hyperrectangle) where {N}
oa=Hyperrectangle) where {N}

if isbounded(Y)
# no free variables
Expand All @@ -869,7 +872,7 @@ end

# symmetric method
function intersection(Y::AbstractPolyhedron{N}, X::CartesianProductArray{N},
oa::Union{Type{<:Approximations.AbstractDirections},Type{<:Hyperrectangle}, Type{<:Interval}}=Hyperrectangle) where {N}
oa=Hyperrectangle) where {N}
intersection(X, Y, oa)
end

Expand All @@ -881,3 +884,33 @@ end
function intersection(X::CartesianProductArray{N}, U::Universe{N}) where {N<:Real}
return intersection(U, X)
end

"""
intersection(X::CartesianProductArray{N}, Y::CartesianProductArray{N})
Return the intersection between cartesian products of a finite number of convex sets.
### Input
- `X` -- cartesian product of a finite number of convex sets
- `Y` -- cartesian product of a finite number of convex sets
### Output
The decomposed set which represents concrete intersection between `X` and `Y`
### Algorithm
This algorithm intersect corresponding blocks between sets.
"""
function intersection(X::CartesianProductArray{N}, Y::CartesianProductArray{N}) where {N<:Real}
@assert same_block_structure(array(X), array(Y)) "block structure has to be the same"

result = CartesianProductArray(length(X.array), N)

for i in 1:length(X.array)
push!(result, intersection(X.array[i], Y.array[i]))
end

return result
end

0 comments on commit 16521c3

Please sign in to comment.