代码 基于产线产能限制的 多条产线 生产 多种产品和半成品 将月度成品和半成品需求拆分到每天,满足切换产线次数少,且考虑半成品初始库存量
时间: 2024-05-22 20:16:31 浏览: 83
基于生产线方式的软件开发
# 假设有两条产线和两种产品和半成品,每天产能为10个
# 月度成品和半成品需求
demand = {
'product1': 100,
'product2': 80,
'semifinished1': 50,
'semifinished2': 40
}
# 半成品初始库存量
semifinished_inventory = {
'semifinished1': 10,
'semifinished2': 20
}
# 计算每种半成品产生的成品个数
semifinished_product_ratio = {
'semifinished1': {'product1': 2, 'product2': 3},
'semifinished2': {'product1': 4, 'product2': 1}
}
# 每种产品和半成品需要的时间
time_required = {
'product1': 1,
'product2': 2,
'semifinished1': 1,
'semifinished2': 2
}
# 每条产线的产能
production_capacity = 10
# 初始化每天的生产计划和半成品库存
daily_plan = {}
semifinished_inventory_daily = semifinished_inventory.copy()
# 计算总需求量
total_demand = sum(demand.values())
# 计算每天需要生产的总量
production_per_day = total_demand // 30 + 1
# 循环每天进行生产计划
for day in range(1, 31):
# 初始化每天的生产计划
daily_plan[day] = []
# 计算当天需要生产的产品和半成品数量
daily_demand = {}
for item in demand:
daily_demand[item] = demand[item] // 30 + 1
# 减去已经生产的数量
for plan in daily_plan.values():
for item in plan:
daily_demand[item] -= 1
# 计算当天需要的半成品数量
semifinished_demand = {}
for semifinished in semifinished_product_ratio:
semifinished_demand[semifinished] = 0
for product in semifinished_product_ratio[semifinished]:
semifinished_demand[semifinished] += daily_demand[product] * semifinished_product_ratio[semifinished][product]
# 减去半成品库存中的数量
for semifinished in semifinished_inventory_daily:
semifinished_demand[semifinished] -= semifinished_inventory_daily[semifinished]
# 循环产线进行生产
while sum(daily_demand.values()) > 0 or sum(semifinished_demand.values()) > 0:
# 判断需要生产哪种产品或半成品
to_produce = None
for item in daily_demand:
if daily_demand[item] > 0:
to_produce = item
break
for semifinished in semifinished_demand:
if semifinished_demand[semifinished] > 0:
to_produce = semifinished
break
# 判断产线是否可以生产该产品或半成品
can_produce = False
for line in range(1, 3):
if production_capacity - len(daily_plan[day]) >= time_required[to_produce]:
can_produce = True
break
# 如果可以生产,则进行生产
if can_produce:
for line in range(1, 3):
if production_capacity - len(daily_plan[day]) >= time_required[to_produce]:
daily_plan[day].append(to_produce)
if to_produce in daily_demand:
daily_demand[to_produce] -= 1
if to_produce in semifinished_demand:
semifinished_demand[to_produce] -= 1
if to_produce in semifinished_inventory_daily:
semifinished_inventory_daily[to_produce] -= 1
# 输出当天的生产计划和半成品库存
print('Day', day, 'production plan:', daily_plan[day], 'semifinished inventory:', semifinished_inventory_daily)
阅读全文