How can I set the solution of a model as the upper bound of a variable in the objective of another model?
AnsweredHi!
I have made two models (model_1 and model_2), and this is how their objectives are defined.
VSPz1 = quicksum(VSPx[(1,j,k)] for k in vehicle_types for j in Follow_Trips_VSP[1])
z1 = quicksum(x[(1,j,k)] for k in vehicle_types for j in Follow_Trips[1])
w1 = 5
z2 = quicksum(y[i,r,t,k] for i in N_Depots
for r in R
for t in Follow_trip2chrg[(r,i)]
for k in vehicle_types)
model_1.setObjective(VSPz1, GRB.MINIMIZE)
model_2.setObjective((w1*z1 + z2), GRB.MINIMIZE)
Is there a way I can set the solution of model_1 as the upper bound of z1?
0
-
Official comment
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. -
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.
Comments
2 comments