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

added constraints_list for CartesianProduct #761

Merged
merged 11 commits into from
Oct 11, 2018
53 changes: 53 additions & 0 deletions src/CartesianProduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ function ∈(x::AbstractVector{<:Real}, cp::CartesianProduct)::Bool
∈(view(x, n1+1:length(x)), cp.Y)
end

"""
constraints_list(cp::CartesianProduct{N})::Vector{LinearConstraint{N}} where N<:Real
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update (copy the function header here (without function))


Return the list of constraints of a (polytopic) Cartesian product.

### Input

- `cp` -- Cartesian product

### Output

A list of constraints.
"""
function constraints_list(cp::CartesianProduct{N, <:AbstractPolytope})::Vector{LinearConstraint{N}} where N<:Real
return constraints_list(CartesianProductArray([cp.X, cp.Y]))
end

"""
vertices_list(cp::CartesianProduct{N})::Vector{Vector{N}} where N<:Real

Expand Down Expand Up @@ -353,6 +370,42 @@ function ∈(x::AbstractVector{N}, cpa::CartesianProductArray{N, <:LazySet{N}}
return true
end

"""
constraints_list(cpa::CartesianProductArray{N})::Vector{LinearConstraint{N}} where N<:Real
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update


Return the list of constraints of a (polytopic) Cartesian product.

### Input

- `cpa` -- Cartesian product

### Output

A list of constraints.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-picky: empty line

"""
function constraints_list(cpa::CartesianProductArray{N, <:AbstractPolytope})::Vector{LinearConstraint{N}} where N<:Real
# collect low-dimensional constraints lists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant now

c_array = array(cpa)
clist = Vector{LinearConstraint{N}}()
sizehint!(clist, sum(dim(s_low) for s_low in c_array))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that dim(cpa) exists too

prev_step = 1
# create high-dimensional constraints list
for c_low in c_array
c_low_list = constraints_list(c_low)
if !isempty(c_low_list)
indices = prev_step : (dim(c_low_list[1]) + prev_step - 1)
end
for constr in c_low_list
new_constr = LinearConstraint(sparsevec(indices, constr.a), constr.b)
push!(clist, new_constr)
end
prev_step += dim(c_low_list[1])
end

return clist
end

"""
vertices_list(cpa::CartesianProductArray{N})::Vector{Vector{N}} where N<:Real

Expand Down