-
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
#619 Is intersection empty for polytopes #624
Merged
+121
−4
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3842988
add is intersection empty
mforets 50d701e
Add isempty for polytopes
mforets 01918b1
unit tests and documentation for isempty(::AbstractPolytope)
mforets cd64a1d
add is_intersection_empty for polytopes
mforets 0b0da5b
use test_suite_polyhedra
mforets 32b271f
update vertices list
mforets af0fe5f
add method disambiguation and symmetric function
mforets e02a4e5
add type parameter in interfaces.md
mforets 10715e9
empty line
mforets 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
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
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
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
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 |
---|---|---|
|
@@ -529,3 +529,48 @@ function is_intersection_empty(ls1::LineSegment{N}, | |
return empty_intersection | ||
end | ||
end | ||
|
||
# --- AbstractPolytope --- | ||
|
||
""" | ||
is_intersection_empty(P::AbstractPolytope{N}, | ||
Q::AbstractPolytope{N}, | ||
witness::Bool=false | ||
)::Union{Bool, Tuple{Bool, Vector{N}}} where {N<:Real} | ||
|
||
Check whether a pair of polytopes do not intersect, and otherwise optionally | ||
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. "a pair of" → "two" |
||
compute a witness. | ||
|
||
### Input | ||
|
||
- `P` -- polytope | ||
- `Q` -- another polytope | ||
- `witness` -- (optional, default: `false`) compute a witness if activated | ||
|
||
### Output | ||
|
||
* If `witness` option is deactivated: `true` iff ``P ∩ Q = ∅`` | ||
* If `witness` option is activated: | ||
* `(true, [])` iff ``P ∩ Q = ∅`` | ||
* `(false, v)` iff ``P ∩ Q ≠ ∅`` and ``v ∈ P ∩ Q`` | ||
|
||
### Algorithm | ||
|
||
This is a fallback implementation of the `AbstractPolytope` interface that computes | ||
the concrete intersection, `intersection`, of the given pair of polytopes. If a | ||
witness is required, the first vertex of the resulting intersection polytope is | ||
returned. | ||
""" | ||
function is_intersection_empty(P::AbstractPolytope{N}, | ||
Q::AbstractPolytope{N}, | ||
witness::Bool=false | ||
)::Union{Bool, Tuple{Bool, Vector{N}}} where {N<:Real} | ||
X = intersection(P, Q) | ||
isempty_flag = isempty(X) | ||
if witness | ||
witness_vertex = isempty_flag ? N[] : vertices_list(X)[1] | ||
return (isempty_flag, witness_vertex) | ||
else | ||
return isempty_flag | ||
end | ||
end |
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
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.
I am not sure if this is the correct interpretation. To me, an
HPolytope
/HPolygon
with no constraints is either not defined or universal (because each new constraint removes parts of the set).Also, add a new line at the end of the file.
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.
I agree that the
HPolytope
with no constraints is particular case that could be treated separately as being "universal", the whole R^n.For
VPolytope
, i think it is reasonable to say that if it has no vertices then it only contains the empty set,V = convex_hull{{}}
.I was concerned with the case where the set is defined by a set of constraints with empty intersection. For instance consider the pair of constraints
x <= -1 && x >= 1
: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.
Rather than finding workarounds, we could accept that our algorithms are generally not correct for invalid polytope inputs, like unbounded or contradicting constraints 😉
Sure.
If
HPolytope
andHPolygon
are problematic, should we replaceAbstractPolytope
byUnion{VPolygon, VPolytope}
then? Our other polytopic sets can never be empty by definition anyway.