代码 基于产线产能限制的 多条产线产品消耗半成品生产成品的 月度需求拆分到每天
时间: 2024-05-05 20:17:12 浏览: 14
以下是一种可能的 Python 代码实现,基于线性规划模型:
```python
from pulp import *
# 月度需求数据
monthly_demand = {
'product1': 5000,
'product2': 8000,
'product3': 6000
}
# 半成品库存数据
semi_finished_inventory = {
'A': 10000,
'B': 15000
}
# 生产线产能数据
production_capacity = {
'line1': 1000,
'line2': 1500,
'line3': 1200
}
# 半成品消耗数据
semi_finished_consumption = {
'product1': {'A': 2, 'B': 1},
'product2': {'A': 3, 'B': 2},
'product3': {'A': 1, 'B': 2}
}
# 定义线性规划模型
model = LpProblem('Production Plan', LpMinimize)
# 定义变量
days = range(1, 31)
products = list(monthly_demand.keys())
semi_finished = list(semi_finished_inventory.keys())
product_production = LpVariable.dicts('Production', (days, products), lowBound=0, cat='Integer')
semi_finished_consumed = LpVariable.dicts('Consumption', (days, semi_finished, products), lowBound=0, cat='Integer')
semi_finished_inventory_end = LpVariable.dicts('InventoryEnd', semi_finished, lowBound=0, cat='Integer')
# 目标函数
model += lpSum([product_production[d][p] for d in days for p in products])
# 约束条件
for d in days:
# 产线产能限制
model += lpSum([product_production[d][p] for p in products]) <= lpSum([production_capacity[l] for l in production_capacity])
# 月度需求拆分到每天
for p in products:
model += lpSum([semi_finished_consumed[d][s][p] for s in semi_finished]) == monthly_demand[p] / 30
model += product_production[d][p] == lpSum([semi_finished_consumed[d][s][p] * semi_finished_consumption[p][s] for s in semi_finished])
# 半成品消耗
for s in semi_finished:
model += semi_finished_inventory_end[s] == lpSum([semi_finished_consumed[d][s][p] * semi_finished_consumption[p][s] for p in products]) + semi_finished_inventory[s]
model += semi_finished_inventory_end[s] >= 0
# 求解线性规划模型
model.solve()
# 输出结果
for p in products:
print(p + ':')
for d in days:
print('\tDay {}: Production = {}, Consumption = {}'.format(d, int(product_production[d][p].varValue), int(lpSum([semi_finished_consumed[d][s][p].varValue for s in semi_finished]))))
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)