Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  cplex python API: linear_constraints.add() too slow

    Posted 11/25/17 12:11 PM

    Originally posted by: mtmx89


    Hi all,
    I have some problem with execution time of linear_constraints.add() function with cplex python API.
    I work on very large problems (usually with likely 650k binary + 200k real variables and and 1M of linear constraints), I already optimized, calling that function only one time, using a list of variables names and value (in cplex.sparsepair structure) and other 2 lists for senses and rhs.
    I computed execution time of linear_constraints.add() funtion and it's around 1h 30m.

    I would have this time as low as possible, how can i improve execution time? Are there some "hidden" parameters that could speed up this process? Can I turn off any presolve algorithm at linear_constraints.add() funtion call?

    I really need some hints, Thanks!


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: cplex python API: linear_constraints.add() too slow

    Posted 11/26/17 06:08 PM

    Originally posted by: Slater_jm


    Hi , not sure if u did this, but u should use  index numbers for the variables  instead of  names when u add  them to  the constraints, that decreases the execution time a lot.  U could make a dictionary for that like 

    fromnametoindx = { n : j for j, n in enumerate(c.variables.get_names()) } and then when u start appending variables to  "thevars"  for the constraints ,use  thevars.append(fromnametoindx [varnames]) instead of thevars.append(varnames).

    Other thing u could try is to cythonize the model formulation, but I dont think that could reduce the execution time so much, maybe  it could speed up the creation of the names of your variables


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: cplex python API: linear_constraints.add() too slow

    Posted 11/27/17 12:49 PM

    Originally posted by: mtmx89


    Very good hints, Thank you! Execution time now is 20 s from 1h and a half, Great!


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: cplex python API: linear_constraints.add() too slow

    Posted 11/27/17 01:29 PM

    Originally posted by: Slater_jm


    Nice, glad I could help


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: cplex python API: linear_constraints.add() too slow

    Posted 11/27/17 12:33 PM

    As already mentioned, you should get much better performance using indices rather than names. This is mentioned in the documentation here.


    #CPLEXOptimizers
    #DecisionOptimization