def test_cut_edges_on_very_deep_graph(self): gr = pygraph.classes.graph.graph() gr.add_nodes(range(0, 5001)) for i in range(0, 5000): gr.add_edge((i, i + 1)) recursionlimit = getrecursionlimit() cut_edges(gr) assert getrecursionlimit() == recursionlimit
def test_cut_edges_on_very_deep_graph(self): gr = pygraph.classes.graph.graph() gr.add_nodes(range(0,5001)) for i in range(0,5000): gr.add_edge((i,i+1)) recursionlimit = getrecursionlimit() cut_edges(gr) assert getrecursionlimit() == recursionlimit
def test_cut_edges_in_hypergraph(self): gr = hypergraph() # Add some nodes / edges gr.add_nodes(range(9)) gr.add_hyperedges(['a1', 'b1', 'c1']) gr.add_hyperedges(['a2', 'b2', 'c2']) # Connect the 9 nodes with three size-3 hyperedges for node_set in [['a1',0,1,2], ['b1',3,4,5], ['c1',6,7,8], ['a2',0,1,2], ['b2',3,4,5], ['c2',6,7,8]]: for node in node_set[1:]: gr.link(node, node_set[0]) # Connect the groups gr.add_hyperedges(['l1','l2']) gr.link(0, 'l1') gr.link(3, 'l1') gr.link(5, 'l2') gr.link(8, 'l2') ce = cut_edges(gr) assert 'l1' in ce assert 'l2' in ce assert len(ce) == 2
def test_cut_edges_in_hypergraph(self): gr = hypergraph() # Add some nodes / edges gr.add_nodes(range(9)) gr.add_hyperedges(['a1', 'b1', 'c1']) gr.add_hyperedges(['a2', 'b2', 'c2']) # Connect the 9 nodes with three size-3 hyperedges for node_set in [['a1', 0, 1, 2], ['b1', 3, 4, 5], ['c1', 6, 7, 8], ['a2', 0, 1, 2], ['b2', 3, 4, 5], ['c2', 6, 7, 8]]: for node in node_set[1:]: gr.link(node, node_set[0]) # Connect the groups gr.add_hyperedges(['l1', 'l2']) gr.link(0, 'l1') gr.link(3, 'l1') gr.link(5, 'l2') gr.link(8, 'l2') ce = cut_edges(gr) assert 'l1' in ce assert 'l2' in ce assert len(ce) == 2
def test_cut_edges_in_graph(self): gr = testlib.new_graph() gr.add_nodes(['x','y']) gr.add_edge(('x','y')) gr.add_edge(('x',0)) gr_copy = deepcopy(gr) ce = cut_edges(gr) for each in ce: before = number_of_connected_components(connected_components(gr)) gr.del_edge(each) number_of_connected_components(connected_components(gr)) > before gr = gr_copy
def test_cut_edges_in_graph(self): gr = testlib.new_graph() gr.add_nodes(['x', 'y']) gr.add_edge(('x', 'y')) gr.add_edge(('x', 0)) gr_copy = deepcopy(gr) ce = cut_edges(gr) for each in ce: before = number_of_connected_components(connected_components(gr)) gr.del_edge(each) number_of_connected_components(connected_components(gr)) > before gr = gr_copy
def main(source_file): print_timing('Started') parser = make_parser() # Construct the graph from highways to find cut edges: gr = graph() parser.setContentHandler(HighwayGraphBuilder(gr)) # Looks like building the graph is about linear in time! parser.parse(source_file) print_timing('Graph built, %d nodes, %d edges' % (len(gr.nodes()), len(gr.edges()) / 2)) # Find cut edges and collect them to a set our_cut_edges = set(cut_edges(gr)) print_timing("Cut edges: %d" % len(our_cut_edges)) # Do the second pass and output changed highways add_tagged_ways(source_file, our_cut_edges) print_timing('Marked')