Python으로 배우는 공급망 분석
Aaren Stubberfield
Supply Chain Analytics Mgr.
상황
제약 문제
B 1단위마다 A 최소 3단위 필요
자주 하는 실수:
from pulp import *
demand = {'A':[0,0,0],'B':[8,7,6]}
costs = {'A':[20,17,18],'B':[15,16,15]}
# Initialize Model
model = LpProblem("Aggregate Production Planning",
LpMinimize)
# Define Variables
time = [0, 1, 2]
prod = ['A', 'B']
X = LpVariable.dicts(
"prod", [(p, t) for p in prod for t in time],
lowBound=0, cat="Integer")
# Define Objective
model += lpSum([costs[p][t] * X[(p, t)]
for p in prod for t in time])
# Define Constraint So Production is >= Demand
for p in prod:
for t in time:
model += X[(p, t)] >= demand[p][t]
for t in time:
model += 3*X[('B',t)] <= X[('A',t)]
B 1단위마다 A가 최소 3단위 있어야 하며, A의 소비자 직판을 반영해야 합니다.
상황
제약 문제
정답 형식
자주 하는 실수
from pulp import *
import pandas as pd
demand = pd.read_csv("Warehouse_Constraint_Demand.csv", index_col=['Product'])
costs = pd.read_csv("Warehouse_Constraint_Cost.csv", index_col=['WH','Product'])
# Initialize Model
model = LpProblem("Distribution Planning", LpMinimize)
# Define Variables
wh = ['W1','W2']
prod = ['A', 'B']
cust = ['C1', 'C2', 'C3', 'C4']
X = LpVariable.dicts("ship", [(w, p, c) for c in cust for p in prod for w in wh],
lowBound=0, cat="Integer")
# Define Objective
model += lpSum([X[(w, p, c)]*costs.loc[(w, p), c]
for c in cust for p in prod for w in wh])
# Define Constraint So Demand Equals Total Shipments
for c in cust:
for p in prod:
model += lpSum([X[(w, p, c)] for w in wh]) == demand.loc[p, c]
제약
model += ((1/12) * lpSum([X['W1', 'A', c] for c in cust])
+ (1/15) * lpSum([X['W1', 'B', c] for c in cust])) <= 4
WH1은 소형으로 주당 A 12개, B 15개, 또는 C 5개만 배송 가능. 4주에 A, B, C의 조합은 무엇이 가능한가?
Python으로 배우는 공급망 분석