Skip to main content

How can I set the solution of a model as the upper bound of a variable in the objective of another model?

Answered

Comments

1 comment

  • Marika Karbstein
    Gurobi Staff Gurobi Staff

    If you solved model_1 with \(\texttt{model_1.optimize()}\) make sure it is solved to optimality. Then you can either add the optimal solution value as UB when defining variable z1, e.g.

    if model_1.status == GRB.OPTIMAL:
    z1 = model_2.addVar(lb=model_1.ObjVal) # continuous variable
    model_2.addConstr(z1 = quicksum(x[(1,j,k)] for k in vehicle_types for j in Follow_Trips[1]))

    or add the constraint

    if model_1.status == GRB.OPTIMAL:
     model_2.addConstr(z <= model_1.ObjVal)
    0

Please sign in to leave a comment.