Exemplo n.º 1
0
 def test_exact_decomposition_cutset_8(self):
     for n in range(0, 13):
         for i in range(0, 10):
             V, E = randomGNP(n, 0.2)
             G = Graph(V, E)
             T, w = tdlib.exact_decomposition_cutset(G)
             self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
Exemplo n.º 2
0
    def onActivatedGroupBoxMode(self):
        if self.RadioSwitch1.isChecked():
            self.Window = 0
            self.pic.hide()
        if self.RadioSwitch2.isChecked():
            self.Window = 1
            self.pic.hide()
        if self.RadioSwitch3.isChecked():
            self.Window = 2

            V_T = list()
            E_T = list()
            try:
                import tdlib
                T, w = tdlib.exact_decomposition_cutset(self.Current.G)
                V_T = T.vertices()
                E_T = T.edges()
            except:
                self.loading_errors.append(
                    "unable to load pytdlib, install pytdlib (>=0.8) (included in the tarball of tdlib)"
                )
                self.loading_errors.append("    -> ./configure")
                self.loading_errors.append("    -> make install")
                self.onActivatedReset()
                self.repaint()
                return
            try:
                import pydot
                graph = pydot.Dot(graph_type='graph')
                for bag in V_T:
                    graph.add_node(pydot.Node(str(bag)))

                i = 0
                while i < (len(E_T) - 1):
                    graph.add_edge(
                        pydot.Edge(str(V_T[E_T[i]]), str(V_T[E_T[i + 1]])))
                    i += 2

                graph.write_png('tmp.png')

            except:
                self.loading_errors.append(
                    "unable to plot the treedecomposition")
                self.loading_errors.append("    -> install pydot")
                self.onActivatedReset()
                self.repaint()
                return

            self.pic.setPixmap(QtGui.QPixmap("tmp.png"))
            self.pic.setAlignment(QtCore.Qt.AlignCenter)
            self.pic.show()

        self.onActivatedReset()
        self.repaint()
Exemplo n.º 3
0
    def test_exact_decomposition_cutset_9(self):
        status = True
        for n in range(0, 13):
            for i in range(0, 10):
                V, E = randomGNP(n, 0.3)
                G = Graph(V, E)
                T, w2 = tdlib.PP_FI_TM(G)
                isleq = tdlib.exact_decomposition_cutset_decision(G, w2)
                if (not isleq):
                    print("error [validate width], graph: " +
                          str(G.vertices()) + ", " + str(G.edges()))
                    print("width_PP_FI_TM: " + str(w2))
                    N, M, width = tdlib.exact_decomposition_cutset(G)
                    hrgl = tdlib.check_treedec(V, E, N, M, message=True)
                    print("proper width_PP_FI_TM: " + str(width) + " " +
                          str(hrgl))
                    self.assertEqual(hrgl, 0)
                    status = False

        self.assertEqual(status, True)
Exemplo n.º 4
0
 def test_exact_decomposition_cutset_7(self):
     G = Graph(V_Grid_5_5, E_Grid_5_5)
     T, w = tdlib.exact_decomposition_cutset(G)
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
     self.assertEqual(w, 5)
Exemplo n.º 5
0
 def test_exact_decomposition_cutset_5(self):
     G = Graph(V_Wagner, E_Wagner)
     T, w = tdlib.exact_decomposition_cutset(G)
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
     self.assertEqual(w, 4)
Exemplo n.º 6
0
 def test_exact_decomposition_cutset_4(self):
     G = Graph(V_Petersen_double, E_Petersen_double)
     T, w = tdlib.exact_decomposition_cutset(G)
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
     self.assertEqual(w, 4)
Exemplo n.º 7
0
 def test_exact_decomposition_cutset_1(self):
     G = Graph(V_P6, E_P6)
     T, w = tdlib.exact_decomposition_cutset(G)
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
     self.assertEqual(w, 1)
Exemplo n.º 8
0
 def test_exact_decomposition_cutset_0(self):
     for V, E in cornercases:
         G = Graph(V, E)
         T, w = tdlib.exact_decomposition_cutset(G)
         self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
Exemplo n.º 9
0
 def test_is_valid_treedecomposition_5(self):
     G = Graph(V_Wagner, E_Wagner)
     T, tw = tdlib.exact_decomposition_cutset(G)
     del T.vertices()[-1]
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T, False), False)
Exemplo n.º 10
0
 def test_is_valid_treedecomposition_2(self):
     G = Graph(V_Petersen, E_Petersen)
     T, tw = tdlib.exact_decomposition_cutset(G)
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)