Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucienshui/flow-network
网络流工业级应用
https://github.com/lucienshui/flow-network
algorithm flow-network
Last synced: 3 days ago
JSON representation
网络流工业级应用
- Host: GitHub
- URL: https://github.com/lucienshui/flow-network
- Owner: LucienShui
- License: apache-2.0
- Created: 2020-10-05T14:04:25.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-23T12:02:35.000Z (over 3 years ago)
- Last Synced: 2024-11-10T22:15:45.326Z (5 days ago)
- Topics: algorithm, flow-network
- Language: Python
- Homepage: https://pypi.org/project/flow-network/
- Size: 74.2 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flow Network
网络流的工业级应用
![Release Drafter](https://github.com/LucienShui/flow-network/workflows/Release%20Drafter/badge.svg)
![Upload Python Package](https://github.com/LucienShui/flow-network/workflows/Upload%20Python%20Package/badge.svg)使用 `Dinic` 和朴素费用流,算法来自 [DuckKnowNothing - 网络流](https://github.com/UPCACM/DuckKnowNothing/tree/master/src/GraphAlgorithm/%E7%BD%91%E7%BB%9C%E6%B5%81)
## 支持平台
> 在尝试了各种方法之后,GitHub Actions 在 Windows 平台下始终无法正确编译 C++,所以放弃支持 Windows 平台
+ Linux
+ macOS## 安装
```bash
pip install flow-network
```## 样例代码
```python
from flow_network import MaximumFlow, MinimumCostFlowmf = MaximumFlow(2) # 创建一个包含 2 个点的网络流对象,下标从 0 开始
mf.add_edge(0, 1, 3) # 添加一条从 0 指向 1 的边,容量为 3
result = mf.run(0, 1) # 指定源点为 0,汇点为 1,跑最大流 & 最小割
print(result) # 3for edge in mf.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,单位流量的费用为 2
flow, cost = mcf.run(0, 1) # 指定源点为 0,汇点为 1,跑最大流 & 最小费
print(flow, cost) # 3 6for edge in mcf.edges:
print(edge.u, edge.v, edge.flow, edge.capacity, edge.cost) # 边的起点、终点、流过的流量、最大容量、单位流量的费用
```### 测试代码
[tests.py](./flow_network/tests.py)
## Reference
+ [How to use C++ classes with ctypes?](https://stackoverflow.com/questions/1615813/how-to-use-c-classes-with-ctypes)
+ [Calling C/C++ from Python?](https://stackoverflow.com/questions/145270/calling-c-c-from-python)
+ [C Class Instance from Void Pointer using Ctypes](https://stackoverflow.com/questions/19389124/c-class-instance-from-void-pointer-using-ctypes)
+ [Python 库打包分发、setup.py 编写、混合 C 扩展打包的简易指南(转载)](https://www.cnblogs.com/xueweihan/p/12030457.html)
+ [Binary wheel can't be uploaded on pypi using twine](https://stackoverflow.com/questions/59451069/binary-wheel-cant-be-uploaded-on-pypi-using-twine)
+ [Manylinux wheel builder](https://github.com/Niraj-Kamdar/manylinux-wheel-builder)