From d7818671a70cc911b2e7991520d0c0672df5949a Mon Sep 17 00:00:00 2001 From: schillic Date: Sat, 6 Apr 2024 23:18:05 +0200 Subject: [PATCH] use exact LP solver for integer sets --- src/Utils/lp_solvers.jl | 4 ++-- test/Utils/lp_solvers.jl | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Utils/lp_solvers.jl b/src/Utils/lp_solvers.jl index ca452fa8ae..46525b53b5 100644 --- a/src/Utils/lp_solvers.jl +++ b/src/Utils/lp_solvers.jl @@ -11,12 +11,12 @@ end end # default LP solver for rational numbers -@inline function default_lp_solver_factory(::Type{<:Rational}) +@inline function default_lp_solver_factory(::Union{Type{<:Rational},Type{Int}}) return JuMP.optimizer_with_attributes(() -> GLPK.Optimizer(; method=GLPK.EXACT)) end @inline task_local_lp_solver_key(::Type{<:AbstractFloat}) = "LAZYSETS_FLOAT_LP_SOLVER" -@inline task_local_lp_solver_key(::Type{<:Rational}) = "LAZYSETS_EXACT_LP_SOLVER" +@inline task_local_lp_solver_key(::Union{Type{<:Rational},Type{Int}}) = "LAZYSETS_EXACT_LP_SOLVER" # default LP solver given two possibly different numeric types @inline function default_lp_solver(M::Type{<:Number}, N::Type{<:Number}) diff --git a/test/Utils/lp_solvers.jl b/test/Utils/lp_solvers.jl index d80be45069..4103a4018d 100644 --- a/test/Utils/lp_solvers.jl +++ b/test/Utils/lp_solvers.jl @@ -1,6 +1,9 @@ -# Check that the default model and explicit solver -# specification works for linprog +# check solver handling +for N in [Float64, Rational{Int}, Int] + LazySets.default_lp_solver(N) +end +# check that the default model and explicit solver specification work for linprog for N in [Float64] p = HPolyhedron{N}() c1 = LinearConstraint(N[2, 2], N(12)) @@ -15,7 +18,10 @@ for N in [Float64] P = HPolyhedron([HalfSpace(N[3 // 50, -4 // 10], N(1)), HalfSpace(N[-1 // 50, 1 // 10], N(-1))]) - # With default model + #################### + # with default model + #################### + # support vector d = N[1, 0] @test σ(d, p) == N[4, 2] @@ -29,7 +35,9 @@ for N in [Float64] # an_element @test an_element(P) ∈ P - # With explicit solver + ###################### + # with explicit solver + ###################### solver = optimizer_with_attributes(() -> GLPK.Optimizer(; method=GLPK.SIMPLEX)) # support vector