Ejemplo n.º 1
0
def test_preflow_push_global_relabel_freq():
    G = nx.DiGraph()
    G.add_edge(1, 2, capacity=1)
    R = preflow_push(G, 1, 2, global_relabel_freq=None)
    assert_equal(R.graph['flow_value'], 1)
    assert_raises(nx.NetworkXError, preflow_push, G, 1, 2,
                  global_relabel_freq=-1)
Ejemplo n.º 2
0
def test_preflow_push_makes_enough_space():
    # From ticket #1542
    G = nx.DiGraph()
    nx.add_path(G, [0, 1, 3], capacity=1)
    nx.add_path(G, [1, 2, 3], capacity=1)
    R = preflow_push(G, 0, 3, value_only=False)
    assert R.graph["flow_value"] == 1
Ejemplo n.º 3
0
def test_preflow_push_makes_enough_space():
    #From ticket #1542
    G = nx.DiGraph()
    G.add_path([0, 1, 3], capacity=1)
    G.add_path([1, 2, 3], capacity=1)
    R = preflow_push(G, 0, 3, value_only=False)
    assert_equal(R.graph['flow_value'], 1)
Ejemplo n.º 4
0
def test_preflow_push_global_relabel_freq():
    G = nx.DiGraph()
    G.add_edge(1, 2, capacity=1)
    R = preflow_push(G, 1, 2, global_relabel_freq=None)
    assert R.graph['flow_value'] == 1
    pytest.raises(nx.NetworkXError, preflow_push, G, 1, 2,
                  global_relabel_freq=-1)
Ejemplo n.º 5
0
def test_preflow_push_makes_enough_space():
    #From ticket #1542
    G = nx.DiGraph()
    nx.add_path(G, [0, 1, 3], capacity=1)
    nx.add_path(G, [1, 2, 3], capacity=1)
    R = preflow_push(G, 0, 3, value_only=False)
    assert_equal(R.graph['flow_value'], 1)
Ejemplo n.º 6
0
def minimum_isolating_cut(graph, source_vertices, sink_vertices):
    """Compute a minimum isolating cut in G.

    The minimum isolating cut is a cut which separates all the source_nodes from all the sink_nodes.

    Params:
        graph: the graph G in which to compute the minimum isolating cut
        source_vertices: vertices required to fall in the source set
        sink_vertices: vertices required to fall in the sink set

    Returns:
        cut_source: the source set of the isolating cut
        cut_weight: the weight of the isolating cut
    """

    # construct auxiliary graph with super-source and super-sink nodes
    graph.add_nodes_from(["s_node", "t_node"])
    graph.add_edges_from([("s_node", source_adj_node)
                          for source_adj_node in source_vertices])
    graph.add_edges_from([(sink_adj_node, "t_node")
                          for sink_adj_node in sink_vertices])

    # find the residual graph after running a maximum flow algorithm
    residual = preflow_push(graph, "s_node", "t_node")

    # remove the edges which are saturated in the residual graph
    cutset = [(u, v, d) for u, v, d in residual.edges(data=True)
              if d["flow"] >= d["capacity"]]
    residual.remove_edges_from(cutset)

    # the sink set is all nodes which are reachable from the super-sink
    #   after the saturated arcs have been removed
    cut_sink = set(nx.shortest_path_length(residual, target="t_node"))
    # the source set is all the nodes which are not in the sink set
    cut_source = set(graph) - cut_sink

    if cutset is not None:
        residual.add_edges_from(cutset)

    # determine the weight of the resulting minimum cut
    cut_weight = residual.graph["flow_value"]

    assert "s_node" in cut_source, " source node not included in source set "
    assert "t_node" in cut_sink, " sink node not included in sink set "

    cut_source -= {"s_node"}
    cut_sink -= {"t_node"}

    graph.remove_nodes_from(["s_node", "t_node"])

    return cut_source, cut_weight
Ejemplo n.º 7
0
 def test_preflow_push_global_relabel(self):
     G = read_graph('gw1')
     R = preflow_push(G, 1, len(G), global_relabel_freq=50)
     assert_equal(R.graph['flow_value'], 1202018)
                'Generator': ['Complete_Graph'],
                'Algorithm': ['Minimum_Cut'],
                'Order':
                i,
                'Density':
                round(C.size() / nx.complete_graph(i).size(), 2),
                'Time':
                execution_time_flow + execution_time_C
            })
            all_data = all_data.append(row)

            #Preflow push Complete Graph
            start_flow = time.time()
            for k in range(5):
                R = preflow_push(C,
                                 ss_list[k][0],
                                 ss_list[k][1],
                                 capacity='weight')
            end_flow = time.time()
            execution_time_flow = end_flow - start_flow

            row = pd.DataFrame({
                'Generator': ['Complete_Graph'],
                'Algorithm': ['Preflow_Push'],
                'Order':
                i,
                'Density':
                round(C.size() / nx.complete_graph(i).size(), 2),
                'Time':
                execution_time_flow + execution_time_C
            })
            all_data = all_data.append(row)
 def test_preflow_push_global_relabel(self):
     G = read_graph('gw1')
     R = preflow_push(G, 1, len(G), global_relabel_freq=50)
     assert_equal(R.graph['flow_value'], 1202018)
 def test_preflow_push_global_relabel(self):
     G = read_graph("gw1")
     R = preflow_push(G, 1, len(G), global_relabel_freq=50)
     assert R.graph["flow_value"] == 1202018
Ejemplo n.º 11
0
 def __find_schedule(self):
     self.residual_network = preflow_push(self.network, "Source", "Sink")