i made right set, but there is key error in gurobipy
I made linear program model in gurobipy like this
def cal_gl_1():
m = gp.Model('Inventory')
s=['AUC','ADU','CF','LT'] #AUC: average unit cost, ADU: annual dollar usage, CF: critical factor, LT: lead time
item_number=list(range(1,11))
def cal_s_1():
s_auc=[71.21, 58.45, 40.82, 19.86, 86.50, 71.2, 78.4, 51.68, 14.66, 72]
list_key = [('AUC',1),('AUC',2),('AUC',3),('AUC',4),('AUC',5),('AUC',6),('AUC',7),
('AUC',8),('AUC',9),('AUC',10)]
auc=dict(zip(list_key,s_auc))
return auc
Lj = m.addVars(item_number,lb=0, name ="lamda" )
ACU=cal_s_1()
for r in s[0]:
m.addConstrs(gp.quicksum(Lj[j]*ACU[r,j])>=ACU[r,j] for j in item_number)
obj=(Lj[j].sum(j,'*') for j in item_number)
m.setObjective(obj, GRB.MINIMIZE)
m.optimize()
data_all.append(m.objVal)
return data_all
However there is keyerror.
KeyError: ('A', 1)
I think there right key ('AUC',1)...('AUC',10). I don't know which is wrong.
The problem is probably here:
for r in s[0]:
Try:
for r in s:
Else r
will be ['A', 'U', 'C']
and not ['AUC','ADU','CF','LT']
.
But maybe you want to constraints only for 'AUC'
. In this case, use:
for r in ['AUC']:
or r = 'AUC'
without loop.