我目前正在建模一个供应问题,该问题试图优化将产品从生产工厂转移到仓库以满足销售的铁路时间表。
该模型运行良好(部分归功于SO!),但是我想创建一个变量来显示供应短缺的程度。当前,如果当前库存为0,需求大于0,则该模型无法满足约束条件并返回“不可行”。
我想定义一个变量来捕获短缺,以便即使实现了短缺,最终结果也始终是“最佳”,并显示此程度。
即
desired_output_df.head(10)
>>>
date product current_inventory sales_demand inventory_shortfall
'2020-01-01' 'AFM' 10000 5000 0
'2020-01-02' 'AFM' 5000 5000 0
'2020-01-03' 'AFM' 0 6000 6000
不幸的是,代码量太大,无法创建MRE,因此我希望根据上面和下面的代码,可以控制转向:
# Objective Function
model += pulp.lpSum([
storage_inventory_target_overage[(date, product)]
+ storage_inventory_target_shortage[(date, product)]
+ storage_inventory_shortage[(date, product)]
for date, product in storage_inventory_vars]
), 'Minimise stockpile target shortfalls and excesses'
# Storage plant stockpile target, max/min and shortage constraints
for date, product in storage_inventory_vars:
max_level = storage_stockpile_max[grade]
min_level = 0
target_level = storage_stockpile_target[product]
model += storage_inventory_vars[(date, product)] <= max_level
# Storage Inventory Target Constraints
model += storage_inventory_target_overage[(date, product)] >= 0
model += storage_inventory_target_overage[(date, product)] - binary[(date, product)] * 100000000 <= 0
model += storage_inventory_target_shortage[(date, product)] >= 0
model += storage_inventory_target_shortage[(date, product)] - (1 - binary[(date, product)]) * 10000000 <= 0
model += storage_inventory_vars[(date, product)] >= target_level \
+ storage_inventory_target_overage[(date, product)] \
- storage_inventory_target_shortage[(date, product)]
# storage Inventory Shortages
model += storage_stockpile_shortage[(date, product)] >= 0
model += storage_inventory_vars[(date, product)] <= 0 == storage_stockpile_shortage[(date, product)]
# Sales Demand
# storage stockpile levels must meet sales demand
for date, product in storage_inventory_vars:
pulp.lpSum(storage_inventory_vars[date, product]) >= sales_demand[date][product]
变量storage_stockpile_shortage[(date, product)]
,storage_inventory_target_shortage
和
storage_inventory_target_overage
是我要测量的变量。
非常感谢。