Adding constraints in R
Answered1) Hi, I am running code that I want to update (add a constraint) to the LP in each iteration. Is there any way to do this? I don't see a Model() function in R so I am not sure if addConstr will work.
2) I want to use the warm start information from prior iterations. Say I supply to the model temp_vbasis and temp_cbasis, I update it as follows (dual_temp is LP result in previous iteration)
temp_vbasis = dual_temp$vbasis; temp_cbasis = c(dual_temp$cbasis, 0).
Will a model update be effectively the same procedure?
-
Hi Siddhaarth,
1) You would have to adjust model$A, model$rhs, model$sense to incorporate the new constraint and then call gurobi(model) to reoptimize. There is no equivalent of the addConstr/AddConstr functions found in the other APIs.
2) This should work
model$vbasis <- temp_vbasis
model$cbasis <- temp_cbasis
# Optimize the model with the warm start
result <- gurobi(model)
Your wings are certainly clipped when using R. I've seen it said that Julia is the spiritual successor to R. Not sure if this is the case or not but it may be worth considering switching, if Python is not an attractive choice. Julia has a relatively strong optimization community (https://jump.dev/ https://discourse.julialang.org/c/domain/opt/13).- Riley
0
Please sign in to leave a comment.
Comments
1 comment