-
Notifications
You must be signed in to change notification settings - Fork 32
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
Changes from 3 commits
bf12e95
cfb077c
90e59d1
cac3787
ab691af
02e23ed
23f2d6e
ae15a3e
07f512e
3e1b468
720a5ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
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})::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 | ||
|
||
|
@@ -353,6 +370,53 @@ function ∈(x::AbstractVector{N}, cpa::CartesianProductArray{N, <:LazySet{N}} | |
return true | ||
end | ||
|
||
""" | ||
constraints_list(cpa::CartesianProductArray{N})::Vector{LinearConstraint{N}} where N<:Real | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit-picky: empty line |
||
""" | ||
function constraints_list(cpa::CartesianProductArray{N})::Vector{LinearConstraint{N}} where N<:Real | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should better use the interface There is a drawback in this approach (but i don't have a clear picture how to make this play nicely with interfaces), in that the interface restriction i propose will make |
||
# collect low-dimensional constraints lists | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant now |
||
clist_low = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
n = 0 | ||
for c_low in array(cpa) | ||
if c_low isa LinearConstraint | ||
push!(clist_low, [c_low]) | ||
n += 1 | ||
else | ||
constraints = constraints_list(c_low) | ||
push!(clist_low, constraints) | ||
n += length(constraints) | ||
end | ||
end | ||
|
||
clist = Vector{LinearConstraint{N}}() | ||
sizehint!(clist, n) | ||
prev_step = 1 | ||
# create high-dimensional constraints list | ||
for c_low in clist_low | ||
if !isempty(c_low) | ||
indices = prev_step : (dim(c_low[1]) + prev_step - 1) | ||
end | ||
for constr in c_low | ||
new_constr = LinearConstraint(sparsevec(prev_step : (dim(constr) + prev_step-1), constr.a), constr.b) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the |
||
push!(clist, new_constr) | ||
end | ||
prev_step += dim(c_low[1]) | ||
end | ||
|
||
return clist | ||
end | ||
|
||
""" | ||
vertices_list(cpa::CartesianProductArray{N})::Vector{Vector{N}} where N<:Real | ||
|
||
|
There was a problem hiding this comment.
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
))