Skip to main content

Delete a Constraint

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,

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

    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 Auxiliar

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

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

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

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

    Thanks for your help Jaromił. I am going to see it right now

    Best regards

    Cristian

    0

Post is closed for comments.