追蹤者

2019年6月30日 星期日

用 Python 做商管程式設計(一) Week 5d

05d-01 存貨政策與自動訂補貨
(Q,R) policy
定義 : 若現貨量 I < Q 則 補貨R件
(s,S) policy
定義 : 若現貨量 I < s  則 補貨至 S 件

Optimizing the (Q,R) policy
    決定 Q 和 R
考量下列 costs
- Inventory cost :  買東西堆在庫房而浪費掉的投資機會
- Ordering cost : 處理貨物的成本
- Shortage cost : 因為沒有賣出去而損失的銷售

例題:
Q = 30 ,一單位貨品買入價1000元,年利率 7.3%,
一次訂貨成本 200,一個顧客來卻缺貨虧 2元,
過去20天需求量如下,20天前的存貨量 為 20件。
求 R 使得總成本最小?
---  code (此程式並沒有加入訂貨成本)
# past sales 
salesStr = "14,23,26,17,17,12,24,19,10,18,22,31,19,16,22,28,20,27,20,32"
sales = salesStr.split(',')
for i in range(len(sales)):
sales[i] = int(sales[i])

#given information 
stgCost = 2
invCost = 1000*0.073/365
Q = 30
I = 20

#finding the best R
bestR = 0
costOfBestR = 1000000000
for R in range(Q):
totalStgCost = 0
totalInvCost = 0

#finding the total cost of this R 
for s in sales:
I -=s
if I < 0 :
totalStgCost += -I * stgCost
I += Q
elif I < R:
I += Q
totalInvCost += I * invCost

#update bestR when necessary
totalCost = totalStgCost + totalInvCost
if totalCost < costOfBestR:
bestR = R
costOfBestR = totalCost
print(R, totalStgCost, totalInvCost, totalCost)
print(bestR)
---

沒有留言:

張貼留言