Beispiel #1
0
    def test_valid(self):
        k2 = nx.complete_graph(2)
        emb = {0: [0], 1: [1]}

        verify_embedding(emb, k2, k2)
        self.assertTrue(is_valid_embedding(emb, k2, k2))

        for err in diagnose_embedding(emb, k2, k2):
            raise err[0](*err[1:])
Beispiel #2
0
    def test_invalid_node(self):
        k2 = nx.complete_graph(2)
        emb = {0: [0], 1: [2]}

        self.assertRaises(InvalidNodeError,
                          lambda: verify_embedding(emb, k2, k2))
        self.assertFalse(is_valid_embedding(emb, k2, k2))

        etypes = set()
        for err in diagnose_embedding(emb, k2, k2):
            etypes.add(err[0])
        self.assertEqual(etypes, {InvalidNodeError})
Beispiel #3
0
    def test_chain_overlap(self):
        k2 = nx.complete_graph(2)
        emb = {0: [0], 1: [0, 1]}

        self.assertRaises(ChainOverlapError,
                          lambda: verify_embedding(emb, k2, k2))
        self.assertFalse(is_valid_embedding(emb, k2, k2))

        etypes = set()
        for err in diagnose_embedding(emb, k2, k2):
            etypes.add(err[0])
        self.assertEqual(etypes, {ChainOverlapError})
Beispiel #4
0
    def test_missing_chain(self):
        k2 = nx.complete_graph(2)
        emb = {0: [0]}

        self.assertRaises(MissingChainError,
                          lambda: verify_embedding(emb, k2, k2))
        self.assertFalse(is_valid_embedding(emb, k2, k2))

        etypes = set()
        for err in diagnose_embedding(emb, k2, k2):
            etypes.add(err[0])
        self.assertEqual(etypes, {MissingChainError})
Beispiel #5
0
    def test_chain_disconnect(self):
        k2 = nx.complete_graph(2)
        p3 = nx.path_graph(3)
        emb = {0: [1], 1: [0, 2]}

        self.assertRaises(DisconnectedChainError,
                          lambda: verify_embedding(emb, k2, p3))
        self.assertFalse(is_valid_embedding(emb, k2, p3))

        etypes = set()
        for err in diagnose_embedding(emb, k2, p3):
            etypes.add(err[0])
        self.assertEqual(etypes, {DisconnectedChainError})
Beispiel #6
0
    def run_battery(self,
                    name,
                    g,
                    reconstruct,
                    cliquesize,
                    cliquelength,
                    bicliquesize,
                    bicliquelength,
                    test_python=False,
                    test_nocache=True):
        labels = g.graph['labels']

        test = self.clique_battery(g,
                                   reconstruct,
                                   test_python=test_python,
                                   test_nocache=test_nocache)
        size, cl = next(test)
        self.assertEqual(size, cliquesize)
        self.assertEqual(cl, cliquelength)
        s = nx.complete_graph(size)
        for i, (h, emb, kind, check_cl) in enumerate(test):
            print(name, labels, kind)
            if check_cl:
                self.assertEqual(max_chainlength(emb), cl)
            verify_embedding(emb, s, h)

        test = self.biclique_battery(g, reconstruct)
        size, cl = next(test)
        self.assertEqual(size, bicliquesize)
        if bicliquelength is not None:
            self.assertEqual(cl, bicliquelength)
        s = nx.complete_bipartite_graph(size, size)
        for i, (h, emb, kind) in enumerate(test):
            print(name, labels, kind)
            if bicliquelength is not None:
                self.assertEqual(max_chainlength(emb), bicliquelength)
            verify_embedding(emb, s, h)
Beispiel #7
0
    def test_chain_overlap_with_edges(self):
        #this is made for compatibility with minorminer; to verify that "overlapped
        #embeddings" don't report spurious MissingEdgeErrors
        k5 = nx.complete_graph(5)
        k4 = nx.complete_graph(4)
        emb = {i: [i % 4, (i + 1) % 4] for i in k5}

        self.assertRaises(ChainOverlapError,
                          lambda: verify_embedding(emb, k5, k4))
        self.assertFalse(is_valid_embedding(emb, k5, k4))

        etypes = set()
        for err in diagnose_embedding(emb, k5, k4):
            etypes.add(err[0])
        self.assertEqual(etypes, {ChainOverlapError})
Beispiel #8
0
    def test_perfect_z6_clique(self):
        k88 = nx.complete_graph(88)
        bgc = busclique.busgraph_cache(self.z6)
        e88_cache = bgc.largest_clique()
        verify_embedding(e88_cache, k88, self.z6)

        e88_cache2 = busclique.find_clique_embedding(88,
                                                     self.z6,
                                                     use_cache=True)
        verify_embedding(e88_cache2, k88, self.z6)

        e88 = busclique.find_clique_embedding(88, self.z6, use_cache=False)
        verify_embedding(e88, k88, self.z6)
Beispiel #9
0
 def test_perfect_z6_biclique(self):
     k88_88 = nx.complete_bipartite_graph(88, 88)
     bgc = busclique.busgraph_cache(self.z6)
     e88_88_cache = bgc.largest_balanced_biclique()
     verify_embedding(e88_88_cache, k88_88, self.z6)