Skip to content

Commit

Permalink
Merge pull request #3292 from JuliaReach/schillic/solvers
Browse files Browse the repository at this point in the history
Outsource solver code to separate file
  • Loading branch information
schillic authored Apr 16, 2023
2 parents 3bea5bb + efebdcd commit 33cc2d2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 41 deletions.
8 changes: 0 additions & 8 deletions src/Initialization/init_Polyhedra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ eval(quote
using .Polyhedra: HRep, VRep,
removehredundancy!, removevredundancy!

function default_polyhedra_backend(P::LazySet{N}) where {N}
if LazySets.dim(P) == 1
return default_polyhedra_backend_1d(N)
else
return default_polyhedra_backend_nd(N)
end
end

function default_polyhedra_backend_1d(N::Type{<:Number}, solver=nothing)
return Polyhedra.IntervalLibrary{N}()
end
Expand Down
33 changes: 0 additions & 33 deletions src/Interfaces/AbstractPolyhedron_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,6 @@ export constrained_dimensions,
an_element,
vertices_list

# default LP solver for floating-point numbers
function default_lp_solver(N::Type{<:AbstractFloat})
JuMP.optimizer_with_attributes(() -> GLPK.Optimizer(method=GLPK.SIMPLEX))
end

# default LP solver for rational numbers
function default_lp_solver(N::Type{<:Rational})
JuMP.optimizer_with_attributes(() -> GLPK.Optimizer(method=GLPK.EXACT))
end

# helper function given two possibly different numeric types
function default_lp_solver(M::Type{<:Number}, N::Type{<:Number})
return default_lp_solver(promote_type(M, N))
end

# Polyhedra backend (fallback method)
function default_polyhedra_backend(P::LazySet{N}) where {N}
require(@__MODULE__, :Polyhedra; fun_name="default_polyhedra_backend")
error("no default backend for numeric type $N")
end

# default LP solver for Polyhedra (fallback method)
# NOTE: exists in parallel to `default_lp_solver` because we use different
# interfaces (see #1493)
function default_lp_solver_polyhedra(N; kwargs...)
require(@__MODULE__, :Polyhedra; fun_name="default_lp_solver_polyhedra")
error("no default solver for numeric type $N")
end

function _is_polyhedra_backend(backend)
return false
end

isconvextype(::Type{<:AbstractPolyhedron}) = true

is_polyhedral(::AbstractPolyhedron) = true
Expand Down
10 changes: 10 additions & 0 deletions src/Interfaces/LazySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ true
"""
isconvextype(X::Type{<:LazySet}) = false

# Polyhedra backend (fallback method)
function default_polyhedra_backend(P::LazySet{N}) where {N}
require(@__MODULE__, :Polyhedra; fun_name="default_polyhedra_backend")
if LazySets.dim(P) == 1
return default_polyhedra_backend_1d(N)
else
return default_polyhedra_backend_nd(N)
end
end

# Note: this method cannot be documented due to a bug in Julia
function low(X::LazySet, i::Int)
return _low(X, i)
Expand Down
1 change: 1 addition & 0 deletions src/LazySets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ include("Utils/numbers.jl")
include("Utils/helper_functions.jl")
include("Utils/macros.jl")
include("Utils/matrix_exponential.jl")
include("Utils/lp_solvers.jl")
include("Utils/file_formats.jl")

# ==================
Expand Down
27 changes: 27 additions & 0 deletions src/Utils/lp_solvers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# default LP solver for floating-point numbers
function default_lp_solver(::Type{<:AbstractFloat})
JuMP.optimizer_with_attributes(() -> GLPK.Optimizer(method=GLPK.SIMPLEX))
end

# default LP solver for rational numbers
function default_lp_solver(::Type{<:Rational})
JuMP.optimizer_with_attributes(() -> GLPK.Optimizer(method=GLPK.EXACT))
end

# default LP solver given two possibly different numeric types
function default_lp_solver(M::Type{<:Number}, N::Type{<:Number})
return default_lp_solver(promote_type(M, N))
end

# check for Polyhedra backend (fallback method)
function _is_polyhedra_backend(backend)
return false
end

# default LP solver for Polyhedra (fallback method)
# NOTE: exists in parallel to `default_lp_solver` because we use different
# interfaces (see #1493)
function default_lp_solver_polyhedra(N, kwargs...)
require(@__MODULE__, :Polyhedra; fun_name="default_lp_solver_polyhedra")
error("no default solver for numeric type $N")
end

0 comments on commit 33cc2d2

Please sign in to comment.