示例#1
0
 def test_detect_no_cycles(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = AcyclicGraphDFS(self.G)
     algorithm.run(1)  # it is safe, because G is connected
     parent_expected = {1: None, 0: 1, 3: 6, 2: 5, 5: 1, 4: 0, 7: 6, 6: 2}
     self.assertEqual(algorithm.parent, parent_expected)
     self.assertTrue(is_acyclic(self.G))
示例#2
0
 def test_detect_no_cycles(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = AcyclicGraphDFS(self.G)
     algorithm.run(1)   # it is safe, because G is connected
     parent_expected = {1: None, 0: 1, 3: 6, 2: 5, 5: 1, 4: 0, 7: 6, 6: 2}
     self.assertEqual(algorithm.parent, parent_expected)
     self.assertTrue(is_acyclic(self.G))
示例#3
0
 def test_detect_no_directed_cycles(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = AcyclicGraphDFS(self.G)
     algorithm.run(0)  # in order to easy test
     parent_expected = {0: None, 2: 1, 1: 0, 4: 0, 3: 2, 6: 5, 5: 4, 7: 5}
     #parent_expected = {0: None, 2: 1, 1: 0, 4: 0, 3: 2, 6: 5, 5: 4, 7: 0}
     self.assertEqual(algorithm.parent, parent_expected)
     self.assertTrue(is_acyclic(self.G))
示例#4
0
 def test_detect_no_directed_cycles(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = AcyclicGraphDFS(self.G)
     algorithm.run(0)   # in order to easy test
     parent_expected = {0: None, 2: 1, 1: 0, 4: 0, 3: 2, 6: 5, 5: 4, 7: 5}
     #parent_expected = {0: None, 2: 1, 1: 0, 4: 0, 3: 2, 6: 5, 5: 4, 7: 0}
     self.assertEqual(algorithm.parent, parent_expected)
     self.assertTrue(is_acyclic(self.G))
示例#5
0
 def test_detect_cycle3(self):
     self.assertEqual(self.G.v(), self.N)
     self.G.add_edge(self.cycle_edges[2])
     algorithm = AcyclicGraphDFS(self.G)
     self.assertRaises(ValueError, algorithm.run)
     self.assertFalse(is_acyclic(self.G))
示例#6
0
 def test_detect_cycle3(self):
     self.assertEqual(self.G.v(), self.N)
     self.G.add_edge(self.cycle_edges[2])
     algorithm = AcyclicGraphDFS(self.G)
     self.assertRaises(ValueError, algorithm.run)
     self.assertFalse(is_acyclic(self.G))
示例#7
0
V = 50
graph_factory = GraphFactory(Graph)
G = graph_factory.make_random(V, False, 0.5)
#G = graph_factory.make_complete(V, False)
#G = graph_factory.make_cyclic(V, False)
E = G.e()
#G.show()

print "Calculate parameters ..."
print "Nodes:", G.v(), V
print "Edges:", G.e(), E
print "Directed:", G.is_directed()
print "Connected:", is_connected(G)
print "Biconnected:", is_biconnected(G)
print "Acyclic:", is_acyclic(G)
print "Bipartite:", is_bipartite(G)
Delta = max(G.degree(node) for node in G.iternodes())
print "Delta:", Delta

print "Testing BoruvkaMST ..."
t1 = timeit.Timer(lambda: BoruvkaMST(G).run())
print V, E, t1.timeit(1)  # single run

print "Testing PrimMST ..."
t1 = timeit.Timer(lambda: PrimMST(G).run())
print V, E, t1.timeit(1)  # single run

print "Testing PrimMSTWithEdges ..."
t1 = timeit.Timer(lambda: PrimMSTWithEdges(G).run())
print V, E, t1.timeit(1)  # single run
示例#8
0
V = 10
graph_factory = GraphFactory(Graph)
G = graph_factory.make_random(V, False, 0.5)
#G = graph_factory.make_complete(V, False)
#G = graph_factory.make_cyclic(V, False)
E = G.e()
#G.show()

print "Calculate parameters ..."
print "Nodes:", G.v(), V
print "Edges:", G.e(), E
print "Directed:", G.is_directed()
print "Connected:", is_connected(G)
print "Biconnected:", is_biconnected(G)
print "Acyclic:", is_acyclic(G)
print "Bipartite:", is_bipartite(G)
Delta = max(G.degree(node) for node in G.iternodes())
print "Delta:", Delta

print "Testing BoruvkaMST ..."
t1 = timeit.Timer(lambda: BoruvkaMST(G).run())
print V, E, t1.timeit(1)            # single run

print "Testing PrimMST ..."
t1 = timeit.Timer(lambda: PrimMST(G).run())
print V, E, t1.timeit(1)            # single run

print "Testing PrimMatrixMST ..."
t1 = timeit.Timer(lambda: PrimMatrixMST(G).run())
print V, E, t1.timeit(1)            # single run
示例#9
0
V = 50
graph_factory = GraphFactory(Graph)
G = graph_factory.make_random(V, False, 0.5)
#G = graph_factory.make_complete(V, False)
#G = graph_factory.make_cyclic(V, False)
E = G.e()
#G.show()

print ( "Calculate parameters ..." )
print ( "Nodes: {} {}".format(G.v(), V) )
print ( "Edges: {} {}".format(G.e(), E) )
print ( "Directed: {}".format(G.is_directed()) )
print ( "Connected: {}".format(is_connected(G)) )
print ( "Biconnected: {}".format(is_biconnected(G)) )
print ( "Acyclic: {}".format(is_acyclic(G)) )
print ( "Bipartite: {}".format(is_bipartite(G)) )
Delta = max(G.degree(node) for node in G.iternodes())
print ( "Delta: {}".format(Delta) )

print ("Testing BoruvkaMST ..." )
t1 = timeit.Timer(lambda: BoruvkaMST(G).run())
print ( "{} {} {}".format(V, E, t1.timeit(1)) )   # single run

print ("Testing PrimMST ..." )
t1 = timeit.Timer(lambda: PrimMST(G).run())
print ( "{} {} {}".format(V, E, t1.timeit(1)) )   # single run

print ("Testing PrimMSTWithEdges ..." )
t1 = timeit.Timer(lambda: PrimMSTWithEdges(G).run())
print ( "{} {} {}".format(V, E, t1.timeit(1)) )   # single run