def test(n):
	g = Graph(n, weighted=False, directed=True)

	g.random_generate()

	print g

	scc(g)

	g.visualize()
Ejemplo n.º 2
0
def test(n):
	g = Graph(n, weighted=False, directed=True)

	g.random_generate(max_degree=20)

	# print g

	# g = simple_graph()

	p = []
	for r in [True, False]:
		try:
			t0 = time.time()
			dfsorder = DFSOrder(g, recursive=r)
		except RuntimeError as e:
			print 'RuntimeError:', e
			continue
		finally:
			print 'running time:', ('%.5f' % (time.time() - t0))

		if n < 20:
			print '     preorder:', dfsorder.preorder
			print '    postorder:', dfsorder.postorder
			print 'rev-postorder:', dfsorder.reversed_postorder
		p.append([dfsorder.preorder, dfsorder.postorder,\
					dfsorder.reversed_postorder])

	if len(p) == 1: # only iterative result
		print 'Iterative running completed'
	else:
		# check if iterative and recursive results are the same
		pre1, post1, rev1 = p[0]
		pre2, post2, rev2 = p[1]

		if (pre1 != pre2 or post1 != post2 or rev1 != rev2):
			print "wrong iterative algorithm"
		else:
			print "OK for this test"