メインコンテンツへスキップ

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

回答済み

コメント

2件のコメント

  • 正式なコメント
    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

投稿コメントは受け付けていません。