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

callback with variables based on the edges of a graph

回答済み

コメント

4件のコメント

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

    How are you creating the variables based on this tuplelist E? From the code snippets you shared, it's hard to see what might cause the different ordering.

    Cheers,
    Matthias

    0
  • ahmad alanaqreh
    • Gurobi-versary
    • Conversationalist
    • Investigator

    Hi Matthias

    I simply do the following :

    x = {}
    for (i, j) in E:
    x[i, j] = model.addVar(vtype=GRB.BINARY, name="x%d,%d," % (i, j))

    or 

    x = model.addVars(E, vtype=GRB.BINARY, name='x')
    0
  • Matthias Miltenberger
    • Gurobi Staff

    Hi Ahmad,

    dictionaries in Python do not necessarily preserve the order of their elements. You might want to use an OrderedDict, instead:

    from collections import OrderedDict
    [...]
    x = OrderedDict()
    for (i, j) in E:
        x[i, j] = m.addVar(vtype=GRB.BINARY, name="x%d,%d," % (i, j))

    Cheers,
    Matthias

    0

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