Gurobi python约束中的“缺少约束索引”错误

时间:2018-09-06 20:34:54

标签: python variables constraints mathematical-optimization gurobi

我在jupyter中使用gurobipy来解决一个相对简单的优化问题,当添加我的约束之一时,会得到此“缺少约束索引”。 shipping_volumes和rate_keys是两个常规数据帧。这是我定义参数和二进制变量的方式:

    carriers = ['UPS', 'FedEx', 'USPS'] 
    clients = shipment_volumes['Client_Code'].unique().tolist()
    locations = shipment_volumes['Shipping Location 
    Type'].unique().tolist()
    services = ['1DEA', '1DAM', '1DPM', '2DAM', '2DPM', '3DAY', 'GRND']
    weights = rate_keys['Bill Weight'].unique().tolist()
    zones = rate_keys['Zone'].unique().tolist()
    addresses = ['N', 'Y']

这些是我用来遍历定义参数和决策变量的列表。

  c = list(itertools.product(services, weights,zones,addresses,carriers))
  cost = dict.fromkeys(c, value)

  d = list(itertools.product(clients, locations, services, weights, zones, 
  addresses))
  shipment_frequency = dict.fromkeys(d, 0)

这是我的决策变量:

 assign = m.addVars(clients, locations, services, weights, zones, 
 addresses, carriers, name = "Assign", vtype=GRB.BINARY)

最后,这是引发错误的约束条件:

 m.addConstrs(quicksum(cost[s, w, z, r, 'UPS']*shipment_frequency[i, j, s, w, z, r] * assign[i, j, s, w, z, r, 'UPS'] \
                  for i in clients for j in locations for s in services for w in weights for z in zones for r in addresses ) >= 230000000 , "C01")

AttributeError跟踪(最近一次通话) gurobipy.Model.addConstrs(../../ src / python / gurobipy.c:89382)()

中的model.pxi gurobipy.Model .__ genexpr_key中的

model.pxi(../../ src / python / gurobipy.c:49846)()

AttributeError:“ TempConstr”对象没有属性“ gi_frame”

在处理上述异常期间,发生了另一个异常:

KeyError跟踪(最近一次通话最近)  在()中 ----> 1 m.addConstrs(quicksum(cost [s,w,z,r,'UPS'] * shipment_frequency [i,j,s,w,z,r] * Assign [i,j,s, w,z,r,'UPS']为客户中i的客户端中i的服务中的i,为w中的w的权重,针对区域中r中的r的权重,地址为)> = 230000000,“ C01”)

gurobipy.Model.addConstrs中的

model.pxi(../../ src / python / gurobipy.c:89435)()

KeyError:'缺少约束索引'

0 个答案:

没有答案