def test_brandes_erlebach(): # Figure 1 chapter 7: Connectivity # http://www.informatik.uni-augsburg.de/thi/personen/kammer/Graph_Connectivity.pdf G = nx.Graph() G.add_edges_from([(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 6), (3, 4), (3, 6), (4, 6), (4, 7), (5, 7), (6, 8), (6, 9), (7, 8), (7, 10), (8, 11), (9, 10), (9, 11), (10, 11)]) for flow_func in flow_funcs: kwargs = dict(flow_func=flow_func) assert_equal(3, local_edge_connectivity(G, 1, 11, **kwargs), msg=msg.format(flow_func.__name__)) assert_equal(3, nx.edge_connectivity(G, 1, 11, **kwargs), msg=msg.format(flow_func.__name__)) assert_equal(2, local_node_connectivity(G, 1, 11, **kwargs), msg=msg.format(flow_func.__name__)) assert_equal(2, nx.node_connectivity(G, 1, 11, **kwargs), msg=msg.format(flow_func.__name__)) assert_equal( 2, nx.edge_connectivity(G, **kwargs), # node 5 has degree 2 msg=msg.format(flow_func.__name__)) assert_equal(2, nx.node_connectivity(G, **kwargs), msg=msg.format(flow_func.__name__))
def avg_node_connectivity(G, I, s): total_connectivity = 0 for t in I: if t != s: total_connectivity += local_node_connectivity(G, s, t) avg_connectivity = total_connectivity / (len(I) - 1) # TODO: normalize return avg_connectivity
def chcekConnectivity(G, startNode): ret = None for u, v in itertools.combinations(startNode, 2): k = local_node_connectivity(G, u, v) if k == 0: ret = False if ret is None: ret = True return ret
def Connectivity(overlap, graph, baseoutput): coverage = 30.0 H = build_auxiliary_node_connectivity(graph) R = build_residual_network(H, 'capacity') with open(baseoutput + '-Connectivity', 'w') as output: for ov in overlap: connect = local_node_connectivity( graph, ov.read1, ov.read2, auxiliary=H, residual=R) / float(coverage) output.write(str(connect) + '\n')
def test_brandes_erlebach(): # Figure 1 chapter 7: Connectivity # http://www.informatik.uni-augsburg.de/thi/personen/kammer/Graph_Connectivity.pdf G = nx.Graph() G.add_edges_from([(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 6), (3, 4), (3, 6), (4, 6), (4, 7), (5, 7), (6, 8), (6, 9), (7, 8), (7, 10), (8, 11), (9, 10), (9, 11), (10, 11)]) for flow_func in flow_funcs: kwargs = dict(flow_func=flow_func) assert_equal(3, local_edge_connectivity(G, 1, 11, **kwargs), msg=msg.format(flow_func.__name__)) assert_equal(3, nx.edge_connectivity(G, 1, 11, **kwargs), msg=msg.format(flow_func.__name__)) assert_equal(2, local_node_connectivity(G, 1, 11, **kwargs), msg=msg.format(flow_func.__name__)) assert_equal(2, nx.node_connectivity(G, 1, 11, **kwargs), msg=msg.format(flow_func.__name__)) assert_equal(2, nx.edge_connectivity(G, **kwargs), # node 5 has degree 2 msg=msg.format(flow_func.__name__)) assert_equal(2, nx.node_connectivity(G, **kwargs), msg=msg.format(flow_func.__name__))
def test_brandes_erlebach(): # Figure 1 chapter 7: Connectivity # http://www.informatik.uni-augsburg.de/thi/personen/kammer/Graph_Connectivity.pdf G = nx.Graph() G.add_edges_from([ (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 6), (3, 4), (3, 6), (4, 6), (4, 7), (5, 7), (6, 8), (6, 9), (7, 8), (7, 10), (8, 11), (9, 10), (9, 11), (10, 11), ]) for flow_func in flow_funcs: kwargs = dict(flow_func=flow_func) errmsg = f"Assertion failed in function: {flow_func.__name__}" assert 3 == local_edge_connectivity(G, 1, 11, **kwargs), errmsg assert 3 == nx.edge_connectivity(G, 1, 11, **kwargs), errmsg assert 2 == local_node_connectivity(G, 1, 11, **kwargs), errmsg assert 2 == nx.node_connectivity(G, 1, 11, **kwargs), errmsg assert 2 == nx.edge_connectivity(G, **kwargs), errmsg assert 2 == nx.node_connectivity(G, **kwargs), errmsg if flow_func is flow.preflow_push: assert 3 == nx.edge_connectivity(G, 1, 11, cutoff=2, **kwargs), errmsg else: assert 2 == nx.edge_connectivity(G, 1, 11, cutoff=2, **kwargs), errmsg
pf_dict[last] += 0 pf_dict[splits[1]] += 0 print # print pf_dict print # Remove nodes with low neighbour count # Donot remove if its destination node. for node in G.nodes(): if len(G.neighbors(node)) < 1 and (not node in dest_as_list): G.remove_node(node) #Save complete graph copy for plotting purposes G_copy = G.copy() print local_node_connectivity(G, "1680", "8867") print minimum_st_node_cut(G, "1680", "8867") # find_cuts(G) fo = open("temp.txt", "w") for mm in all_cut_vertex: fo.write(mm+"\n"); print "number of cuts " + str(len(all_cut_vertex))