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

MOI 0.10 upgrade #105

Merged
merged 3 commits into from
Nov 14, 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
Expand Up @@ -25,7 +25,7 @@ CodecZlib = "0.7.0"
Krylov = "0.7.7"
LDLFactorizations = "0.6, 0.7, 0.8"
LinearOperators = "2.0"
MathOptInterface = "0.9.5"
MathOptInterface = "0.10"
QPSReader = "0.2"
TimerOutputs = "0.5.6"
julia = "1.3"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ When using Tulip through JuMP/MOI, parameters can be set either through MOI's ge
```julia
moi_model = Tulip.Optimizer{Float64}()

MOI.set(moi_model, MOI.RawParameter("IPM_IterationsLimit"), 200)
MOI.set(moi_model, MOI.RawOptimizerAttribute("IPM_IterationsLimit"), 200)
```

* Through Tulip's API
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/lp_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ x = MOI.add_variable(lp)
y = MOI.add_variable(lp)

# Set variable bounds
MOI.add_constraint(lp, MOI.SingleVariable(x), MOI.GreaterThan(0.0)) # x >= 0
MOI.add_constraint(lp, MOI.SingleVariable(y), MOI.GreaterThan(0.0)) # y >= 0
MOI.add_constraint(lp, x, MOI.GreaterThan(0.0)) # x >= 0
MOI.add_constraint(lp, y, MOI.GreaterThan(0.0)) # y >= 0

# Add constraints
row1 = MOI.add_constraint(lp,
Expand All @@ -114,7 +114,7 @@ MOI.set(lp, MOI.ObjectiveSense(), MOI.MIN_SENSE)

# Set some parameters
MOI.set(lp, MOI.Silent(), true) # disable output
MOI.set(lp, MOI.RawParameter("Presolve_Level"), 0) # disable presolve
MOI.set(lp, MOI.RawOptimizerAttribute("Presolve_Level"), 0) # disable presolve

# Solve the problem
MOI.optimize!(lp)
Expand Down
4 changes: 2 additions & 2 deletions examples/optimal_other_type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ x = MOI.add_variable(lp)
y = MOI.add_variable(lp)

# Set variable bounds
MOI.add_constraint(lp, MOI.SingleVariable(x), MOI.GreaterThan(T(0))) # x >= 0
MOI.add_constraint(lp, MOI.SingleVariable(y), MOI.GreaterThan(T(0))) # y >= 0
MOI.add_constraint(lp, x, MOI.GreaterThan(T(0))) # x >= 0
MOI.add_constraint(lp, y, MOI.GreaterThan(T(0))) # y >= 0

# Add constraints
row1 = MOI.add_constraint(lp,
Expand Down
5 changes: 3 additions & 2 deletions src/Interfaces/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function MOI.empty!(m::Optimizer)
# Reset bound tracking
m.bnd2name = Dict{MOI.ConstraintIndex, String}()
m.var2bndtype = Dict{MOI.VariableIndex, Set{MOI.ConstraintIndex}}()
return nothing
end

function MOI.is_empty(m::Optimizer)
Expand All @@ -168,10 +169,10 @@ end

MOI.optimize!(m::Optimizer) = optimize!(m.inner)

MOI.Utilities.supports_default_copy_to(::Optimizer, ::Bool) = true
MOI.supports_incremental_interface(::Optimizer) = true

function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike; kwargs...)
return MOI.Utilities.automatic_copy_to(dest, src; kwargs...)
return MOI.Utilities.default_copy_to(dest, src; kwargs...)
end


Expand Down
19 changes: 11 additions & 8 deletions src/Interfaces/MOI/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# =============================================
const SUPPORTED_OPTIMIZER_ATTR = Union{
MOI.NumberOfThreads,
MOI.RawParameter,
MOI.RawOptimizerAttribute,
MOI.SolverName,
MOI.Silent,
MOI.TimeLimitSec
MOI.TimeLimitSec,
}

MOI.supports(::Optimizer, ::A) where{A<:SUPPORTED_OPTIMIZER_ATTR} = true
Expand Down Expand Up @@ -56,9 +56,9 @@ end
#
# RawParameter
#
MOI.get(m::Optimizer, attr::MOI.RawParameter) = get_parameter(m.inner, attr.name)
MOI.get(m::Optimizer, attr::MOI.RawOptimizerAttribute) = get_parameter(m.inner, attr.name)

MOI.set(m::Optimizer, attr::MOI.RawParameter, val) = set_parameter(m.inner, attr.name, val)
MOI.set(m::Optimizer, attr::MOI.RawOptimizerAttribute, val) = set_parameter(m.inner, attr.name, val)


# =============================================
Expand Down Expand Up @@ -114,7 +114,7 @@ function MOI.get(
m::Optimizer{T}, ::MOI.ObjectiveFunctionType
) where{T}
if m._obj_type == _SINGLE_VARIABLE
return MOI.SingleVariable
return MOI.VariableIndex
else
return MOI.ScalarAffineFunction{T}
end
Expand Down Expand Up @@ -148,7 +148,8 @@ end
#
function MOI.get(m::Optimizer{T}, attr::MOI.ObjectiveValue) where{T}
MOI.check_result_index_bounds(m, attr)
return get_attribute(m.inner, ObjectiveValue())
raw_z = get_attribute(m.inner, ObjectiveValue())
return raw_z * !m.is_feas
end

#
Expand All @@ -159,6 +160,8 @@ function MOI.get(m::Optimizer{T}, attr::MOI.DualObjectiveValue) where{T}
return get_attribute(m.inner, DualObjectiveValue())
end

MOI.get(m::Optimizer, ::MOI.ObjectiveBound) = MOI.get(m, MOI.DualObjectiveValue())

#
# RawSolver
#
Expand Down Expand Up @@ -213,7 +216,7 @@ end
#
# TODO: use inner query
function MOI.get(m::Optimizer, attr::MOI.PrimalStatus)
attr.N == 1 || return MOI.NO_SOLUTION
attr.result_index == 1 || return MOI.NO_SOLUTION

if isnothing(m.inner.solution)
return MOI.NO_SOLUTION
Expand All @@ -227,7 +230,7 @@ end
#
# TODO: use inner query
function MOI.get(m::Optimizer, attr::MOI.DualStatus)
attr.N == 1 || return MOI.NO_SOLUTION
attr.result_index == 1 || return MOI.NO_SOLUTION

if isnothing(m.inner.solution)
return MOI.NO_SOLUTION
Expand Down
Loading