Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

网络流工业级应用

License

NotificationsYou must be signed in to change notification settings

LucienShui/flow-network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

网络流的工业级应用

Release DrafterUpload Python Package

使用Dinic 和朴素费用流,算法来自DuckKnowNothing - 网络流

支持平台

在尝试了各种方法之后,GitHub Actions 在 Windows 平台下始终无法正确编译 C++,所以放弃支持 Windows 平台

  • Linux
  • macOS

安装

pip install flow-network

样例代码

fromflow_networkimportMaximumFlow,MinimumCostFlowmf=MaximumFlow(2)# 创建一个包含 2 个点的网络流对象,下标从 0 开始mf.add_edge(0,1,3)# 添加一条从 0 指向 1 的边,容量为 3result=mf.run(0,1)# 指定源点为 0,汇点为 1,跑最大流 & 最小割print(result)# 3foredgeinmf.edges:# 遍历每条边print(edge.u,edge.v,edge.flow,edge.capacity)# 边的起点、终点、流过的流量、最大容量mcf=MinimumCostFlow(2)# 创建一个包含 2 个点的费用流对象,下标从 0 开始mcf.add_edge(0,1,3,2)# 添加一条从 0 指向 1 的边,容量为 3,单位流量的费用为 2flow,cost=mcf.run(0,1)# 指定源点为 0,汇点为 1,跑最大流 & 最小费print(flow,cost)# 3 6foredgeinmcf.edges:print(edge.u,edge.v,edge.flow,edge.capacity,edge.cost)# 边的起点、终点、流过的流量、最大容量、单位流量的费用

测试代码

tests.py

Reference


[8]ページ先頭

©2009-2025 Movatter.jp