How modify RHS
AnsweredHello. I need help to modify de RHS of a constr. I saw another post but I am not clear. This is my model
model.addConstrs((quicksum(x[i,j] for j in N) <= n*y[i] for i in M),name="Apertura_centro")
I would like to know how to modify the right side of Apertura_centro[5], as example
I saw this https://www.gurobi.com/documentation/8.1/refman/rhs.html
Best regards and thanks for your help.
Cristian
-
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,
For a constraint
c0 = m.addConstr(x + 2 * y + 3 * z <= 4, "c0")
you can modify the right hand side via
c0.rhs = 3
In your case, this would be
Apertura_centro = model.addConstrs((quicksum(x[i,j] for j in N) <= n*y[i] for i in M),name="Apertura_centro")
Apertura_centro[5].rhs = 3assuming that \(\texttt{M}\) containts \(\texttt{5}\) as element.
Best regards,
Jaromił0 -
Ok, perfect. In this case Apertura_centro will be a tuple-dict, where each element will be a constraint and the index???.
If I get a constraint using d = getConstraintbyname("Apertura_centro[5]") and then, I do d.RSH = 3, should be right too??.
Thanks for your answer.
0 -
Hi Cris,
Yes, \(\texttt{Apertura_centro}\) will be a tupledict indexed by \(\texttt{M}\) in your case.
Yes, you can use the getConstrByName function. However, this function requires a call to Model.update() first in order to make the constraint names accessible directly after the addConstrs call. This results in a slower code, which might be fully negligible for your model.
Best regards,
Jaromił0 -
OMG. Thanks for your answer Jaromil. I am doing a Simulated Annealing. The worst problem when I code is I think in many options for do the same in this case change the RHS but I always want to know what is the best way to do it. I tryed to check the gurobi manual, bur somethimes I dont find what I am looking for. In this case the best option was what you had said using
Apertura_centro = model.addConstrs((quicksum(x[i,j] for j in N) <= n*y[i] for i in M),name="Apertura_centro")
Apertura_centro[5].rhs = 3but in the manual I dont see an example like this. I would like to know where I could find examples like this or if It is only practice and time.
Best regards and thanks for always help with Doubts.
Cristian.
0 -
Hi Cris,
The only example where we explicitly set the RHS through an attribute is the multiscenario.py example where attributes are set for particular scenarios in the manner as described in this thread.
I would guess that it is mainly practice, time, and reading needed to fully comprehend the Gurobi API as it has grown throughout the years. Regarding the update call, you might be interested in the documentation of the UpdateMode parameter.
Best regards,
Jaromił0 -
Thanks for your answer Jeromil. I am student yet and I am happy with what I have learned in this time. Thanks for your words and help, as always.
Best regars,
Cristian.
0
Post is closed for comments.
Comments
7 comments