Skip to main content

How can I get the mathematical expression for a specific constraint id?

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Marika Karbstein
    • Gurobi Staff
    1.  You can use the write method to write out your models to a human-readable format

      model.write("myLP.lp")

      You can open the file myLP.lp in any standard text editor and search for the constraint name.
      Or:

    2. You write a script in a similar way as discussed How do I access the left-hand side of a constraint?, for example

      import gurobipy as gp
      m=gp.read("data/glass4.mps")
      m.read("sol.sol")
      m.update()

      con = m.getConstrByName("c15")
      lexpr = m.getRow(con)
      lhs = 0
      for i in range(lexpr.size()):
        coeff = lexpr.getCoeff(i)
        var = lexpr.getVar(i)
        lhs += coeff * var.Start

      print(f"{m.getRow(con)} {con.Sense} {con.RHS}")
      print(f"{lhs} {con.Sense} {con.RHS}")

       

     

    0

Post is closed for comments.