Skip to main content

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

Answered

Comments

1 comment

  • Marika Karbstein
    Gurobi Staff 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

Please sign in to leave a comment.