How to get the dual of a non convex MIQCP Gurobi

manoj.centura
Thu, 22 May 2025 22:41:51 +0000
Optimization (Mathematical)

hi All,
I need to get the duals of a nonconvex MIQCP i tried below code from

model = Model(Gurobi.Optimizer)
set_optimizer_attribute(model, "NonConvex", 2)
@variable(model, x, Bin)
@variable(model, y >= 0)
@constraint(model, x * y <= 10)  # Non-convex bilinear term
@objective(model, Max, y)

@constraint(model,linear_constraint_name,x+y<=10)
optimize!(model)

# Fix binaries and solve as convex QCP (if possible)
fixed_model = copy(model)
set_optimizer(fixed_model, Gurobi.Optimizer)
set_optimizer_attribute(model, "QCPDual", 1)
fix(x, value(x); force=true)
fix(y, value(y); force=true)
set_optimizer_attribute(fixed_model, "QCPDual", 1)
optimize!(fixed_model)

# Retrieve duals (if convex)
dual_value = shadow_price(fixed_model[:linear_constraint_name])

2 posts - 2 participants