精品文档
。
1
欢迎下载
from pulp import *
import numpy as np
from itertools import product
Sale = 3
Production = 3
cost = np.array([[11,10,9],[7,2,4],[3,1,4]])
demand = np.array([5,12,9])
capacity = [8,14,17]
prob = LpProblem("Transportation",LpMinimize)
X
=
LpVariable.dicts("Unit_Cost",
product(range(Sale),
range(Production)),
0,
None)
prob
+=
lpSum(cost[l,
c]
*
X[l,
c]
for
l
in
range(Sale)
for
c
in
range(Production))
for l in range(Sale):
prob += lpSum(1*X[l, c] for c in range(Production)) == demand[l]
for c in range(Production):
prob += lpSum(1*X[l, c] for l in range(Sale)) <= capacity[c]
prob.solve()
solution = []
# Get optimal solution
if LpStatus[prob.status] == "Optimal":
X = {(l, c): value(X[l, c]) for l in range(Sale) for c in range(Production)}