Exemple #1
0
 def test_solving_does_not_alter_list_of_conflicts(self):
     list_of_conflicts = [{1, 2, 5}, {3, 4}, {1, 2}]
     original_list_of_conflicts = [{1, 2, 5}, {3, 4}, {1, 2}]
     rc_tree = RcTree(list_of_conflicts)
     for solve_args in self.solve_options:
         rc_tree.solve(*solve_args)
         self.assertEqual(original_list_of_conflicts,
                          rc_tree.list_of_conflicts)
Exemple #2
0
 def test_linear_problem(self):
     list_of_conflicts = list(linear_conflicts(4, 3))
     expected_mhs = [{3, 7}, {1, 4, 7}, {8, 1, 5}, {1, 5, 9}, {1, 5, 7},
                     {2, 4, 7}, {8, 2, 5}, {9, 2, 5}, {2, 5, 7}, {8, 3, 5},
                     {9, 3, 5}, {8, 3, 6}, {9, 3, 6}, {8, 1, 4, 6},
                     {1, 4, 6, 9}, {8, 2, 4, 6}, {9, 2, 4, 6}]
     rc_tree = RcTree(list_of_conflicts)
     rc_tree.solve(sort=True)
     self.assertEqual(expected_mhs,
                      list(rc_tree.generate_minimal_hitting_sets()))
     self.assertTrue(rc_tree.verify())
     rc_tree.solve(prune=True)
     self.assertEqual(expected_mhs,
                      list(rc_tree.generate_minimal_hitting_sets()))
     self.assertTrue(rc_tree.verify())
Exemple #3
0
 def test_resetting_deletes_everything(self):
     list_of_conflicts_initial = [{1}, {3, 4, 5}]
     rc_tree = RcTree(list_of_conflicts_initial)
     rc_tree.solve()
     rc_tree.reset()
     self.assertEqual(0, len(list(rc_tree.generate_minimal_hitting_sets())))
     self.assertIsNone(rc_tree.root)
     self.assertEqual(
         0, len(list(rc_tree.breadth_first_explore(rc_tree.root))))
Exemple #4
0
 def test_solving_minimal_sorted_list_of_conflicts_2(self):
     list_of_conflicts = [{1}, {3, 4, 5}]
     expected_mhs = [{1, 3}, {1, 4}, {1, 5}]
     rc_tree = RcTree(list_of_conflicts)
     for solve_args in self.solve_options:
         rc_tree.solve(*solve_args)
         self.assertEqual(expected_mhs,
                          list(rc_tree.generate_minimal_hitting_sets()))
         self.assertTrue(rc_tree.verify())
Exemple #5
0
 def test_empty_list_of_conflicts_does_nothing(self):
     rc_tree = RcTree([])
     for solve_args in self.solve_options:
         elapsed = rc_tree.solve(*solve_args)
         self.assertEqual([], list(rc_tree.generate_minimal_hitting_sets()))
         self.assertIsNone(rc_tree.root)
         self.assertTrue(elapsed < 0.5)
         self.assertTrue(rc_tree.verify())
         self.assertEqual(
             0, len(list(rc_tree.breadth_first_explore(rc_tree.root))))
Exemple #6
0
 def test_solving_nonminimal_unsorted_list_of_conflicts_2(self):
     list_of_conflicts = [{1, 2, 3, 4}, {3}, {2, 4}, {15}, {9, 2, 15},
                          {9, 3}, {8, 7}, {8, 9, 1, 7}]
     expected_mhs = [{8, 2, 3, 15}, {2, 3, 7, 15}, {8, 3, 4, 15},
                     {3, 4, 7, 15}]
     rc_tree = RcTree(list_of_conflicts)
     for solve_args in self.solve_options:
         rc_tree.solve(*solve_args)
         self.assertEqual(expected_mhs,
                          list(rc_tree.generate_minimal_hitting_sets()))
         self.assertTrue(rc_tree.verify())
Exemple #7
0
 def test_solving_nonminimal_unsorted_list_of_conflicts_3(self):
     list_of_conflicts = [{1, 2, 3, 4, 7}, {1, 2, 4, 6, 8, 10},
                          {8, 9, 2, 10}, {10}, {3, 5, 6, 7, 10},
                          {4, 5, 8, 9, 10}, {1, 2, 5, 8, 9},
                          {3, 4, 5, 6, 7, 9, 10}, {8, 5,
                                                   6}, {3, 4, 5, 6, 10}]
     expected_mhs = [{8, 1, 10}, {8, 10, 2}, {8, 10, 3}, {8, 10, 4},
                     {8, 10, 7}, {1, 10, 5}, {10, 2, 5}, {10, 3, 5},
                     {10, 4, 5}, {10, 5, 7}, {1, 10, 6}, {10, 2, 6},
                     {9, 10, 3, 6}, {9, 10, 4, 6}, {9, 10, 6, 7}]
     rc_tree = RcTree(list_of_conflicts)
     rc_tree.solve(sort=True)
     self.assertEqual(expected_mhs,
                      list(rc_tree.generate_minimal_hitting_sets()))
     self.assertTrue(rc_tree.verify())
     rc_tree = RcTree(list_of_conflicts)
     rc_tree.solve(prune=True)
     self.assertEqual(
         set(map(frozenset, expected_mhs)),
         set(map(frozenset, rc_tree.generate_minimal_hitting_sets())))
     self.assertTrue(rc_tree.verify())