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

Implement issubset between two representations #304

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/repelemop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,53 @@ function Base.issubset(p::Polyhedron, h::HRepElement, solver=Polyhedra.linear_ob
end
end

"""
issubseth(p::Rep, h::HRep)

Returns whether `p` is a subset of `h` by checking whether `p` is a subset of
each hyperplane and halfspace of `h`.
"""
function issubseth(rep::Rep, h::HRep, args...)
f(el) = issubset(rep, el, args...)
return all(f, hyperplanes(h)) && all(f, halfspaces(h))
end

"""
issubsetv(v::VRep, p::Rep)

Returns whether `v` is a subset of `p` by checking whether each line, ray and
point of `v` belongs to `p`.
"""
function issubsetv(v::VRep, rep::Rep, args...)
f(el) = in(el, rep, args...)
return all(f, lines(v)) && all(f, rays(v)) && all(f, points(v))
end

# `issubsetv` would work just as well for this one
# We give a priority to `issubseth` as users are more likely to use
# hyperrectangles that have small H-representation than its polar the
# cross-polytope.
Base.issubset(p::VRepresentation, q::HRepresentation, args...) = issubseth(p, q, args...)
Base.issubset(p::HRepresentation, q::HRepresentation, args...) = issubseth(p, q, args...)
Base.issubset(p::VRepresentation, q::VRepresentation, args...) = issubsetv(p, q, args...)
function Base.issubset(p::HRepresentation, q::VRepresentation, args...)
error("`issubset(h::HRepresentation, v::VRepresentation)` is not supported, use representation conversion for at least one of the two arguments, e.g., by doing `import HiGHS; issubset(h, polyhedron(v), HiGHS.Optimizer)`.")
end

"""
issubset(p::Rep, q::Rep)

Returns whether `p` is a subset of `q`.
"""
function Base.issubset(p::Polyhedron, q::Polyhedron, args...)
# We give a priority to `issubseth` for the same reason as above.
if hrepiscomputed(q) || !(vrepiscomputed(p))
return issubseth(p, q, args...)
else
return issubsetv(p, q, args...)
end
end

################
# INTERSECTION #
################
Expand Down