if path_key == all_child_graphs[j].gp.layer_name:
                                for i in range((len(substitute_paths_in_use[key][path_key]) - 2)):
                                    all_child_graphs[j].ep.residual_capacity[all_child_graphs[j].edge(substitute_paths_in_use[key][path_key][i], substitute_paths_in_use[key][path_key][i + 1])] = 1
                                    all_child_graphs[j].ep.residual_capacity[all_child_graphs[j].edge(substitute_paths_in_use[key][path_key][i + 1], substitute_paths_in_use[key][path_key][i])] = 1
                except Exception, e:
                    print repr(e)

        frequency_n_paths = {}

        ##### Finding all the primary paths possible under various layers#####
        for j in range(number_frequency_bands):
            g = all_child_graphs[j]
            src = g.vertex(request[0])
            tgt = g.vertex(request[1])

            res = boykov_kolmogorov_max_flow(g, src, tgt, g.ep.residual_capacity)
            g.ep.edge_flow.a = g.ep.residual_capacity.a - res.a  # the actual flow

            counter = 0
            for seed_edge in src.out_edges():
                if g.ep.edge_flow[seed_edge] == 1:
                    counter += 1

            for i in range(counter):
                path = []
                current = src
                path.append(src)
                s.push(src)
                while (not(current == tgt)) and (not(s.isEmpty())):
                    for edge in current.out_edges():
                        if g.ep.edge_flow[edge] == 1 and g.ep.residual_capacity[edge] == 1:
Exemple #2
0
    for e in edges:
        edge = g.add_edge(e[0]+1, e[1]+1)
        cap[edge] = e[2]
        edge_cap_text[edge] = str(e[2])

    bottom_states = [23, 24, 30, 46, 74, 57, 3, 79, 55]
    top_states = [17, 47, 5, 70, 2, 71, 14, 72]
    for i in bottom_states:
        e = g.add_edge(0, i)
        cap[e] = 7

    for i in top_states:
        e = g.add_edge(i, len(names)+1)
        cap[e] = 7

    res = gt.boykov_kolmogorov_max_flow(g, source, sink, cap)
    part = gt.min_st_cut(g, source, cap, res)
    mc = sum([cap[e] - res[e] for e in g.edges() if part[e.source()] != part[e.target()]])
    res.a = cap.a - res.a  # the actual flow

    color = g.new_vertex_property("string")
    for i in range(len(names)+2):
        e = g.vertex(i)
        if part[e]:
            color[i] = 'b'
        else:
            color[i] = 'r'
    color[0] = 'black'
    color[len(names)+1] = 'black'

    graph_draw(g, pos=pos, edge_pen_width=prop_to_size(cap, mi=1, ma=10, power=1),