the function of model copying
回答済みhi,
I use the gurobi for python. I want to copy the model, making changes in the original model and the copied model, such as adding different constraints and objective functions.
For example, I have model_1, with variable x,y , the constraint x>0 and the objective min x+y. I want to copy the model as model_2 and model_3, while in model_2, y<1 is added and in model_3, y>1 is added and the objective turns to x+2y. I dont know how to do this.
In the real problem, there are many variables and constraints, and it is not convenient to redefine them.
Thanks
0
-
正式なコメント
Hi Jiakang,
There are several options for this.
- You could use the model.copy() function. This gives you a complete, independent copy of the model. It also means any references to variables/constraints in the original model, will still point to the original model. You should use model.getVarByName() or similar to retrieve variables/constraints in the copy to modify them.
- You could also use the multi-scenario functionality. Here, you first build a base model and then define for each "scenario" how it differs from that base scenario. While you cannot add variables/constraints, the documentation shows how to still achieve the same (see "Tips and tricks").
- Finally, you could treat the models sequentially. If you don't plan on solving them in parallel, you could just define the first model and solve it, store the solution, then modify it to create the second model.
Does one of those options work for you?
Kind regards,
Ronald
サインインしてコメントを残してください。
コメント
1件のコメント