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))