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

Is it possible to retrieve variables as tuplelist outside the model definition scope in gurobipy?

回答済み

コメント

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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Matthias Miltenberger
    • Gurobi Staff

    Hi Runqiu,

    You can store the data structure containing the variables as a new member of the model object:

    def model_create_and_solve():
    m = gp.Model()
    # add vars...
    x = m.addVars(station_station_indices, vtype=GRB.BINARY, name="visit_truck")
    # ...more vars...
    # add constraints...
    # add objectives...
    m.optimize()
    # store interesting variables for later inspection
    m._x = x
    return m

    def result_post_process(m):
    # process to output the results based on values of the variables
    x = m._x
    ...

    Alternatively, you could also return the variables separately with the model. Keeping a reference in the model itself is probably easier, though.

    I hope that helps.

    Cheers,
    Matthias

    0

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