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

2 comments

  • Official comment
    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.
  • Marika Karbstein
    • 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

Post is closed for comments.