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

Accessing indexed variables systematically after a run?

回答済み

コメント

2件のコメント

  • 正式なコメント
    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?.
  • Eli Towle
    • Gurobi Staff

    To clarify, you are looking for a way to iterate over certain groups of variables in your model?

    Model.addVars() returns a tupledict object containing the newly added variables. If you create a Python variable to store this tupledict, you can use it to iterate over the group of variables you are interested in. For example:

    import gurobipy as gp


    m = gp.Model()

    x = m.addVars(3, name='x')
    y = m.addVars(4, name='y')
    z = m.addVars(5, 5, name='z')

    m.optimize()

    for v in x.values():
    print(v.VarName, v.X)

    prints only the names and optimal values of the three \( \texttt{x} \) variables:

    x[0] 0.0
    x[1] 0.0
    x[2] 0.0
    0

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