-
Notifications
You must be signed in to change notification settings - Fork 10
make setting and getting the objective constant a part of the LQOI interface #44
Conversation
Codecov Report
@@ Coverage Diff @@
## master #44 +/- ##
==========================================
+ Coverage 75.29% 75.35% +0.05%
==========================================
Files 13 13
Lines 1263 1266 +3
==========================================
+ Hits 951 954 +3
Misses 312 312
Continue to review full report at Codecov.
|
Gurobi.jl tests also pass for me with LQOI set to this branch. |
I tried updating Gurobi.jl to overload the functions introduced here by setting model = GurobiOptimizer();
MOI.empty!(model)
MOIU.loadfromstring!(model,"""
variables: x
maxobjective: 1.0x
c1: 1.0x <= 1.0
""")
x = MOI.get(model, MOI.VariableIndex, "x")
Gurobi.set_dblattr!(model.inner, "ObjCon", 1.0) # this works
Gurobi.update_model!(model.inner)
MOI.optimize!(model)
# This assertion passes
@assert MOI.get(model, MOI.ObjectiveValue()) == 2.0 # (1.0 * 1.0 + 1.0)
Gurobi.set_dblattr!(model.inner, "ObjCon", 2.0) # this has no effect
Gurobi.update_model!(model.inner)
MOI.optimize!(model)
# This assertion fails:
@assert MOI.get(model, MOI.ObjectiveValue()) == 3.0 # (1.0 * 1.0 + 2.0) |
Do you have python/gurobipy installed? Otherwise I can have a look when I get back to my desk (edit: to see if it is a gurobi bug) |
Yeah, I'm trying it in python now |
Hm, I'm not sure how to reproduce this in Python, since the API is totally different. I tried doing: from __future__ import print_function
import gurobipy as grb
m = grb.Model("lp")
x = m.addVar(name="x")
obj = 1.0 * x + 1.0
m.setObjective(obj, sense=grb.GRB.MAXIMIZE)
m.addConstr(1.0 * x <= 1.0)
m.optimize()
print("objval:", m.getObjective().getValue())
m.setObjective(1.0 * x + 2.0)
m.optimize()
print("objval:", m.getObjective().getValue()) which works just fine, but that involves replacing the entire objective expression, which isn't what we're doing in Julia. |
In Julia, I get the correct result if I also set the model = GurobiOptimizer();
MOI.empty!(model)
MOIU.loadfromstring!(model,"""
variables: x
maxobjective: 1.0x
c1: 1.0x <= 1.0
""")
x = MOI.get(model, MOI.VariableIndex, "x")
Gurobi.set_dblattr!(model.inner, "ObjCon", 1.0) # this works
Gurobi.update_model!(model.inner)
MOI.optimize!(model)
# This assertion passes
@assert MOI.get(model, MOI.ObjectiveValue()) == 2.0 # (1.0 * 1.0 + 1.0)
Gurobi.set_dblattr!(model.inner, "ObjCon", 2.0)
Gurobi.set_dblattrarray!(model.inner, "Obj", 1, 1, ones(1))
Gurobi.update_model!(model.inner)
MOI.optimize!(model)
@assert MOI.get(model, MOI.ObjectiveValue()) == 3.0 # (1.0 * 1.0 + 2.0) |
Ok, I can reproduce the issue in Python: from __future__ import print_function
import gurobipy as grb
m = grb.Model("lp")
x = m.addVar(name="x")
obj = 1.0 * x + 1.0
m.setObjective(obj, sense=grb.GRB.MAXIMIZE)
m.addConstr(1.0 * x <= 1.0)
m.optimize()
print("ObjVal:", m.getAttr("ObjVal"))
m.setAttr("ObjCon", 2.0)
m.optimize()
print("ObjVal:", m.getAttr("ObjVal")) |
Have you sent them an issue (https://groups.google.com/forum/#!newtopic/gurobi)? Otherwise I'll do it now. |
I just did (but it looks like my message is still being held for moderation) |
Since @joaquimg is happy, would you like me to merge this now or wait for Gurobi? |
I'd say go ahead and merge. The issue with Gurobi is annoying but not related to this PR, and I think this is a good change nonetheless. |
First step for #43