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

Efficient alternative to model.getCoeff

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • 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?.
  • Matthias Miltenberger
    • Gurobi Staff

    Hi Georg,

    You could do something like this:

    rows = [model.getRow(c) for c in model.getConstrs()]
    for row in rows:
    coeffs = {row.getVar(i).varname: row.getCoeff(i) for i in range(row.size())}
    coeffs
    {'x1': -1.0, 'x10': 1.0}

    You might also find model.getA() interesting.

    Cheers,
    Matthias

    0
  • Georg Wicke
    • Gurobi-versary
    • First Comment
    • First Question

    That's about what I was looking for - thanks a ton!

    I would suggest some API to get the LinExpr for a constraint on the constraint object itself, though; I expected to be able to access the LHS in the same spot as the RHS and the sense. Gurobi's API generally shines by its object-orientedness, which is somewhat broken in this spot.

    0

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