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

Slow model building

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

コメント

3件のコメント

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Vegard,

    That does sound unusually slow.  Can you show us how you are creating the variables?

    - Riley

    0
  • Vegard Hansen
    First Comment
    First Question

    I am building the variables like this:

    l = dict.fromkeys((g,k) for g in all_generations for k in production_schedules[g])
      for g in all_generations:
          for k in production_schedules[g]:
                l[(g,k)] = problem.addVar(name = 'lambda({},{})'.format(g,k))

    The model building scales very badly with the nr of columns k, already at k > 50 it starts getting quite slow.
    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Without seeing the entire code, and the data structures you are using it is hard to say what the cause is.  Are you using pandas anywhere?

    In your code snippet for building variables you can replace the first line with

    l = dict()

    and the last line with

    l[g,k] = problem.addVar(name = 'lambda({},{})'.format(g,k))

    The first thing I would do is invoke the golden rule of computers and turn it off and on again.  I'm wondering if you are running low on memory and a reset could help.

    The second thing I would do is record the time taken for each chunk of code, so you can narrow down where the issue is:

    import time

    # stuff here

    start_time = time.time()
    # build variables
    end_time = time.time()
    execution_time = end_time - start_time
    print(f"Variable creation time: {execution_time} seconds")

    start_time = time.time()
    # first set of constraints
    end_time = time.time()
    execution_time = end_time - start_time
    print(f"First constraints creation time: {execution_time} seconds")

    # and so on...

    - Riley

     

    0

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