I want to make sure I understand correctly the difference between the dual
/shadow_price
returned by JuMP
. Let’s consider the following primal problem:
using JuMP, Gurobi
begin
model = Model(Gurobi.Optimizer)
@variable(model, x[1:3] >= 0)
@objective(model, Max, 5x[1] + 12x[2] + 4x[3])
@constraint(model, c1, x[1]+2x[2]+x[3] <= 10)
@constraint(model, c2, 2x[1] - x[2] + 3x[3] == 8)
optimize!(model)
end
println("Dual c1: ", dual(c1)) # returns -5.8
println("Dual c2: ", dual(c2)) # returns 0.4
println("Shadow price c1: ", shadow_price(c1)) # returns 5.8
println("Shadow price c2: ", shadow_price(c2)) # returns 0.4
Now, let’s solve the dual problem using JuMP
begin
model2 = Model(Gurobi.Optimizer)
@variable(model2, y1 >= 0)
@variable(model2, y2)
@objective(model2, Min, 10y1+8y2)
@constraint(model2, d1, y1+2y2 >= 5)
@constraint(model2, d2, 2y1-y2 >= 12)
@constraint(model2, d3, y1+3y2 >= 4)
optimize!(model2)
end
println("y1: ", value(y1)) # returns 5.8
println("y2: ", value(y2)) # returns -0.4
Now, y1
, y2
correspond to the dual variables for the primal problem, and I was expecting their values to equal values obtained either via dual
or shadow_price
functions; however y1 = shadow_price(c1)
and y2 = -dual(c2) = -shadow_price(c2)
.
I am solving a problem using column generation, and I want to extract the dual variables corresponding to the constraints in the master problem (MP). For my problem, all my constraints are equality constraints (convexity constraints and complicating constraints). So, I just want to solve the primal version of the MP and extract the correct dual variable values using JuMP directly. Which function should I be using (dual
/shadow_price
) and is there anything else I need to be careful about while extracting the dual values?
Thanks!