Skip to content

Instantly share code, notes, and snippets.

@odow
Last active April 12, 2017 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odow/2dd99948fde8ae8bafc92f3f40d6aa2e to your computer and use it in GitHub Desktop.
Save odow/2dd99948fde8ae8bafc92f3f40d6aa2e to your computer and use it in GitHub Desktop.
# First comment out lines https://github.com/JuliaOpt/Gurobi.jl/blob/master/src/GurobiSolverInterface.jl#L246-L254
using Gurobi,JuMP
# Create the JuMP Model:
# min 0
# s.t.
# x >= 1
# x <= 3
m=Model(solver=GurobiSolver())
@variable(m, x)
@constraints(m, begin
x >= 1
x <= 3
end)
# initialise Gurobi Model
JuMP.build(m)
# Change Gurobi model to
# min -y
# s.t.
# x - y >= 1
# x + y <= 3
# y ∈ [0, 1]
# has optimal solution (x,y) = (2, 1), obj=-1
MathProgBase.addvar!(internalmodel(m), [1, 2], [-1.0, 1.0], 0, 1, -1)
Gurobi.updatemodel!(internalmodel(m))
@assert Gurobi.getobj(internalmodel(m)) == [0.0, -1.0]
@assert Gurobi.getsense(internalmodel(m)) == :Min
@assert Gurobi.num_vars(internalmodel(m).inner) == 2
@assert solve(m) == :Optimal
@assert getobjectivesense(m) == :Min
@assert Gurobi.getobj(internalmodel(m)) == [0.0, -1.0] # fails: reports [0.0, 3.19e-308]
@assert getobjectivevalue(m) == -1 # fails: reports 0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment