[英]How to limit DCs in transportation optimization problem?
In typical transportation optimization problem, we optimize cost for given sources:(Distribution Centers) and demand:(Stores) points.在典型的运输优化问题中,我们针对给定的来源:(配送中心)和需求:(商店)点优化成本。
In below example, how can we add additional constraint to limit no.在下面的示例中,我们如何添加额外的约束来限制编号。 of Distribution Centers(DC)?配送中心(DC)?
ie Problem:即问题:
if dc_lim=10
total_available_DCs=30
Then Total DCs in optimize network<=dc_lim.
Current Code:当前代码:
model = ConcreteModel()
model.dual = Suffix(direction=Suffix.IMPORT)
# Step 1: Define index sets
CUS = list(I) # Stores
SRC = list(Supply.keys()) # DCs (Distribution Centres)
K=list(Products)
# Step 2: Define the decision
model.x = Var(CUS, SRC,K, domain = NonNegativeReals)
# Step 3: Define Objective
model.Cost = Objective(
expr = sum([T[c,s,k]*model.x[c,s,k] for c in CUS for s in SRC for k in K if (c,s,k) in T]),
sense = minimize)
# Step 4: Constraints
#Supply Constraint
model.src = ConstraintList()
for s in SRC:
model.src.add(sum([model.x[c,s,k] for c in CUS for k in K if (c,s,k) in T]) <= Supply[s])
#Demand Constraint
model.dmd = ConstraintList()
for c in CUS:
for k in K:
model.dmd.add(sum([model.x[c,s,k] for s in SRC if (c,s,k) in T]) == Demand[c,k])
results = SolverFactory('glpk').solve(model)
It is much better to look at the math instead of a bunch of code.看数学而不是一堆代码要好得多。 So here we go.所以这里我们 go。
min sum((c,s,k), T(c,s,k)*x(c,s,k))
sum((c,k), x(c,s,k)) ≤ supply(s) ∀s
sum(s, x(c,s,k)) = demand(c,k) ∀c,k
x(c,s,k) ≤ M(c,s,k)*y(s) ∀c,s,k "if closed don't ship from DC"
sum(s,y(s)) ≤ limit "limit number of open DCs"
y(s) ∈ {0,1} "DC is open or closed"
x(c,s,k) ≥ 0
M(c,s,k) = min(supply(s),demand(c,k)) "constants"
Transcribing this into code is trivial.将其转录成代码是微不足道的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.