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

define the model as a function

回答済み

コメント

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.
  • Jaromił Najman
    • Gurobi Staff

    You can define your model in a function. You have to make sure that all data is available inside the function. This means that if you need the value of the parameter \(\texttt{CUSTOMERS}\), then you have to either pass it to function VRP1 as an argument, i.e.,

    def VRP1(CUSTOMERS):
    [...]

    or you read you data from a file to get access to it.

    Best regards, 
    Jaromił

    0
  • Shutian Li
    • Gurobi-versary
    • First Question
    • First Comment

    Hi Jaromił,

    Thanks for your response. Are there any methods that allow me to include two or three models that share the same sets? 

    For example, what I want such as: 

    CUSTOMERS = [i for i in range(1,20)]

    def VRP1(): 

    def VRP2(): 

    Thanks! 

    0
  • Jaromił Najman
    • Gurobi Staff

    Are there any methods that allow me to include two or three models that share the same sets? 

    What exactly do you mean by share the same sets?

    You can write multiple functions \(\texttt{VRP1, VRP2, ...}\) and pass your \(\texttt{CUSTOMERS}\) list as argument to each one of those.

    def VRP1(CUSTOMERS):
    [...]

    def VRP2(CUSTOMERS):
    [...]


    CUSTOMERS = [i for i in range(1,20)]
    VRP1(CUSTOMERS)
    VRP2(CUSTOMERS)

    Best regards, 
    Jaromił

    0

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