Ejemplo n.º 1
0
 def run(self, root=None):
     """Executable pseudocode."""
     if root is None:
         algorithm = TreeCenter(self.graph)
         algorithm.run()
         root = algorithm.tree_center[0]
     self.plot(root, 0, 6, level=0)
Ejemplo n.º 2
0
 def test_center_two2(self):
     T = Graph(2)
     T.add_edge(Edge(0, 1))
     algorithm = TreeCenter(T)
     algorithm.run()
     self.assertEqual(algorithm.tree_center, [0, 1])
     self.assertEqual(algorithm.tree_radius, 1)
Ejemplo n.º 3
0
 def test_center_two2(self):
     T = Graph(2)
     T.add_edge(Edge(0, 1))
     algorithm = TreeCenter(T)
     algorithm.run()
     self.assertEqual(algorithm.tree_center, [0, 1])
     self.assertEqual(algorithm.tree_radius, 1)
Ejemplo n.º 4
0
 def test_center_two(self):
     self.G.add_edge(Edge(6, 7))
     algorithm = TreeCenter(self.G)
     algorithm.run()
     self.assertEqual(algorithm.tree_center, [4, 5])
     self.assertEqual(algorithm.tree_radius, 3)
Ejemplo n.º 5
0
 def test_center_one(self):
     self.assertEqual(self.G.e(), self.N-1)
     algorithm = TreeCenter(self.G)
     algorithm.run()
     self.assertEqual(algorithm.tree_center, [4])
     self.assertEqual(algorithm.tree_radius, 2)
Ejemplo n.º 6
0
#!/usr/bin/python

import unittest
import timeit
from graphtheory.structures.edges import Edge
from graphtheory.structures.graphs import Graph
from graphtheory.forests.treecenter import TreeCenter
from graphtheory.structures.factory import GraphFactory

V = 1000  # liczba wierzcholkow
E = V - 1  # liczba krawedzi
graph_factory = GraphFactory(Graph)
G = graph_factory.make_tree(V)
#G.show()

print("Calculate parameters ...")
print("Nodes: {} {}".format(G.v(), V))
print("Edges: {} {}".format(G.e(), E))
assert G.v() == V
assert G.e() == E
print("Directed: {}".format(G.is_directed()))
print("Delta: {}".format(max(G.degree(node) for node in G.iternodes())))

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

# EOF
Ejemplo n.º 7
0
 def test_cycle(self):
     self.G.add_edge(Edge(2, 4))
     algorithm = TreeCenter(self.G)
     self.assertRaises(ValueError, algorithm.run)
Ejemplo n.º 8
0
 def test_center_two(self):
     self.G.add_edge(Edge(6, 7))
     algorithm = TreeCenter(self.G)
     algorithm.run()
     self.assertEqual(algorithm.tree_center, [4, 5])
     self.assertEqual(algorithm.tree_radius, 3)
Ejemplo n.º 9
0
 def test_center_one(self):
     self.assertEqual(self.G.e(), self.N - 1)
     algorithm = TreeCenter(self.G)
     algorithm.run()
     self.assertEqual(algorithm.tree_center, [4])
     self.assertEqual(algorithm.tree_radius, 2)