写一段python代码:钢带辐射形轮胎每周补给进货,其需求量如我的电脑桌面“a.xlsx”表所示。假定:补给进货的订货提前期为1至3天,当前有7个库存轮胎且无订单,发出一个订单的费用是20元,每天每个轮胎的库存费是0.02元,每当不能满足一位顾客的需求时,顾客就离开,假定每位离开的顾客给公司带来8元的损失,公司每周运营7天,每天24小时。请确定订货量和订货点以减少总费用和平均费用。
时间: 2023-06-15 15:08:37 浏览: 64
这是一个典型的库存管理问题,可以使用经典的EOQ模型来解决。
首先,我们需要读取“a.xlsx”表中的需求量数据,可以使用pandas库完成:
```python
import pandas as pd
df = pd.read_excel('a.xlsx', sheet_name='Sheet1')
demand = df['Demand'].tolist()
```
然后,我们需要定义一些参数:
```python
# 每周运营天数
DAYS = 7
# 每天运营小时数
HOURS = 24
# 每个轮胎的库存费用
HOLDING_COST = 0.02
# 发出一个订单的费用
ORDER_COST = 20
# 每位离开的顾客对公司的损失
LOST_PROFIT = 8
# 当前库存数量
current_inventory = 7
# 订货提前期
LEAD_TIME = 3
# 订货点
reorder_point = LEAD_TIME * sum(demand) / (DAYS * HOURS) + current_inventory
```
接下来,我们可以计算最优订货量Q和最小总费用:
```python
import math
# 计算最优订货量
Q = math.sqrt(2 * LEAD_TIME * sum(demand) * ORDER_COST / HOLDING_COST)
# 修正为整数
Q = int(Q)
# 计算最小总费用
total_cost = ORDER_COST * sum(demand) / Q + HOLDING_COST * Q / 2
```
最后,我们可以模拟一周的库存变化和顾客的需求,并计算平均费用:
```python
import random
# 模拟一周的库存变化和顾客的需求
lost_profit = 0
for day in range(DAYS):
inventory = current_inventory
for hour in range(HOURS):
# 减少库存
inventory -= demand[day * HOURS + hour]
if inventory < 0:
# 不能满足顾客的需求,顾客离开
lost_profit += LOST_PROFIT
inventory = 0
# 判断是否需要订货
if inventory <= reorder_point:
# 订货
inventory += Q
current_inventory = inventory
# 计算平均费用
average_cost = total_cost / sum(demand) + HOLDING_COST * Q / 2 / sum(demand) + lost_profit / sum(demand)
```
完整代码如下:
相关推荐
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)