资源简介
Edmonds-karp算法的Python实现版,可用于解决最大流问题,
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Edmonds-Karp algorithm for maximum flow problems.
“““
__author__ = “““ysitu “““
# Copyright (C) 2014 ysitu
# All rights reserved.
# BSD license.
import networkx as nx
from networkx.algorithms.flow.utils import *
__all__ = [‘edmonds_karp‘]
def edmonds_karp_core(R s t cutoff):
“““Implementation of the Edmonds-Karp algorithm.
“““
R_node = R.node
R_pred = R.pred
R_succ = R.succ
inf = R.graph[‘inf‘]
def augment(path):
“““Augment flow along a path from s to t.
“““
# Determine the path residual capacity.
flow = inf
it = iter(path)
u = next(it)
for v in it:
attr = R_succ[u][v]
flow = min(flo
- 上一篇:携程机票python爬取脚本优化版本
- 下一篇:pyltp安装包whl文件.rar
评论
共有 条评论