예제 #1
0
def cut_and_solve_basic(kpp):
    max_cliques = kpp.G.maximal_cliques()
    k = kpp.k
    kpp.add_separator(YCliqueSeparator(max_cliques, 4, k))
    kpp.add_separator(YCliqueSeparator(max_cliques, 5, k))
    kpp.cut()
    kpp.solve()
예제 #2
0
def cut_and_solve_extension(kpp):
    max_cliques = kpp.G.maximal_cliques()
    k = kpp.k
    k2 = kpp.k2
    kpp.add_separator(YCliqueSeparator(max_cliques, 4, k))
    kpp.add_separator(YCliqueSeparator(max_cliques, 5, k))
    kpp.cut()
    kpp.sep_algs.clear()
    kpp.add_z_variables()
    kpp.add_separator(YZCliqueSeparator(max_cliques, 7, k, k2))
    kpp.add_separator(ZCliqueSeparator(max_cliques, 8, k, k2))
    kpp.cut()
    kpp.solve()
예제 #3
0
파일: test_kpp.py 프로젝트: Heeka/kpp
 def test_cuts(self):
     print("\ttest_cuts...")
     cuts_kpp = KPP(self.G, k, verbosity=0)
     cuts_kpp.add_separator(YCliqueSeparator(self.max_cliques, k + 1, k))
     cuts_kpp.cut()
     cuts_kpp.solve()
     obj_val = cuts_kpp.model.objVal
     self.assertAlmostEqual(self.obj_val, obj_val)
예제 #4
0
파일: test_kpp.py 프로젝트: Heeka/kpp
 def test_cuts_and_break_symmetry(self):
     print("\ttest_cuts_and_break_symmetry...")
     kpp = KPP(self.G, k, verbosity=0)
     kpp.add_separator(YCliqueSeparator(self.max_cliques, k + 1, k))
     kpp.cut()
     kpp.break_symmetry()
     kpp.solve()
     obj_val = kpp.model.objVal
     self.assertAlmostEqual(self.obj_val, obj_val)
예제 #5
0
파일: test_kpp.py 프로젝트: Heeka/kpp
    def test_fractional_ycut(self):
        print("\ttest_fractional_ycut...")
        cuts_kpp = KPPExtension(self.G, k, k2, verbosity=0)
        cuts_kpp.add_separator(YCliqueSeparator(self.max_cliques, k + 1, k))
        y_sep_alg_1 = YCliqueSeparator(self.max_cliques, k + 1, k)
        yz_sep_alg = YZCliqueSeparator(self.max_cliques, k2 * k + 1, k, k2)
        z_sep_alg = ZCliqueSeparator(self.max_cliques, k2 * k + 2, k, k2)
        cuts_kpp.add_separator(y_sep_alg_1)

        cuts_kpp.cut()
        cuts_kpp.add_fractional_cut()
        cuts_kpp.sep_algs = []
        cuts_kpp.add_z_variables()
        cuts_kpp.add_separator(yz_sep_alg)
        cuts_kpp.add_separator(z_sep_alg)
        cuts_kpp.cut()
        cuts_kpp.solve()
        obj_val = cuts_kpp.model.objVal
        self.assertAlmostEqual(self.obj_val, obj_val)
예제 #6
0
파일: test_kpp.py 프로젝트: Heeka/kpp
    def test_cuts_and_break_symmetry(self):
        print("\ttest_cuts_and_break_symmetry...")
        kpp = KPPExtension(self.G, k, k2, verbosity=0)
        y_sep_alg_1 = YCliqueSeparator(self.max_cliques, k + 1, k)
        y_sep_alg_2 = YCliqueSeparator(self.max_cliques, k + 2, k)
        yz_sep_alg = YZCliqueSeparator(self.max_cliques, k * k2 + 1, k, k2)
        z_sep_alg = ZCliqueSeparator(self.max_cliques, k * k2 + 2, k, k2)
        kpp.add_separator(y_sep_alg_1)
        kpp.add_separator(y_sep_alg_2)
        kpp.cut()
        kpp.sep_algs = []
        kpp.add_z_variables()
        kpp.add_separator(yz_sep_alg)
        kpp.add_separator(z_sep_alg)
        kpp.cut()

        kpp.break_symmetry()
        kpp.solve()
        obj_val = kpp.model.objVal
        self.assertAlmostEqual(self.obj_val, obj_val)
예제 #7
0
def test_YCliqueSeparator(n, k):
  graph = ig.Graph.Full(n)
  for e in graph.es():
    e["weight"] = random()
  kpp = KPP(graph, k, verbosity=0)
  kpp.solve()
  opt_val = kpp.model.objVal
  max_cliques = graph.maximal_cliques()  # [graph.vs()]
  kpp_sep = KPP(graph, k, verbosity=0)
  for p in range(k + 1, n + 1):
    kpp_sep.add_separator(YCliqueSeparator(max_cliques, p, k))
  kpp_sep.cut()
  kpp_sep.add_node_variables()
  kpp_sep.solve()
  new_opt_val = kpp_sep.model.objVal
  assert isclose(opt_val, new_opt_val)