Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support RawStatusString and SolveTimeSec #111

Merged
merged 3 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Tulip"
uuid = "6dd1b50a-3aae-11e9-10b5-ef983d2400fa"
authors = ["Mathieu Tanneau <mathieu.tanneau@gmail.com>"]
version = "0.9.0"
version = "0.9.1"

[deps]
CodecBzip2 = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
Expand Down
18 changes: 14 additions & 4 deletions src/Interfaces/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -197,4 +207,4 @@ include("./constraints.jl")
# ==============================================================================
# V. Objective
# ==============================================================================
include("./objective.jl")
include("./objective.jl")
15 changes: 14 additions & 1 deletion src/Interfaces/MOI/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const SUPPORTED_OPTIMIZER_ATTR = Union{
MOI.RawOptimizerAttribute,
MOI.SolverName,
MOI.SolverVersion,
MOI.SolveTimeSec,
MOI.Silent,
MOI.TimeLimitSec,
}
Expand Down Expand Up @@ -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
#
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion src/Tulip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using SparseArrays

using TimerOutputs

version() = v"0.9.0"
version() = v"0.9.1"

include("utils.jl")

Expand Down
9 changes: 0 additions & 9 deletions test/Interfaces/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down