diff --git a/src/repelemop.jl b/src/repelemop.jl index 8049d900..d8be2d6f 100644 --- a/src/repelemop.jl +++ b/src/repelemop.jl @@ -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 # ################