メインコンテンツへスキップ

Removing few variable from optimization model

ユーザーの入力を待っています。

コメント

4件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Jonasz Staszek
    • Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    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
    Jonasz

     

    1
  • Tanmoy Das
    • Gurobi-versary
    • Investigator
    • Collaborator

    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
  • Jonasz Staszek
    • Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    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,
    Jonasz

    1

投稿コメントは受け付けていません。