纸浆厂的运输问题涉及到运输的每一个项目。然而,在我的情况下,您使用的每一条路线/车道都有成本,而不是每一个装运的项目,即目标函数是最小化使用的路线(卡车)数量
*即,如果任何路线变量(数量)选择为>;通过优化器0,我希望将相同的成本附加到它,而不考虑数量,否则忽略它(0成本)。 概率+=lpSum([np.最小值(路线变量[w][b],1)路线中(w,b)的成本[w][b]),“总车道”
我尝试使用np.minimum,但解决方案似乎没有考虑到它。替代方案是什么
supply=pd.DataFrame.from_dict({38893: {'location_code': '2025', 'excess_cases': 18.0},
43872: {'location_code': '1580', 'excess_cases': 16.0},
43929: {'location_code': '1036', 'excess_cases': 16.0},
62403: {'location_code': '1607', 'excess_cases': 10.0},
67220: {'location_code': '1983', 'excess_cases': 9.0}}).T
demand=pd.DataFrame.from_dict({12223: {'location_code': '3321', 'deficit_cases': 12.0},
15682: {'location_code': '3077', 'deficit_cases': 9.0},
16147: {'location_code': '1264', 'deficit_cases': 9.0},
18964: {'location_code': '3208', 'deficit_cases': 7.0},
19389: {'location_code': '1031', 'deficit_cases': 7.0}}).T
VendorStores = supply['location_code']
excess = supply.set_index(['location_code'])['excess_cases'].to_dict()
deficitStores = demand['location_code']
deficit = demand.set_index(['location_code'])['deficit_cases'].to_dict()
costs = makeDict((VendorStores, deficitStores),[[1]*len(deficitStores)]*len(VendorStores))
prob = LpProblem("LP Problem",LpMinimize)
Routes = [(w,b) for w in VendorStores for b in deficitStores]
route_vars = LpVariable.dicts("Route",(VendorStores,deficitStores),0,None,LpInteger)
prob += lpSum([np.minimum(route_vars[w][b],1)*costs[w][b] for (w,b) in Routes]), "Total Lanes"
for w in VendorStores:
prob += lpSum([route_vars[w][b] for b in deficitStores]) <= excess[w], "Sum of Cases out of VendorStore {0}".format(str(w))
for b in deficitStores:
prob += lpSum([route_vars[w][b] for w in VendorStores]) >= deficit[b]
你的代码不是很清楚,也不完整;我们不知道成本是多少。例如,请通过解释或使用更清晰的变量名来改进它
要添加一个参数,表示您在何处使用路由,在LP术语中,应满足以下条件:
在这里,如果没有通过路由r运送任何东西,那么r将为零以最小化目标函数,如果
d_r > 0
,那么r将为1,Mr = M
,如果d_r <= M
,这将起作用。因此,这完全取决于您为M选择的值用python术语来说:
相关问题 更多 >
编程相关推荐