From 17f3d48765929b0982585e18fa05067e0e50946f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 23 Apr 2022 10:28:31 -0400 Subject: [PATCH 1/2] Implement issubset(::Rep, ::Rep) --- src/repelemop.jl | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/repelemop.jl b/src/repelemop.jl index 8049d900..ad0ea43c 100644 --- a/src/repelemop.jl +++ b/src/repelemop.jl @@ -200,6 +200,50 @@ 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...) + +""" + 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 # ################ From 006ed0bc70450c86c41fb0fe39a031df829c65d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 23 Apr 2022 10:31:16 -0400 Subject: [PATCH 2/2] Add error --- src/repelemop.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/repelemop.jl b/src/repelemop.jl index ad0ea43c..d8be2d6f 100644 --- a/src/repelemop.jl +++ b/src/repelemop.jl @@ -229,6 +229,9 @@ end 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)