首页 > 其他分享 >GUROBI案例实战(一)——Supply Network Design(网络流模型)

GUROBI案例实战(一)——Supply Network Design(网络流模型)

时间:2024-03-21 13:59:51浏览次数:39  
标签:1.5 F1 Network Supply 0.5 Design D4 D2 D3

GUROBI官方给出的案例,但本篇实现方式与其有些不一样,并且对一些函数给出了解释:ymodeling-examples/supply_network_design/supply_network_design_1.ipynb at master · Gurobi/modeling-examples (github.com)

一、问题描述

给定两个工厂、四个中转站、六个客户:

FactorySupply(最大生产量)
F1 150,000
F2200,000
DepotThroughput(吞吐量:中转站不生产、不消耗资源,只是传递资源)
D170,000
D250,000
D3100,000
D440,000
CustomersDemands(需要的资源)
C150,000
C210,000
C340,000
C435,000
C560,000
C620,000

二、建模

1.集合

工厂集合:f \in F =\left \{ F1,F2 \right \}

中转站集合:d\in D = \left \{ D1, D2, D3, D4\right \}

客户点集合:c \in C=\left \{ C1, C2, C3, C4, C5, C6 \right \}

2.参数

工厂f的最大生产能力 :supply_{f}\in R^{+}

中转站d的最大吞吐量:through_{d}\in R^{+}

客户c的资源需求:demand_{c}\in R^{+}

从节点s到节点t的单位资源的运输成本:cost(s,t) \in R^{+}

3.决策变量

从节点s到节点t运输的资源数量:flow_{s,t}

4.目标函数

最小化总的运输成本: min z = \sum cost_{s,t}*flow_{s,t}

5.约束条件

工厂的产量约束:\sum_{t} flow_{f,t} <= supply_{f}

中转站的吞吐量约束:\sum_{f} flow_{f, d}<=through_{d}

中转站的流量平衡约束:\sum_{f} flow_{f,d} == \sum_{c}flow_{d,c}

客户点的需求约束:\sum_{s}flow_{s,c} == demand_{c}

三、代码实现

import gurobipy as gp
from gurobipy import *
# 参数
supply = dict({
    "F1": 150000,
    "F2": 200000
})

through = dict({
    "D1": 70000,
    "D2": 50000,
    "D3": 100000,
    "D4": 40000
})

demand = dict({
    "C1": 50000,
    "C2": 10000,
    "C3": 40000,
    "C4": 35000,
    "C5": 60000,
    "C6": 20000
})

arcs, cost = gp.multidict({
    ("F1","D1"): 0.5,
    ("F1","D2"):0.5,
    ("F1","D3"): 1.0,
    ("F1","D4"):0.2,
    ("F1","C1"):1.0,
    ("F1","C3"):1.5,
    ("F1","C4"):2.0,
    ("F1","C6"):1.0,
    ("F2","D2"):0.3,
    ("F2","D3"):0.5,
    ("F2","D4"):0.2,
    ("F2","C1"):2.0,
    ("D1","C2"):1.5,
    ("D1","C3"):0.5,
    ("D1","C5"):1.5,
    ("D1","C6"):1.0,
    ("D2","C1"):1.0,
    ("D2","C2"):0.5,
    ("D2","C3"):0.5,
    ("D2","C4"):1.0,
    ("D2","C5"):0.5,
    ("D3","C2"):1.5,
    ("D3","C3"):2.0,
    ("D3","C5"):0.5,
    ("D3","C6"):1.5,
    ("D4","C3"):0.2,
    ("D4","C4"):1.5,
    ("D4","C5"):0.5,
    ("D4","C6"):1.5
})
print(arcs)
# model
model = gp.Model()
# decision var
flow = model.addVars(arcs, vtype = GRB.CONTINUOUS, name = "flow")  # flow为tupledict
print(flow)
# constraints
# factory production
factory = supply.keys()
model.addConstrs((flow.sum(f, "*") <= supply[f] for f in factory), name = "factory constraints")
# depot constraints
depot = through.keys()
model.addConstrs((flow.sum("*", d) <= through[d] for d in depot), name = "depot constraint 1")
model.addConstrs((flow.sum("*", d) == flow.sum(d, "*") for d in depot), name = "depot constraint 2")
# customer constraints
customers = demand.keys()
model.addConstrs((flow.sum("*", c) == demand[c] for c in customers), name = "customers constraints")
# objective
obj = flow.prod(cost)
model.setObjective(obj, GRB.MINIMIZE)

# optimize
model.write("test.lp")
model.update()
model.optimize()

提示:上述代码实现中用到的multidict()、sum()、prod()等在另一篇帖子里有详细介绍

写文章-CSDN创作中心

标签:1.5,F1,Network,Supply,0.5,Design,D4,D2,D3
From: https://blog.csdn.net/qq_44533176/article/details/136854988

相关文章

  • 高速电路顶级会议Design Con历年精选电路设计文章分享
    DesignCon是一个年度的技术会议,专注于高速通信和电子设计领域。该会议旨在为电子工程师、系统设计师、IC设计师、测试和测量工程师等专业人士提供一个交流和学习的平台。DesignCon聚集了来自全球各地的行业专家和领导者,他们分享最新的技术趋势、挑战和解决方案。会议涵盖......
  • System design summary
    systemdesignhttps://github.com/donnemartin/system-design-primerPerformance vs scalabilityscalability这里面的伸缩性是指指标的。当系统有较高的负载时,每个用户仍然能够有较好的响应时,我们说他系统伸缩性强。Performance就是指一个请求的响应越快,自然说性能越高......
  • Meta-Learned Attribute Self-Interaction Network for Continual and GeneralizedZer
    目录摘要介绍releatedworkzero-shotlearning零样本持续学习提出的方法bibtex格式参考文献摘要零样本学习(ZSL)是一种有希望的方法,通过利用类别属性将模型推广到训练期间未见过的类别,但仍然存在挑战。最近,利用生成模型来解决对训练期间已见类别的偏见的方法推动了技......
  • 【EDSR】《Enhanced Deep Residual Networks for Single Image Super-Resolution》
    CVPRworkshops-2017code:https://github.com/limbee/NTIRE2017/tree/masterhttps://github.com/sanghyun-son/EDSR-PyTorch文章目录1BackgroundandMotivation2RelatedWork3Advantages/Contributions4Method4.1Residualblocks4.2Single-scalemodel4.3M......
  • 如何将第三方控件嵌入ToolStrip控件,并提供Design-Time支持
    ToolStripControlHost 旨在通过使用 ToolStripControlHost 构造函数或扩展 ToolStripControlHost 本身来启用任意Windows窗体控件的承载。通过扩展 ToolStripControlHost 并实现公开控件的常用属性和方法的属性和方法,可以更轻松地包装控件。还可以在 ToolStripControlHo......
  • Learning Disentangled Graph Convolutional Networks Locally and Globally论文阅读
    LearningDisentangledGraphConvolutionalNetworksLocallyandGlobally论文阅读笔记Abstract存在的问题:​ 尽管现有的gcn取得了成功,但它们通常忽略了现实世界图中通常出现的纠缠潜在因素,这导致了无法解释的节点表示。更糟糕的是,虽然重点放在局部图信息上,但整个图的全局知......
  • ant design vue动态显示隐藏表格列字段,支持记忆功能
    本文档内容下载:动态显示隐藏表格列字段,支持记忆功能.docx.zip:​​https://url37.ctfile.com/f/8850437-1036113839-678952?p=4760​​(访问密码:4760)链接:​​https://caiyun.139.com/m/i?135CdoJGCdpkg​​新版本以及新版本代码生成,会自动增加该功能,无需额外修改。仅......
  • P2746 [USACO5.3] 校园网Network of Schools 题解
    题目链接:校园网NetworkofSchools这个题得翻译下题目意思才知道在干嘛,题目一开始表明了这个是一个有向图,因为边是单向的。其次关于第一个问题:基于一个事实,如果有\(x\rightarrowy\rightarrowz\),那么只需要\(x\)接受协议,它所在的\(scc\)强连通分量上的点一定都能不需要......
  • KGAT Knowledge Graph Attention Network for Recommendation
    目录概符号说明KGATEmbeddingLayerAttentiveEmbeddingPropagationLayers代码WangX.,HeX.,CaoY.,LiuM.andChuaT.KGAT:Knowledgegraphattentionnetworkforrecommendation.KDD,2019.概知识图谱for推荐系统.符号说明\(\mathcal{G}_1=\{(u,y_{ui}......
  • 使用 Ant Design(Antd)创建精美的界面
    使用AntDesign(Antd)创建精美的界面AntDesign(简称Antd)是一个流行的ReactUI组件库,提供了丰富多样的组件,使得开发人员能够快速构建漂亮的用户界面。在本篇博客中,我们将介绍Antd的基本使用方法,并展示一些常用组件的示例。按钮Antd提供了多种按钮样式,用于满足不同的......