JuliaPolyhedra / Polyhedra.jl

Polyhedral Computation Interface
Other
172 stars 27 forks source link

MethodError in sethrep! for intervals #263

Closed mforets closed 3 years ago

mforets commented 3 years ago
julia> using LazySets, Polyhedra

julia> P = LazySets.Interval(1.0, 2.0);

julia> Q = polyhedron(convert(HPolyhedron, P); backend=LazySets.default_polyhedra_backend(P))
Polyhedron Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}:
2-element iterator of Polyhedra.HalfSpace{Float64, StaticArrays.SVector{1, Float64}}:
 HalfSpace([1.0], 2.0)
 HalfSpace([-1.0], -1.0):
2-element iterator of StaticArrays.SVector{1, Float64}:
 [2.0]
 [1.0]

julia> backend = LazySets.default_polyhedra_backend(P)
IntervalLibrary{Float64}()

julia> Q = polyhedron(convert(HPolyhedron, P); backend=backend)
Polyhedron Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}:
2-element iterator of Polyhedra.HalfSpace{Float64, StaticArrays.SVector{1, Float64}}:
 HalfSpace([1.0], 2.0)
 HalfSpace([-1.0], -1.0):
2-element iterator of StaticArrays.SVector{1, Float64}:
 [2.0]
 [1.0]

julia> solver=LazySets.default_lp_solver_polyhedra(Float64; presolve=true)
MathOptInterface.OptimizerWithAttributes(GLPK.Optimizer, Pair{MathOptInterface.AbstractOptimizerAttribute, Any}[MathOptInterface.RawParameter("presolve") => 1])

julia> c, r = Polyhedra.chebyshevcenter(Q, solver)
glp_simplex: unable to recover undefined or non-optimal solution
ERROR: MethodError: no method matching sethrep!(::Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}, ::Polyhedra.Intersection{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}})
Closest candidates are:
  sethrep!(::Any, ::Any, ::Any) at /home/mforets/.julia/packages/Polyhedra/ajeAR/src/defaultlibrary.jl:115
  sethrep!(::DefaultPolyhedron, ::HRepresentation) at /home/mforets/.julia/packages/Polyhedra/ajeAR/src/defaultlibrary.jl:120
  sethrep!(::DefaultPolyhedron, ::HRepresentation, ::Any) at /home/mforets/.julia/packages/Polyhedra/ajeAR/src/defaultlibrary.jl:120
Stacktrace:
 [1] sethrep!(p::Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}, h::Polyhedra.Intersection{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}, red::Polyhedra.Redundancy)
   @ Polyhedra ~/.julia/packages/Polyhedra/ajeAR/src/defaultlibrary.jl:115
 [2] detecthlinearity!(p::Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}, solver::MathOptInterface.OptimizerWithAttributes; verbose::Int64)
   @ Polyhedra ~/.julia/packages/Polyhedra/ajeAR/src/linearity.jl:37
 [3] detecthlinearity!(p::Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}, solver::MathOptInterface.OptimizerWithAttributes)
   @ Polyhedra ~/.julia/packages/Polyhedra/ajeAR/src/linearity.jl:36
 [4] hchebyshevcenter(p::Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}, solver::MathOptInterface.OptimizerWithAttributes; linearity_detected::Bool, kws::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Polyhedra ~/.julia/packages/Polyhedra/ajeAR/src/center.jl:122
 [5] hchebyshevcenter(p::Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}, solver::MathOptInterface.OptimizerWithAttributes)
   @ Polyhedra ~/.julia/packages/Polyhedra/ajeAR/src/center.jl:119
 [6] chebyshevcenter(p::Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}, solver::MathOptInterface.OptimizerWithAttributes; kws::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Polyhedra ~/.julia/packages/Polyhedra/ajeAR/src/center.jl:146
 [7] chebyshevcenter(p::Polyhedra.Interval{Float64, StaticArrays.SVector{1, Float64}, StaticArrays.Size{(1,)}}, solver::MathOptInterface.OptimizerWithAttributes)
   @ Polyhedra ~/.julia/packages/Polyhedra/ajeAR/src/center.jl:145
 [8] top-level scope
   @ REPL[11]:1

Of course, chebyshevcenter should specialize for intervals. Downstream report: https://github.com/JuliaReach/LazySets.jl/pull/2779#issue-688690694

blegat commented 3 years ago

Interval always contained a canonical representation so https://github.com/JuliaPolyhedra/Polyhedra.jl/blob/e772525a61be79b4b023e330b8b106d1b0231dbf/src/interval.jl#L38-L167 should be replaced by a helper functions that are then used by the constructors Interval and by sethrep!/setvrep!. Another option (that might be the long term solution) would be to remove Interval and just use the specialized interval methods for redundancy removal and representation conversion in DefaultPolyhedron