Skip to main content

How modify RHS

Answered

Comments

7 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    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?.
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    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 = 3

    assuming that \(\texttt{M}\) containts \(\texttt{5}\) as element.

    Best regards,
    Jaromił

    0
  • Cris
    Gurobi-versary
    Curious
    Conversationalist

    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
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    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
  • Cris
    Gurobi-versary
    Curious
    Conversationalist

    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 = 3

    but 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
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    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
  • Cris
    Gurobi-versary
    Curious
    Conversationalist

    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.