Removing few variable from optimization model
ユーザーの入力を待っています。I have the following list of Gurobi decision variables.
<Gurobi.Var DV[May2021, Journey1]>,
<Gurobi.Var DV[May2021, Journey2]>,
<Gurobi.Var DV[May2021, Journey3]>,
<Gurobi.Var DV[june2021, Journey1]>,
<Gurobi.Var DV[june2021, Journey2]>,
<Gurobi.Var DV[june2021, Journey3]>,
<Gurobi.Var DV[july2021, Journey1]>,
<Gurobi.Var DV[july2021, Journey2]>,
<Gurobi.Var DV[july2021, journey3]>,
<Gurobi.Var DV[aug2021, Journey1]>,
<Gurobi.Var DV[aug2021, Journey2]>,
<Gurobi.Var DV[aug2021, Journey3]
I want to remove some variables & reoptimize the model.I am trying to remove/drop multiple decision variables from model. I can use remove to remove variables one by one model.remove(DV[July2021, Journey2]). but, I want to remove
- all decision variables which has Journey2 in their 2nd index.
- Also, I want to remove all decision variables any month before june2021 in their 1st index. so, final variables list should be like the following
<Gurobi.Var DV[june2021, Journey1]>,
<Gurobi.Var DV[june2021, Journey3]>,
<Gurobi.Var DV[july2021, Journey1]>,
<Gurobi.Var DV[july2021, journey3]>,
<Gurobi.Var DV[aug2021, Journey1]>,
<Gurobi.Var DV[aug2021, journey3]
-
正式なコメント
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Tanmoy,
I am afraid you cannot delete variables when the optimization is running.
Judging from the context of your post I assume you would like to remove variables after one optimization call has concluded. This can be done using model.remove(), as you suggested.
There are several methods to achieve your objective. For an illustrative example (in no way optimized for performance), I am going to assume that you store your variables in a dictionary DV:
model.remove([DV[month, journey] for month, journey in DV.keys() if month == "june2021" or journey == "Journey2"])
Best regards
Jonasz1 -
Thanks for your reply, Jonasz. Sorry for the confusion. I am aiming to rerun the model once an optimal solution is found (& then drop some variables from the model). So, I am going to try your suggested approach now.
But, journey2 is the 1st DV in the current optimal solution. So, adding "journey2" manually for comparison will NOT work for me. Can you please suggest me how can get "journey2" text from solution of the model?
<Gurobi.Var DV[june2021, Journey2]>,
0 -
I'm not sure I understood your question, but let me give it a try.
Each variable has a VarName attribute. You could iterate over all the variables of the model, and check if "Journey2" is included in the VarName. To access variable by name, you could try model.getVarByName() method.
Best regards,
Jonasz1
投稿コメントは受け付けていません。
コメント
4件のコメント