Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不相交路径算法_Python_Algorithm_Path_Disjoint Sets - Fatal编程技术网

Python 不相交路径算法

Python 不相交路径算法,python,algorithm,path,disjoint-sets,Python,Algorithm,Path,Disjoint Sets,什么是计算和查找扩充路径的最简单方法 利用标记遍历计算边不相交路径寻找增广路径 def paths(G, s, t): # Edge-disjoint path coun H, M, count = tr(G), set(), 0 # Transpose, matching, result while True: # Until the func

什么是计算和查找扩充路径的最简单方法

利用标记遍历计算边不相交路径寻找增广路径

def paths(G, s, t):                           # Edge-disjoint path coun
    H, M, count = tr(G), set(), 0             # Transpose, matching, result
    while True:                               # Until the function returns
        Q, P = {s}, {}                              # Traversal queue + tree
        while Q:                                    # Discovered, unvisited
            u = Q.pop()                             # Get one
            if u == t:                              # Augmenting path!
                count += 1                     # That means one more path
                break                               # End the traversal
            forw = (v for v in G[u] if (u,v) not in M)  # Possible new edges
            back = (v for v in H[u] if (v,u) in M)  # Cancellations
            for v in chain(forw, back):       # Along out- and in-edges
                if v in P: continue           # Already visited? Ignore
                P[v] = u                            # Traversal predecessor
                Q.add(v)                            # New node discovered
        else:                                       # Didn't reach t?
            return count                            # We're donefinnish

我能用我的while循环来芬兰语吗?怎么用?

我试了一下,它成功了

while u != s:    
    u, v = P[u], u
    if v in G[u]:
        M.add((u,v))
else:
    M.remove((v,u))

我试了一下,成功了

while u != s:    
    u, v = P[u], u
    if v in G[u]:
        M.add((u,v))
else:
    M.remove((v,u))