Skip to content

Commit

Permalink
updates to MOI 06 (#157)
Browse files Browse the repository at this point in the history
* updates to MOI 06

* comments by @mlubin
  • Loading branch information
vitornesello authored and mlubin committed Sep 20, 2018
1 parent 4a66f1a commit 120d606
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.6
MathProgBase 0.5 0.8
Compat 0.33
LinQuadOptInterface 0.3 0.4
LinQuadOptInterface 0.4 0.5
6 changes: 2 additions & 4 deletions src/MOIWrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function LQOI.get_primal_status(model::Optimizer)
elseif is_mip(model.inner) && get_sol_count(model.inner) > 0
return MOI.FeasiblePoint
else
return MOI.UnknownResultStatus
return MOI.NoSolution
end
end

Expand Down Expand Up @@ -488,13 +488,11 @@ function hasprimalray(model::Optimizer)
end
end

MOI.free!(m::Optimizer) = free_model(m.inner)

# ==============================================================================
# Callbacks in Gurobi
# ==============================================================================
struct CallbackFunction <: MOI.AbstractOptimizerAttribute end
function MOI.set!(m::Optimizer, ::CallbackFunction, f::Function)
function MOI.set(m::Optimizer, ::CallbackFunction, f::Function)
set_callback_func!(m.inner, f)
update_model!(m.inner)
end
Expand Down
26 changes: 13 additions & 13 deletions test/MOIWrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ end
@testset "Gurobi Callback" begin
@testset "Generic callback" begin
m = Gurobi.Optimizer(OutputFlag=0)
x = MOI.addvariable!(m)
MOI.addconstraint!(m, MOI.SingleVariable(x), MOI.GreaterThan(1.0))
MOI.set!(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
x = MOI.add_variable(m)
MOI.add_constraint(m, MOI.SingleVariable(x), MOI.GreaterThan(1.0))
MOI.set(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.ScalarAffineFunction{Float64}(
[MOI.ScalarAffineTerm{Float64}(1.0, x)],
0.0
Expand All @@ -114,7 +114,7 @@ end
nothing
end

MOI.set!(m, Gurobi.CallbackFunction(), callback_function)
MOI.set(m, Gurobi.CallbackFunction(), callback_function)
MOI.optimize!(m)

@test length(cb_calls) > 0
Expand Down Expand Up @@ -178,7 +178,7 @@ end
end
end

MOI.set!(m, Gurobi.CallbackFunction(), callback_function)
MOI.set(m, Gurobi.CallbackFunction(), callback_function)
MOI.optimize!(m)

@test MOI.get(m, MOI.VariablePrimal(), x) == 1
Expand Down Expand Up @@ -211,10 +211,10 @@ end
Heuristics=0.0,
Presolve=0)
N = 100
x = MOI.addvariables!(m, N)
x = MOI.add_variables(m, N)
for xi in x
MOI.addconstraint!(m, MOI.SingleVariable(xi), MOI.ZeroOne())
MOI.set!(m, MOI.VariablePrimalStart(), xi, 0.0)
MOI.add_constraint(m, MOI.SingleVariable(xi), MOI.ZeroOne())
MOI.set(m, MOI.VariablePrimalStart(), xi, 0.0)
end
# Given a collection of items with individual weights and values,
# maximize the total value carried subject to the constraint that
Expand All @@ -226,10 +226,10 @@ end
end
item_weights = rand(N)
item_values = rand(N)
MOI.addconstraint!(m,
MOI.add_constraint(m,
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(item_weights, x), 0.0),
MOI.LessThan(10.0))
MOI.set!(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.set(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(.-item_values, x), 0.0))
MOI.optimize!(m)

Expand All @@ -242,13 +242,13 @@ end

@testset "Constant objective (issue #111)" begin
m = Gurobi.Optimizer()
x = MOI.addvariable!(m)
MOI.set!(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
x = MOI.add_variable(m)
MOI.set(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{Float64}[], 2.0))
@test MOI.get(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}()).constant == 2.0
@test Gurobi.get_dblattr(m.inner, "ObjCon") == 2.0

MOI.modify!(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), MOI.ScalarConstantChange(3.0))
MOI.modify(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), MOI.ScalarConstantChange(3.0))
@test MOI.get(m, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}()).constant == 3.0
@test Gurobi.get_dblattr(m.inner, "ObjCon") == 3.0
end

0 comments on commit 120d606

Please sign in to comment.