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

Adding constraint in gurobipy-pandas with arrays of different lengths

回答済み

コメント

2件のコメント

  • Mario Klostermeier
    • Gurobi-versary
    • First Question
    • First Comment

    Hello,

    this is not perfect but you don't need two loops.

    for i in A:
    model.addLConstr(z >= y[i,:], name=f"G1-{k}")
    0
  • Riley Clement
    • Gurobi Staff

    Hi Koen,

    We need the indices on the series to align to use gurobipy-pandas.  One option is to use pandas.DataFrame.merge to get the alignment although this will drop the "i" index from the resulting dataframe which is not ideal.  There are workarounds to keep the "i" index but it gets clunky.

    A better approach is to align the index of z with y using pandas.Series.reindex

    G1_cons = gppd.add_constrs(  
        model, z.reindex(y.index, level=0), GRB.GREATER_EQUAL, y, name="G1-",
    )

    - Riley

    0

サインインしてコメントを残してください。