예제 #1
0
 def test_PP_FI_TM(self):
     print("---PP_FI_TM---")
     for i in range(0, COUNT+1):
         G = Graph(eval(PREFIX+".V_"+str(i)), eval(PREFIX+".E_"+str(i)))
         base.print_graph_name(PREFIX, i)
         T, w = tdlib.PP_FI_TM(G)
         self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
예제 #2
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_independent_set_with_treedecomposition_0a(self):
     V, E = cornercases[0]
     G = Graph(V, E)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.max_independent_set_with_treedecomposition(G, T)
     self.assertEqual(s, 0)
     self.assertEqual(len(S), s)
예제 #3
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_clique_with_treedecomposition_0d(self):
     V, E = cornercases[3]
     G = Graph(V, E)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.max_clique_with_treedecomposition(G, T)
     self.assertEqual(len(S), 5)
     self.assertEqual(len(S), s)
예제 #4
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_min_vertex_cover_with_treedecomposition_0d(self):
     V, E = cornercases[3]
     G = Graph(V, E)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.min_vertex_cover_with_treedecomposition(G, T)
     self.assertEqual(len(S), 4)
     self.assertEqual(len(S), s)
예제 #5
0
 def test_PP_FI_TM_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.PP_FI_TM(G)
             self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
예제 #6
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_clique_with_treedecomposition_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.PP_FI_TM(G)
             s, S = tdlib.max_clique_with_treedecomposition(G, T)
             self.assertEqual(len(S), s)
예제 #7
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)
예제 #8
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_min_vertex_cover_with_treedecomposition_5(self):
     G = Graph(V_Wagner, E_Wagner)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.min_vertex_cover_with_treedecomposition(G, T)
     self.assertEqual(len(S), 5)
     self.assertEqual(len(S), s)
예제 #9
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_min_vertex_cover_with_treedecomposition_3(self):
     G = Graph(V_Petersen, E_Petersen)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.min_vertex_cover_with_treedecomposition(G, T)
     self.assertEqual(len(S), 6)
     self.assertEqual(len(S), s)
예제 #10
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_independent_set_with_treedecomposition_7(self):
     G = Graph(V_Grid_5_5, E_Grid_5_5)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.max_independent_set_with_treedecomposition(G, T)
     self.assertEqual(s, 13)
     self.assertEqual(len(S), s)
예제 #11
0
    def test_min_vertex_cover(self):
        print("---vertex_cover---")

        max_n = 0
        avg_n = 0.0

        max_m = 0
        avg_m = 0.0

        max_vc = 0
        avg_vc = 0.0

        max_tw = 0
        avg_tw = 0.0

        max_time = 0
        avg_time = 0.0

        Ns = list()
        Ms = list()
        VCs = list()
        TWs = list()
        TIMEs = list()

        for i in range(0, COUNT + 1):
            #for i in range(1224, 1752+1):
            base.print_graph_name(PREFIX, i)
            G = Graph(eval(PREFIX + ".V_" + str(i)),
                      eval(PREFIX + ".E_" + str(i)))

            start = time.time()
            #T, w = tdlib.minDegree_decomp(G)
            T, w = tdlib.PP_FI_TM(G)
            s, S = tdlib.min_vertex_cover_with_treedecomposition2(G, T, False)
            end = time.time()

            t = end - start

            max_n = len(G.vertices()) if len(G.vertices()) > max_n else max_n
            avg_n += len(G.vertices())
            Ns.append(len(G.vertices()))

            max_m = len(G.edges()) if len(G.edges()) > max_m else max_m
            avg_m += len(G.edges())
            Ms.append(len(G.edges()))

            max_vc = s if s > max_vc else max_vc
            avg_vc += s
            VCs.append(s)

            max_tw = w if w > max_tw else max_tw
            avg_tw += w
            TWs.append(w)

            max_time = t if t > max_time else max_time
            avg_time += t
            TIMEs.append(t)

        #COUNT = 1752-1224

        avg_n /= COUNT
        avg_m /= COUNT
        avg_vc /= COUNT
        avg_tw /= COUNT
        avg_time /= COUNT

        med_n = median(Ns)
        med_m = median(Ms)
        med_vc = median(VCs)
        med_tw = median(TWs)
        med_time = median(TIMEs)

        print("avg n: " + str(avg_n))
        print("med n: " + str(med_n))
        print("max n: " + str(max_n))

        print("")

        print("avg m: " + str(avg_m))
        print("med m: " + str(med_m))
        print("max m: " + str(max_m))

        print("")

        print("avg tw: " + str(avg_tw))
        print("med tw: " + str(med_tw))
        print("max tw: " + str(max_tw))

        print("")

        print("avg vc: " + str(avg_vc))
        print("med vc: " + str(med_vc))
        print("max vc: " + str(max_vc))

        print("")

        print("avg time: " + str(avg_time))
        print("med time: " + str(med_time))
        print("max time: " + str(max_time))
예제 #12
0
 def test_PP_FI_TM_6(self):
     G = Graph(V_Pappus, E_Pappus)
     T, w = tdlib.PP_FI_TM(G)
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
     self.assertEqual(w, 6)
예제 #13
0
 def test_PP_FI_TM_5(self):
     G = Graph(V_Wagner, E_Wagner)
     T, w = tdlib.PP_FI_TM(G)
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
     self.assertEqual(w, 4)
예제 #14
0
 def test_PP_FI_TM_4(self):
     G = Graph(V_Petersen_double, E_Petersen_double)
     T, w = tdlib.PP_FI_TM(G)
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
     self.assertEqual(w >= 4 and w <= 5, True) #c++11 issuse
예제 #15
0
 def test_PP_FI_TM_0(self):
     for V, E in cornercases:
         G = Graph(V, E)
         T, w = tdlib.PP_FI_TM(G)
         self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
예제 #16
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_min_vertex_cover_with_treedecomposition_6(self):
     G = Graph(V_Pappus, E_Pappus)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.min_vertex_cover_with_treedecomposition(G, T)
     self.assertEqual(len(S), 9)
     self.assertEqual(len(S), s)
예제 #17
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_clique_with_treedecomposition_6(self):
     G = Graph(V_Pappus, E_Pappus)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.max_clique_with_treedecomposition(G, T)
     self.assertEqual(len(S), 2)
     self.assertEqual(len(S), s)
예제 #18
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_min_vertex_cover_with_treedecomposition_7(self):
     G = Graph(V_Grid_5_5, E_Grid_5_5)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.min_vertex_cover_with_treedecomposition(G, T)
     self.assertEqual(len(S), 12)
     self.assertEqual(len(S), s)
예제 #19
0
 def test_PP_FI_TM_7(self):
     G = Graph(V_Grid_5_5, E_Grid_5_5)
     T, w = tdlib.PP_FI_TM(G)
     self.assertEqual(tdlib.is_valid_treedecomposition(G, T), True)
     self.assertEqual(w, 5)
예제 #20
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_clique_with_treedecomposition_4(self):
     G = Graph(V_Petersen_double, E_Petersen_double)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.max_clique_with_treedecomposition(G, T)
     self.assertEqual(len(S), 2)
     self.assertEqual(len(S), s)
예제 #21
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_independent_set_with_treedecomposition_3(self):
     G = Graph(V_Petersen, E_Petersen)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.max_independent_set_with_treedecomposition(G, T)
     self.assertEqual(s, 4)
     self.assertEqual(len(S), s)
예제 #22
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_clique_with_treedecomposition_7(self):
     G = Graph(V_Grid_5_5, E_Grid_5_5)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.max_clique_with_treedecomposition(G, T)
     self.assertEqual(len(S), 2)
     self.assertEqual(len(S), s)
예제 #23
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_independent_set_with_treedecomposition_5(self):
     G = Graph(V_Wagner, E_Wagner)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.max_independent_set_with_treedecomposition(G, T)
     self.assertEqual(s, 3)
     self.assertEqual(len(S), s)
예제 #24
0
파일: test_apps.py 프로젝트: jamesjer/tdlib
 def test_max_independent_set_with_treedecomposition_6(self):
     G = Graph(V_Pappus, E_Pappus)
     T, w = tdlib.PP_FI_TM(G)
     s, S = tdlib.max_independent_set_with_treedecomposition(G, T)
     self.assertEqual(s, 9)
     self.assertEqual(len(S), s)
예제 #25
0
    def test_min_vertex_cover(self):
        print("---vertex_cover---")

        max_n = 0
        avg_n = 0.0

        max_m = 0
        avg_m = 0.0

        max_vc = 0
        avg_vc = 0.0

        max_tw = 0
        avg_tw = 0.0

        max_time = 0
        avg_time = 0.0

        Ns = list()
        Ms = list()
        VCs = list()
        TWs = list()
        TIMEs = list()

        COUNT = 0

        #for k in range(1, 16):
        for n in [50, 100, 200, 250, 500]:
            max_n2 = 0
            avg_n2 = 0.0

            max_m2 = 0
            avg_m2 = 0.0

            max_vc2 = 0
            avg_vc2 = 0.0

            max_tw2 = 0
            avg_tw2 = 0.0

            max_time2 = 0
            avg_time2 = 0.0

            Ns2 = list()
            Ms2 = list()
            VCs2 = list()
            TWs2 = list()
            TIMEs2 = list()

            COUNT2 = 0

            #for n in [50,100,200,250,500]:
            for k in range(1, 16):
                for p in [.97, .95, .90, .80, .70]:
                    for c in range(5):
                        suffix = str(n) + '_' + str(k) + '_' + str(p).replace(
                            '.', '') + '_' + str(c)
                        #print(suffix)

                        G = Graph(eval(PREFIX + ".V_" + suffix),
                                  eval(PREFIX + ".E_" + suffix))

                        start = time.time()
                        #T, w = tdlib.minDegree_decomp(G)
                        T, w = tdlib.PP_FI_TM(G)
                        s, S = tdlib.min_vertex_cover_with_treedecomposition2(
                            G, T, False)
                        end = time.time()

                        t = end - start

                        max_n = len(G.vertices()) if len(
                            G.vertices()) > max_n else max_n
                        avg_n += len(G.vertices())
                        Ns.append(len(G.vertices()))

                        max_m = len(
                            G.edges()) if len(G.edges()) > max_m else max_m
                        avg_m += len(G.edges())
                        Ms.append(len(G.edges()))

                        max_vc = s if s > max_vc else max_vc
                        avg_vc += s
                        VCs.append(s)

                        max_tw = w if w > max_tw else max_tw
                        avg_tw += w
                        TWs.append(w)

                        max_time = t if t > max_time else max_time
                        avg_time += t
                        TIMEs.append(t)

                        COUNT += 1

                        max_n2 = len(G.vertices()) if len(
                            G.vertices()) > max_n2 else max_n2
                        avg_n2 += len(G.vertices())
                        Ns2.append(len(G.vertices()))

                        max_m2 = len(
                            G.edges()) if len(G.edges()) > max_m2 else max_m2
                        avg_m2 += len(G.edges())
                        Ms2.append(len(G.edges()))

                        max_vc2 = s if s > max_vc2 else max_vc2
                        avg_vc2 += s
                        VCs2.append(s)

                        max_tw2 = w if w > max_tw2 else max_tw2
                        avg_tw2 += w
                        TWs2.append(w)

                        max_time2 = t if t > max_time2 else max_time2
                        avg_time2 += t
                        TIMEs2.append(t)

                        COUNT2 += 1

            avg_n2 /= COUNT2
            avg_m2 /= COUNT2
            avg_vc2 /= COUNT2
            avg_tw2 /= COUNT2
            avg_time2 /= COUNT2

            med_n2 = median(Ns2)
            med_m2 = median(Ms2)
            med_vc2 = median(VCs2)
            med_tw2 = median(TWs2)
            med_time2 = median(TIMEs2)

            print("---k: " + str(k) + "---")

            print("avg n: " + str(avg_n2))
            print("med n: " + str(med_n2))
            print("max n: " + str(max_n2))

            print("")

            print("avg m: " + str(avg_m2))
            print("med m: " + str(med_m2))
            print("max m: " + str(max_m2))

            print("")

            print("avg tw: " + str(avg_tw2))
            print("med tw: " + str(med_tw2))
            print("max tw: " + str(max_tw2))

            print("")

            print("avg vc: " + str(avg_vc2))
            print("med vc: " + str(med_vc2))
            print("max vc: " + str(max_vc2))

            print("")

            print("avg time: " + str(avg_time2))
            print("med time: " + str(med_time2))
            print("max time: " + str(max_time2))

        #COUNT = 1752-1224

        print("---total---")

        avg_n /= COUNT
        avg_m /= COUNT
        avg_vc /= COUNT
        avg_tw /= COUNT
        avg_time /= COUNT

        med_n = median(Ns)
        med_m = median(Ms)
        med_vc = median(VCs)
        med_tw = median(TWs)
        med_time = median(TIMEs)

        print("avg n: " + str(avg_n))
        print("med n: " + str(med_n))
        print("max n: " + str(max_n))

        print("")

        print("avg m: " + str(avg_m))
        print("med m: " + str(med_m))
        print("max m: " + str(max_m))

        print("")

        print("avg tw: " + str(avg_tw))
        print("med tw: " + str(med_tw))
        print("max tw: " + str(max_tw))

        print("")

        print("avg vc: " + str(avg_vc))
        print("med vc: " + str(med_vc))
        print("max vc: " + str(max_vc))

        print("")

        print("avg time: " + str(avg_time))
        print("med time: " + str(med_time))
        print("max time: " + str(max_time))