-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bf12e95
added constraints_list for CartesianProduct
kpotomkin cfb077c
added constraints_list for CartesianProductArray
kpotomkin 90e59d1
removed redundant code
kpotomkin cac3787
refactored constraints_list for CartesianProduct
kpotomkin ab691af
Updated method signature
kpotomkin 02e23ed
small changes in comments sections
kpotomkin 23f2d6e
add docs, tests, update signature of the method
kpotomkin ae15a3e
fixed wrong dimension in sparsevec
kpotomkin 07f512e
fixed wrong dimension
kpotomkin 3e1b468
Merge remote-tracking branch 'origin/master' into 753
kpotomkin 720a5ad
minor changes
schillic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,39 @@ 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 | ||
# collect low-dimensional constraints lists | ||
clist_low = (constraints_list(cp.X), constraints_list(cp.Y)) | ||
|
||
clist = Vector{LinearConstraint{N}}() | ||
m = length(clist_low[1]) + length(clist_low[2]) | ||
sizehint!(clist, m) | ||
prev_step = 1 | ||
# create high-dimensional constraints list | ||
for X in 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. Maybe do not use |
||
for constr in X | ||
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. The indices are a constant vector for each if !isempty(X)
indices = prev_step : (dim(X[1]) + prev_step-1)
end
for constr in X
new_constr = LinearConstraint(sparsevec(indices, constr.a), constr.b)
... |
||
push!(clist, new_constr) | ||
end | ||
prev_step += dim(X[1]) | ||
end | ||
|
||
return clist | ||
end | ||
|
||
""" | ||
vertices_list(cp::CartesianProduct{N})::Vector{Vector{N}} where N<:Real | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
))