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

Adding constraint in gurobipy-pandas with arrays of different lengths

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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.
  • 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

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