当前位置:网站首页>干货丨数学规划视角下的分货优化解题思路
干货丨数学规划视角下的分货优化解题思路
2022-08-04 12:22:00 【InfoQ】
一、问题描述
二、构造模型
业务规则1:尽可能满足门店的需求
业务规则2:大仓优先级
业务规则3:最小分货单元
3.代码实现
from coptpy import Envr, COPT
"""
问题参数
"""
# 大仓和门店列表
WH_LIST = ["wh1", "wh2"]
STORE_LIST = ["store1", "store2", "store3"]
# 大仓总量
WH_CAPACITY = {"wh1": 100, "wh2": 300}
# 门店目标库存水平
STORE_TARGET_INV = {"store1": 100, "store2": 80, "store3": 120}
# 门店库存水平
STORE_INV = {"store1": 50, "store2": 20, "store3": 30}
# 大仓优先级
PRIORITY = {
("wh1", "store1"): 0.9,
("wh2", "store1"): 0.1,
("wh1", "store2"): 0.9,
("wh2", "store2"): 0.1,
("wh1", "store3"): 0.05,
("wh2", "store3"): 0.95,
}
# 最小分货单元
MIQ = 6
# 惩罚系数
PENALTY_ORDER = 1
PENALTY_SLACK = 100
"""
创建模型
"""
# 创建模型
env = Envr()
model = env.createModel("xiaomi")
# 生成变量
x_dict = {} # 分货量
x_slack_dict = {} # 分货之后的缺货量
x_int_dict = {} # 为了满足最小分货单元的辅助变量
for i in WH_LIST:
for j in STORE_LIST:
x_dict[i, j] = model.addVar(vtype=COPT.CONTINUOUS, lb=0, name=f"order_{i}_{j}")
x_int_dict[i, j] = model.addVar(vtype=COPT.INTEGER, lb=0, name=f"order_int_{i}_{j}")
for j in STORE_LIST:
x_slack_dict[j] = model.addVar(vtype=COPT.CONTINUOUS, lb=0, name=f"order_slack_{j}")
# 设置目标函数
obj = PENALTY_ORDER * sum([sum([PRIORITY[i, j] * x_dict[i, j] for j in STORE_LIST]) for i in WH_LIST])
obj += PENALTY_SLACK * sum([x_slack_dict[j] for j in STORE_LIST])
model.setObjective(obj, sense=COPT.MINIMIZE)
# 增加约束
for i in WH_LIST:
# 每个大仓的分货总量不能超过限制
model.addConstr(sum([x_dict[i, j] for j in STORE_LIST]) <= WH_CAPACITY[i], f"le_capacity_{i}")
for j in STORE_LIST:
# 每个门店补货之后的库存水平要尽可能超过目标库存水平
model.addConstr(STORE_INV[j] + sum([x_dict[i, j] for i in WH_LIST]) + x_slack_dict[j] >= STORE_TARGET_INV[j], f"target_inventory_{j}")
for i in WH_LIST:
for j in STORE_LIST:
# 每个大仓发给每个门店的分货量要是最小分货单元的倍数
model.addConstr(MIQ * x_int_dict[i, j] == x_dict[i, j], f"miq_{i}_{j}")
"""
模型求解
"""
model.solve()
for i in WH_LIST:
for j in STORE_LIST:
# 获取大仓i发给门店j的分货量
print(f"{i} -> {j}: {x_dict[i, j].x}")4.总结

边栏推荐
猜你喜欢

yolo系列的Neck模块

Based on the BiLSTM regression forecast method

DC-DC电源中前馈电容的选择

推荐一款优秀的通用管理后台

Hit the interview!The latest interview booklet of Ali Jin, nine silver and ten is stable!

JS逆向字体反爬,某供应商平台反爬实践

动规(16)-并查集基础题——格子游戏

244 page PDF!"2022 China cloud computing ecological blue book published

手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果

炫酷又高效的数据可视化大屏,做起来真的没那么难!丨极客星球
随机推荐
开发小程序插件如何实现盈利?
鲜花“刺客”收割七夕
num_workers
接到“网站动态换主题”的需求,我是如何踩坑的
Flutter教程大全合集(2022年版)
WPF 截图控件之画笔(八)「仿微信」
什么是 DevOps?看这一篇就够了!
Focusing on data sources, data quality and model performance to build a credit profile of small and micro enterprises
广告电商系统开发
论文翻译:2022_Time-Frequency Attention for Monaural Speech Enhancement
String is a reference type
shell之循环语句(for、while、until)
MySQL索引原理以及SQL优化
获取本机IP地址的脚本
推荐一款优秀的通用管理后台
缓存字符流
Flutter强大的下拉筛选菜单gzx_dropdown_menu
ES 节点2G内存分析
244 page PDF!"2022 China cloud computing ecological blue book published
Hands-on Deep Learning_LeNet