2

I have a very large problem and I am facing computational time issues even in the declaration of the variables in OrTools (>10minutes).

Here is a peace of my code

x = {}
for i in setI:
    for j in setJ:
        x[i,j] = model.NewIntVar(0, 1, 'x[{}]'.format([i,j]))

If a create the same variable using Pyomo I do not face this problem, I believe I am doing something wrong.

Can someone, please, help me to improve the performance of my algorithm?

Thanks

rapha123
  • 179
  • 9
  • I have tried the following x = [model.NewIntVar(0, 1, 'x[{}]'.format([i,j])) for i in setI for j in setJ], but no success – rapha123 Jul 17 '21 at 14:32
  • Not sure if that snippet is enough to provide *helpful* tips due to missing context. In general you should *profile* this to recognize the bottleneck: dict iteration, dict mutation, ortools var-setup, string-formatting. The next step will depend on this analysis. / Somewhat guessing / ignoring context, a pattern like this i'm handling always by replacing `x={}` with `np.empty((len(setI), len(setJ)), dtype=object)`. This implies a need for index-mapping (i in setI -> index 0, next i in setI -> index 1; same for other dim) at some point but might be worth it. ortools will still do mallocs though – sascha Jul 17 '21 at 15:22
  • try not creating a name (using ''). – Laurent Perron Jul 17 '21 at 17:45

0 Answers0