def run_strongly_connected_components(): resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)) sys.setrecursionlimit(10**6) graph = Graph() with open('data/SCC.txt', 'r') as file: for line in file: vertices = line.split(' ') tail = int(vertices[0]) head = int(vertices[1]) graph.add_edge([tail, head]) print('max vertex: %s' % graph.max_vertex()) graph.reverse() print('edges count: %s' % len(graph.edges)) components = find_components(graph) components.sort(reverse=True) print('components sizes: %s must be [434821, 968, 459, 313, 211]' % components[:5]) print('correct = %s' % are_lists_equal(components[:5], [434821, 968, 459, 313, 211]))
def test_max_vertex(self): g = Graph() g.add_edge([9, 7]) g.add_edge([9, 3]) g.add_edge([7, 1]) g.add_edge([1, 4]) g.add_edge([4, 7]) g.add_edge([3, 6]) g.add_edge([6, 9]) g.add_edge([8, 6]) g.add_edge([8, 5]) g.add_edge([2, 8]) g.add_edge([5, 2]) self.assertEqual(g.max_vertex(), 9)
def test_correctness(self): g = Graph() g.add_edge([7, 1]) g.add_edge([1, 4]) g.add_edge([4, 7]) g.add_edge([9, 7]) g.add_edge([9, 3]) g.add_edge([3, 6]) g.add_edge([6, 9]) g.add_edge([8, 6]) g.add_edge([8, 5]) g.add_edge([2, 8]) g.add_edge([5, 2]) self.assertListEqual(find_components(g), [3, 3, 3])
def test_reverse(self): g = Graph() g.add_edge([7, 1]) g.add_edge([1, 4]) g.add_edge([4, 7]) g.add_edge([9, 7]) g.add_edge([9, 3]) g.add_edge([3, 6]) g.add_edge([6, 9]) g.add_edge([8, 6]) g.add_edge([8, 5]) g.add_edge([2, 8]) g.add_edge([5, 2]) g.reverse() g.reverse() f = copy(g) self.assertDictEqual(g.edges, f.edges)