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

How do I switch the max function from CPLEX OPL to Gurobi?

回答済み

コメント

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?.
  • Jaromił Najman
    • Gurobi Staff

    Hi,

    You have to introduce an auxiliary variable for the max function and an auxiliary variable for each addition because Gurobi's max function only works with single variables. Then you can use the addGenConstrMax function. An example would be

    aux = model.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY, name="auxiliary_variable")

    varList = []
    for i in I:
    for j in J:
    for k in K:
    # introduce auxiliary variable for each sum x_zjk + y_zjk
    # and add it the list
    v = model.addVar(lb=-GRB.INFINITY, ub=GRB.INFINITY)
    model.addConstr(v - x[z][j][k]+y[z][j][k] == 0)
    varList.append(v)

    # introduce the constraint aux = max(varList)
    model.addGenConstrMax(aux, varList, name="maxconstr")

    You can then use the \(\texttt{aux}\) variable whenever you need to use the \(\max \{x_{zjk}+y_{zjk} | z \in Z, j \in J, k \in K\}\) term.

    Best regards,
    Jaromił

    0

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