Delete a Constraint
AnsweredHello, I have a column generation problem. I am working matrix and I would like delete a constraint to create another new. I would like to know what is the correct option to do this. I saw in documentation
model.remove(model.getConstrs()[1:3])
but in each iteration y generate more constrains so I will not know the correct i and j.
I would like to know if I use
model.remove(model.getConstrs())
It clears all restrictions in my model.
Best regards and thanks
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Cris,
Yes,
model.remove(model.getConstrs())
removes all constraints from your model.
In order to check what your problem looks like after you removed only a few or all constraints, you can use the Model.write() to write an LP file and examine the file to see whether all desired constraints have been removed.
Best regards,
Jaromił0 -
Thanks for your answer Jaromił.
I Have a question yet. If I call my constraints
master.update()
# Restricciones
R1m = master.addConstrs((quicksum(s[k,t] for k in K) <= PAt[t]) for t in T)
R2m = master.addConstrs((s[k,t] <= M_grande * z[k,t]) for k in K for t in T)
R3m = master.addConstrs((quicksum(Rt[k][m]*s[k,t] for k in K) >= D[m][t]) for m in M for t in T) # Restricción AuxiliarThere is an option to delete just the R3m??. Something like this
model.remove(model.getConstrs(R3m))
I dont know the correct sintax to do that.
(I am using benders decomposition and I need a first solution so I tryed to do some cuts with R3m and then I need delete it)
Best regards and thanks for your answer
0 -
Hi Cris,
You can use
model.remove(R3m)
to remove the \(\texttt{R3m}\) constraints only.
I would again use the Model.write() function to double check whether the correct constraints have been removed.
Best regards,
Jaromił0 -
Thanks for your answer. I try to used Model.write() but I wasn´t too sure of how. I read the link but I wasn´t to clear how to do It. I will try with
model.remove(R3m)
Thanks for your help
0 -
Hi Cris,
The Model.write() function can be used as
model.write("my_LP_before_remove.lp")
model.remove(R3m)
model.write("my_LP_after_remove.lp")The above will generate 2 LP files. You can use the \(\texttt{write}\) function to also write different files. All are summarized in the documentation of the \(\texttt{write}\) function.
Best regards,
Jaromił0 -
Thanks for your help Jaromił. I am going to see it right now
Best regards
Cristian
0
Post is closed for comments.
Comments
7 comments