def test_wheel5(self): N = 5 G = Graph(N, False) edges = [Edge(0, 1), Edge(0, 2), Edge(0, 3), Edge(0, 4), Edge(1, 2), Edge(2, 3), Edge(3, 4), Edge(4, 1)] for node in range(N): G.add_node(node) for edge in edges: G.add_edge(edge) algorithm = HalinGraph(G) algorithm.run() #print "wheel5 outer", algorithm.outer self.assertEqual(algorithm.outer, set([1, 2, 3, 4])) self.assertTrue(algorithm.is_outer_k4())
def test_halin7(self): N = 7 G = Graph(N, False) edges = [Edge(0, 1), Edge(0, 2), Edge(0, 6), Edge(1, 2), Edge(1, 4), Edge(2, 3), Edge(3, 4), Edge(3, 5), Edge(4, 5), Edge(4, 6), Edge(5, 6)] for node in range(N): G.add_node(node) for edge in edges: G.add_edge(edge) algorithm = HalinGraph(G) algorithm.run() #print "halin7 outer", algorithm.outer self.assertEqual(algorithm.outer, set([0, 2, 3, 5, 6])) self.assertTrue(algorithm.is_outer_k4())
def test_3prism(self): N = 6 G = Graph(N, False) edges = [Edge(0, 1), Edge(1, 2), Edge(2, 3), Edge(3, 4), Edge(4, 5), Edge(0, 5), Edge(1, 4), Edge(2, 0), Edge(3, 5)] for node in range(N): G.add_node(node) for edge in edges: G.add_edge(edge) algorithm = HalinGraph(G) algorithm.run() #print "3prism outer", algorithm.outer #self.assertEqual(algorithm.outer, set([0, 2, 3, 5])) self.assertEqual(algorithm.outer, set([0, 1, 4, 5])) #self.assertEqual(algorithm.outer, set([1, 2, 3, 4])) self.assertTrue(algorithm.is_outer_k4())
def test_halin10l(self): N = 10 G = Graph(N, False) edges = [Edge(0, 1), Edge(0, 4), Edge(0, 9), Edge(1, 2), Edge(1, 9), Edge(2, 3), Edge(2, 7), Edge(3, 4), Edge(3, 5), Edge(4, 5), Edge(5, 6), Edge(6, 7), Edge(6, 8), Edge(7, 8), Edge(8, 9)] for node in range(N): G.add_node(node) for edge in edges: G.add_edge(edge) algorithm = HalinGraph(G) algorithm.run() #print "halin10l outer", algorithm.outer self.assertEqual(algorithm.outer, set([0, 4, 5, 6, 8, 9])) self.assertTrue(algorithm.is_outer_k4())
def test_halin8a(self): N = 8 G = Graph(N, False) edges = [Edge(0, 1), Edge(0, 2), Edge(0, 7), Edge(1, 2), Edge(1, 5), Edge(2, 3), Edge(3, 4), Edge(3, 7), Edge(4, 5), Edge(4, 6), Edge(5, 6), Edge(6, 7)] for node in range(N): G.add_node(node) for edge in edges: G.add_edge(edge) algorithm = HalinGraph(G) algorithm.run() #print "halin8a outer", algorithm.outer # Sa dwie mozliwosci narysowania tego grafu. self.assertEqual(algorithm.outer, set([0, 1, 5, 6, 7])) #self.assertEqual(algorithm.outer, set([1, 2, 3, 4, 5])) self.assertTrue(algorithm.is_outer_k4())
def test_4prism(self): N = 8 G = Graph(N, False) edges = [Edge(0, 1), Edge(1, 2), Edge(2, 3), Edge(3, 0), Edge(4, 5), Edge(5, 6), Edge(6, 7), Edge(7, 4), Edge(0, 4), Edge(1, 5), Edge(2, 6), Edge(3, 7)] for node in range(N): G.add_node(node) for edge in edges: G.add_edge(edge) #G.show() algorithm = HalinGraph(G) self.assertRaises(ValueError, algorithm.run)
#!/usr/bin/python import timeit import random from graphtheory.structures.edges import Edge from graphtheory.structures.graphs import Graph from graphtheory.structures.factory import GraphFactory from graphtheory.planarity.halin import HalinGraph from graphtheory.planarity.halintools import make_halin_outer from graphtheory.planarity.halintools import make_halin_cubic_outer V = 10 graph_factory = GraphFactory(Graph) G = graph_factory.make_necklace(n=V) # V even outer = set(range(0,V,2)) | set([V-1]) # necklace #G, outer = make_halin_outer(V) #G, outer = make_halin_cubic_outer(V) # always finishing with 7-wheel E = G.e() #G.show() print ( "Testing HalinGraph ..." ) t1 = timeit.Timer(lambda: HalinGraph(G).run()) print ( "{} {} {}".format(V, E, t1.timeit(1)) ) # single run # EOF
#!/usr/bin/python from graphtheory.structures.edges import Edge from graphtheory.structures.graphs import Graph from graphtheory.structures.factory import GraphFactory from graphtheory.planarity.halin import HalinGraph from graphtheory.planarity.wheels import is_wheel V = 10 graph_factory = GraphFactory(Graph) #G = graph_factory.make_prism(size=3) # V=2*size=6 #G = graph_factory.make_complete(n=4) # V=4 #G = graph_factory.make_wheel(n=V) # V > 3 G = graph_factory.make_necklace(n=V) # V even G.show() print ( "Recognition ..." ) print ( "is_wheel {}".format( is_wheel(G) )) algorithm = HalinGraph(G) algorithm.run() print ( "outer {}".format( algorithm.outer )) outer = algorithm.outer #assert outer == set(range(1,V)) # wheel assert outer == set(range(0,V,2)) | set([V-1]) # necklace # EOF
def test_k4(self): # graf K4 = W4 G = self.graph_factory.make_complete(n=4, directed=False) # Sa 4 mozliwosci narysowania K4 na plaszczyznie bez przeciec. algorithm = HalinGraph(G) algorithm.run() self.assertTrue(algorithm.is_outer_k4())
from graphtheory.planarity.halintools import make_halin from graphtheory.planarity.halintools import make_halin_cubic from graphtheory.planarity.wheels import is_wheel graph_factory = GraphFactory(Graph) #G = graph_factory.make_prism(size=3) # V=2*size=6 #G = graph_factory.make_complete(n=4) # V=4 #G = graph_factory.make_wheel(n=5) # V > 3 G = graph_factory.make_necklace(n=6) # V even #G = make_halin(n=7) # V > 3 #G = make_halin_cubic(n=8) # V even G.show() print("Recognition ...") print("is_wheel {}".format(is_wheel(G))) algorithm = HalinGraph(G) algorithm.run() print("outer {}".format(algorithm.outer)) outer = algorithm.outer print("Vertex coloring ...") algorithm = HalinNodeColoring(G, outer) algorithm.run() print("parent {}".format(algorithm.parent)) assert len(algorithm.parent) == G.v() print("color {}".format(algorithm.color)) all_colors = set(algorithm.color[node] for node in G.iternodes()) print("len(all_colors) {}".format(len(all_colors))) assert len(algorithm.color) == G.v() print("Finding PEO for chordal completion ...")