def solve_graph(graph, name): """ Runs a planarity test on a predefined graph. Args: graph (networkx.Graph): Input graph name (str): The name of the graph Returns: planarity (bool): Planarity of the graph """ # graph_nodes = len(graph.nodes()) # graph_edges = len(graph.edges()) # FouldsRobinsonPlanarity.find_planarity(G) # TarjanHopcroftPlanarity.find_planarity(graph) planar, bad_graph = KuratowskiPlanarity.find_planarity(graph) print "Graph %s is planar: %s" % ( name, planar, ) GraphUtils.draw_graph(graph, name, bad_graph) return planar
def testPlanar(self): # Generate K(4) graph p_graph = GraphGenerator.make_planar_graph() # Test graph planar, bad_graph = KuratowskiPlanarity.find_planarity(p_graph) GraphUtils.draw_graph(p_graph, "planar_test", bad_graph) # print "Test on planar graph:", 'PASS' if planar else 'FAIL' self.assertTrue(planar) # True means graph is planar
def testK5(self): # Generate K(5) graph k5 = GraphGenerator.make_k5_graph() # Test graph planar, bad_graph = KuratowskiPlanarity.find_planarity(k5) GraphUtils.draw_graph(k5, "K5", bad_graph) # print "Test on K(5):", 'FAIL' if planar else 'PASS' self.assertFalse(planar) # False means K(5) subgraph was found
def testK33(self): # Generate K(3, 3) graph k33 = GraphGenerator.make_k33_graph() # Test graph planar, bad_graph = KuratowskiPlanarity.find_planarity(k33) GraphUtils.draw_graph(k33, "K33", bad_graph) # print "Test on K(3, 3):", 'FAIL' if planar else 'PASS' self.assertFalse(planar) # False means K(3, 3) subgraph was found