Improving Performance CP-SAT model

800 views
Skip to first unread message

Azat Zeinolla

unread,
Nov 20, 2018, 5:32:55 AM11/20/18
to or-tools-discuss
Hello, I'm relatively new to using ortools. And from what I've heard from community it is very fast/efficient library to use, which means it's most likely i'm doing something wrong.
Could you take a look at my model and say if i'm doing something wrong. Sorry for not a technical question.

When I used it for a planning horizon of 1 year it solved problem relatively fast, in like 90 secondish. But making it just 2 years instead of 1 year, made it run indefinetly long.
Could you tell If I'm missing something about the usage of library, or simply I modelled it wrong. Thank you, and sorry for not a technical question.

#Variables
z = {}
for c in tblocks:
        for t in months:
            z[(c,t)] = model.NewIntVar(0, 1, 'C'+ str(c) + 'T' + str(t))
zS = {}
for c in tblocks:
    zS[(c,1,2)] = 0
    for t in range(2,num_month+1):
        zS[(c,t,2)] = z[(c,t-1)] 

for c in tblocks:
    for i in range(3,mon_num.max()+1):
        for j in range(i):
            zS[(c,j+1,i)] = 0
        for t in range(i,num_month+1):
            zS[(c,t,i)] = zS[(c,t-1,i-1)]

#1
for c in tblocks:
    model.Add(sum(z[(c,t)] for t in months)<=1)
print('constraint 1 created ' + str(time.time()-starttime))
#2
for d in range(num_years):
    model.Add((sum(z[(c,t+1)]*tblock_life.loc[(c,1)].i00_u_life for c in tblocks for t in range(d*12,(d+1)*12)) + sum(zS[(c,t+1,i)]*tblock_life.loc[(c,i)].i00_u_life for c in tblocks for t in range(d*12,(d+1)*12) for i in range(2,num_month+1))) >=2500)
print('constraint 2 created ' + str(time.time()-starttime))
#3
for t in months:
    model.Add((sum(z[(c,t)]*tblock_life.loc[(c,1)].i00_pr_chas_plan for c in tblocks) + sum(zS[(c,t,i)]*tblock_life.loc[(c,i)].i00_pr_chas_plan for c in tblocks for i in range(2,num_month+1))) <=2400)
print('constraint 3 created ' + str(time.time()-starttime))

#obj
model.Minimize(sum(z[(c,t)] for c in tblocks for t in months))
solver = cp_model.CpSolver()
status = solver.Solve(model)
print('calculation complete ' + str(time.time()-starttime))




Laurent Perron

unread,
Nov 20, 2018, 6:47:48 AM11/20/18
to or-tools...@googlegroups.com
Even if it is fast, the problems are still exponential.
So in theory, increasing the size of the problem by 1 double the solving time, so doubling the size...

A few comments:
  - you problem is purely linear, you may want to use a MIP solver for that
  - with your current model, you can try adding:

solver.num_search_workers = 8

before calling solve.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages