Skip to main content

Slow model building

Awaiting user input

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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.
  • Riley Clement
    • Gurobi Staff

    Hi Vegard,

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

    - Riley

    0
  • Vegard Hansen
    • Gurobi-versary
    • 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

    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

Post is closed for comments.