From 74180f325c84c0897baa15e2b7175bddab9e286f Mon Sep 17 00:00:00 2001 From: mtanneau <9593025+mtanneau@users.noreply.github.com> Date: Thu, 16 Dec 2021 13:52:10 -0500 Subject: [PATCH] Support RawStatusString and SolveTimeSec (#111) * Support MOI.RawStatusString * Support MOI.SolveTimeSec * Bump version --> v0.9.1 --- Project.toml | 2 +- src/Interfaces/MOI/MOI_wrapper.jl | 18 ++++++++++++++---- src/Interfaces/MOI/attributes.jl | 15 ++++++++++++++- src/Tulip.jl | 2 +- test/Interfaces/MOI_wrapper.jl | 9 --------- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Project.toml b/Project.toml index 4eaaa24..19e5995 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Tulip" uuid = "6dd1b50a-3aae-11e9-10b5-ef983d2400fa" authors = ["Mathieu Tanneau "] -version = "0.9.0" +version = "0.9.1" [deps] CodecBzip2 = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd" diff --git a/src/Interfaces/MOI/MOI_wrapper.jl b/src/Interfaces/MOI/MOI_wrapper.jl index 6e1a7ba..6a3cae6 100644 --- a/src/Interfaces/MOI/MOI_wrapper.jl +++ b/src/Interfaces/MOI/MOI_wrapper.jl @@ -106,18 +106,22 @@ mutable struct Optimizer{T} <: MOI.AbstractOptimizer # Keep track of bound constraints var2bndtype::Dict{MOI.VariableIndex, Set{Type{<:MOI.AbstractScalarSet}}} + # Tulip.Model does not record solution time... + solve_time::Float64 + function Optimizer{T}(;kwargs...) where{T} m = new{T}( Model{T}(), false, _SCALAR_AFFINE, # Variable and constraint counters - 0, 0, + 0, 0, # Index mapping MOI.VariableIndex[], Dict{MOI.VariableIndex, Int}(), MOI.ConstraintIndex[], Dict{MOI.ConstraintIndex{MOI.ScalarAffineFunction, <:SCALAR_SETS{T}}, Int}(), # Name -> index mapping Dict{String, MOI.VariableIndex}(), Dict{String, MOI.ConstraintIndex}(), Dict{MOI.ConstraintIndex, String}(), # Variable bounds tracking - Dict{MOI.VariableIndex, Set{Type{<:MOI.AbstractScalarSet}}}() + Dict{MOI.VariableIndex, Set{Type{<:MOI.AbstractScalarSet}}}(), + 0.0 ) for (k, v) in kwargs @@ -146,6 +150,8 @@ function MOI.empty!(m::Optimizer) # Reset bound tracking m.bnd2name = Dict{MOI.ConstraintIndex, String}() m.var2bndtype = Dict{MOI.VariableIndex, Set{MOI.ConstraintIndex}}() + + m.solve_time = 0.0 return nothing end @@ -167,7 +173,11 @@ function MOI.is_empty(m::Optimizer) return true end -MOI.optimize!(m::Optimizer) = optimize!(m.inner) +function MOI.optimize!(m::Optimizer) + t_solve = @elapsed optimize!(m.inner) + m.solve_time = t_solve + return nothing +end MOI.supports_incremental_interface(::Optimizer) = true @@ -197,4 +207,4 @@ include("./constraints.jl") # ============================================================================== # V. Objective # ============================================================================== -include("./objective.jl") \ No newline at end of file +include("./objective.jl") diff --git a/src/Interfaces/MOI/attributes.jl b/src/Interfaces/MOI/attributes.jl index 510e776..bd50f67 100644 --- a/src/Interfaces/MOI/attributes.jl +++ b/src/Interfaces/MOI/attributes.jl @@ -6,6 +6,7 @@ const SUPPORTED_OPTIMIZER_ATTR = Union{ MOI.RawOptimizerAttribute, MOI.SolverName, MOI.SolverVersion, + MOI.SolveTimeSec, MOI.Silent, MOI.TimeLimitSec, } @@ -38,6 +39,11 @@ MOI.get(::Optimizer, ::MOI.SolverName) = "Tulip" # MOI.get(::Optimizer, ::MOI.SolverVersion) = string(Tulip.version()) +# +# SolveTimeSec +# +MOI.get(m::Optimizer, ::MOI.SolveTimeSec) = m.solve_time + # # Silent # @@ -86,7 +92,7 @@ const SUPPORTED_MODEL_ATTR = Union{ MOI.SimplexIterations, MOI.BarrierIterations, MOI.RawSolver, - # MOI.RawStatusString, # TODO + MOI.RawStatusString, MOI.ResultCount, MOI.TerminationStatus, MOI.PrimalStatus, @@ -183,6 +189,13 @@ function MOI.get(m::Optimizer{T}, ::MOI.RelativeGap) where{T} return (abs(zp - zd) / (T(1 // 10^6)) + abs(zd)) end +# +# RawStatusString +# +function MOI.get(m::Optimizer, ::MOI.RawStatusString) + return string(m.inner.status) +end + # # ResultCount # diff --git a/src/Tulip.jl b/src/Tulip.jl index 089c304..73f1c9e 100644 --- a/src/Tulip.jl +++ b/src/Tulip.jl @@ -7,7 +7,7 @@ using SparseArrays using TimerOutputs -version() = v"0.9.0" +version() = v"0.9.1" include("utils.jl") diff --git a/test/Interfaces/MOI_wrapper.jl b/test/Interfaces/MOI_wrapper.jl index cdccfaf..816d7d6 100644 --- a/test/Interfaces/MOI_wrapper.jl +++ b/test/Interfaces/MOI_wrapper.jl @@ -20,9 +20,6 @@ const CONFIG = MOIT.Config(Float64, atol=1e-6, rtol=1e-6, MOIT.runtests( OPTIMIZER, CONFIG, exclude=[ - # already in TODO - "test_attribute_RawStatusString", - "test_attribute_SolveTimeSec", # behaviour to implement: list of model, constraint attributes set "test_model_ListOfConstraintAttributesSet", "test_model_ModelFilter_AbstractModelAttribute", @@ -53,9 +50,6 @@ end MOIT.runtests( BRIDGED, CONFIG, exclude=[ - # already in TODO - "test_attribute_RawStatusString", - "test_attribute_SolveTimeSec", # behaviour to implement: list of model, constraint attributes set "test_conic_NormInfinityCone_3", "test_conic_NormInfinityCone_INFEASIBLE", # should be NO_SOLUTION or INFEASIBLE_POINT @@ -116,9 +110,6 @@ MOIU.@model(ModelData, MOIT.runtests( BRIDGED2, CONFIG, exclude=[ - # already in TODO - "test_attribute_RawStatusString", - "test_attribute_SolveTimeSec", # should be NO_SOLUTION or INFEASIBLE_POINT "test_conic_NormInfinityCone_INFEASIBLE", "test_conic_NormOneCone_INFEASIBLE",