Skip to content

Commit

Permalink
Support RawStatusString and SolveTimeSec (#111)
Browse files Browse the repository at this point in the history
* Support MOI.RawStatusString

* Support MOI.SolveTimeSec

* Bump version --> v0.9.1
  • Loading branch information
mtanneau authored Dec 16, 2021
1 parent 309d35d commit 74180f3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
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

2 comments on commit 74180f3

@mtanneau
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/50695

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.1 -m "<description of version>" 74180f325c84c0897baa15e2b7175bddab9e286f
git push origin v0.9.1

Please sign in to comment.