Dear folks,
I like to delete non-binding constraints in an LP, i.e., constraints with zero shadow price, and then re-optimize. I tried:
optimize!( model )
if has_duals( model )
num_cons = num_constraints(model, GenericAffExpr{Float64,VariableRef}, MOI.LessThan{Float64})
less_than_constraints = all_constraints(model, GenericAffExpr{Float64,VariableRef}, MOI.LessThan{Float64})
for i in num_cons:-1:1
if shadow_price(less_than_constraints[i]) == 0
delete(model, less_than_constraints[i])
end
end
end
optimize!( model )
However, after the first constraint is removed the following error is thrown:
ErrorException("The shadow price is not available because no dual result is available.")
What works is pushing the constraints to delete in a vector, and then deleting them all at once:
if has_duals( model )
num_cons = num_constraints(model, GenericAffExpr{Float64,VariableRef}, MOI.LessThan{Float64})
less_than_constraints = all_constraints(model, GenericAffExpr{Float64,VariableRef}, MOI.LessThan{Float64})
non_binding_cons = Any[]
for i in num_cons:-1:1
if shadow_price(less_than_constraints[i]) == 0
push!( non_binding_cons, less_than_constraints[i] )
end
end
delete(model, non_binding_cons)
end
The latter approach, however, does not seem very efficient to me. Do you have any better ideas?
Thanks in advance.