Hi there,
I am trying to extract shadow prices out of a MIQP model. In order to do this I want to “fix” the mixed integer variables after a first solving and then extract the duals.
Here’s a minimal working example:
using JuMP
using Gurobi
model = Model(Gurobi.Optimizer)
@variable(model, x, Bin)
@variable(model, y)
@constraint(model, x * y >= 1)
@constraint(model, c1, x + y <= 6)
@objective(model, Max, y)
optimize!(model)
solution = Dict(v => value(v) for v in all_variables(model))
for v in all_variables(model)
is_binary(v) || continue
unset_binary(v)
fix(v, solution[v]; force=true)
end
new_model = copy(model)
set_optimizer(new_model, Gurobi.Optimizer)
set_optimizer_attribute(new_model, "QCPDual", 1)
optimize!(new_model)
JuMP.shadow_price(new_model[:c1])
However, for larger and more difficult models, QCPDual is not guaranteed to compute duals according to this post.
I was thinking if there is an option to get fully rid of the binary/integer variables and replace those by the result values in order to end up with a full LP. Is there a way to e.g. iterate through my constraints by using e.g. all_constraints(model; include_variable_in_set_constraints=true) replace the variables and afterwards delete the variables from the model?
In the end I would hope to get then a model in this case which looks like this:
@max Dual variable (shadow prices) exists in convex conic programs, not in QP.
Because QP may be convex or nonconvex. Therefore, if you want a dual variable, you should first formulate your problem as a convex quadratic conic program, not only a QP.
If your intention is to get an LP with adjustable parameters, then just natively write a function in which you build this LP, and the function arguments being those parameters.
I don’t think in a realistic operations research problem we will make use of the dual variable of a general QP (or QCQP).
We tend to write dual programs for convex conic programs (including convex SOCP). (Do we also write dual programs for QP? seems exists but I don’t encounter it often).
I have a bit of experience about the Gurobi solver. Sometimes I encounter strange behaviors. Perhaps tuning those parameters could help make it more stable, like Presolve, DualReductions
Thanks for your quick answers! Actually, I cannot provide an easy example where I encounter the failed computation of the Duals by QCPDual…
However, I thought it could be an “easy” way of getting rid of the QP formulations (at least in my usecase). I only have QP formulations in my model where I multiply binaries with linear continuous variables. That’s why I thought I could remove those formulations.