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

define the model as a function

回答済み

コメント

3件のコメント

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

サインインしてコメントを残してください。