def test_impossible_clique(self): k = 55 m = 2 # Find embedding pg = pegasus_graph(m) with self.assertRaises(ValueError): find_clique_embedding(k, target_graph=pg)
def clique_battery(self, g, reconstruct, test_python=False, test_nocache=True): bgcg = busclique.busgraph_cache(g) emb0 = bgcg.largest_clique() size = len(emb0) cl = max_chainlength(emb0) N = range(size) yield size, cl yield g, emb0, 'g:bcg.lc', True yield g, bgcg.find_clique_embedding(size), 'g:bcg.fce', True yield g, busclique.find_clique_embedding(size, g), 'g:bc.fce', True if test_nocache: yield (g, busclique.find_clique_embedding(size, g, use_cache=False), 'g:bc.fce,nc', True) yield g, bgcg.largest_clique_by_chainlength(cl), 'g:bc.lcbc', True if test_python: if g.graph['family'] == 'chimera': if g.graph['labels'] == 'int': # this fails on coordinate-labeled graphs... TODO? args = size, g.graph['rows'] kwargs = dict(target_edges=g.edges) yield (g, chimera.find_clique_embedding(*args, **kwargs), 'g:legacy.fce', True) if g.graph['family'] == 'pegasus': kwargs = dict(target_graph=g) yield (g, pegasus.find_clique_embedding(size, **kwargs), 'g:legacy.fce', False) nodes = set(itertools.chain.from_iterable(emb0.values())) h = reconstruct(nodes) bgch = busclique.busgraph_cache(h) yield h, busclique.find_clique_embedding(N, h), 'h:bc.fce', True if test_nocache: yield (h, busclique.find_clique_embedding(N, h, use_cache=False), 'h:bc.fce,nc', True) yield h, bgch.largest_clique(), 'h:bgc.lc', True yield h, bgch.find_clique_embedding(N), 'h:bgc.fce', True yield h, bgch.largest_clique_by_chainlength(cl), 'h:bgc.lcbc', True if test_python: if g.graph['family'] == 'chimera': if g.graph['labels'] == 'int': # this fails on coordinate-labeled graphs... TODO? args = size, h.graph['rows'] kwargs = dict(target_edges=h.edges) yield (h, chimera.find_clique_embedding(*args, **kwargs), 'h:legacy.fce', True) if g.graph['family'] == 'pegasus': kwargs = dict(target_graph=h) yield (h, pegasus.find_clique_embedding(size, **kwargs), 'h:legacy.fce', False)
def test_k_parameter_int(self): k_int = 5 m = 3 # Find embedding pg = pegasus_graph(m, coordinates=True) embedding = find_clique_embedding(k_int, target_graph=pg) self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k_int), pg))
def test_valid_clique_coord(self): k = nx.complete_graph(15) m = 4 # Find embedding pg = pegasus_graph(m, coordinates=True) embedding = find_clique_embedding(k, target_graph=pg) self.assertTrue(is_valid_embedding(embedding, k, pg))
def test_k_parameter_list(self): k_nodes = ['one', 'two', 'three'] m = 4 # Find embedding pg = pegasus_graph(m, coordinates=True) embedding = find_clique_embedding(k_nodes, target_graph=pg) self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k_nodes), pg))
def test_zero_clique(self): k = 0 m = 3 # Find embedding pg = pegasus_graph(m) embedding = find_clique_embedding(k, target_graph=pg) self.assertEqual(k, len(embedding)) self.assertEqual({}, embedding)
def test_clique_incomplete_graph(self): k = 5 m = 2 # Nodes in a known K5 embedding # Note: {0: [14, 32], 1: [33, 15], 2: [16, 34], 3: [35, 17], 4: [36, 12]} known_embedding_nodes = {14, 32, 33, 15, 16, 34, 35, 17, 36, 12} # Create graph with missing nodes incomplete_pg = pegasus_graph(m) removed_nodes = set(incomplete_pg.nodes) - known_embedding_nodes incomplete_pg.remove_nodes_from(removed_nodes) # See if clique embedding is found embedding = find_clique_embedding(k, target_graph=incomplete_pg) self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k), incomplete_pg))
def test_clique_missing_edges(self): k = 9 m = 2 pg = pegasus_graph(m) #pick a random ordering of the edges edges = list(pg.edges()) shuffle(edges) K = nx.complete_graph(k) #now delete edges, one at a time, until we can no longer embed K with self.assertRaises(ValueError): while 1: (u, v) = edges.pop() pg.remove_edge(u, v) # See if clique embedding is found embedding = find_clique_embedding(k, target_graph=pg) self.assertTrue(is_valid_embedding(embedding, K, pg))