1 /******************************************
2 Copyright (c) 2016, Mate Soos
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 ***********************************************/
22
23 #include "gtest/gtest.h"
24
25 #include <set>
26 using std::set;
27
28 #include "src/solver.h"
29 #include "src/intree.h"
30 #include "src/solverconf.h"
31 using namespace CMSat;
32 #include "test_helper.h"
33
34 struct intree : public ::testing::Test {
intreeintree35 intree()
36 {
37 must_inter.store(false, std::memory_order_relaxed);
38 SolverConf conf;
39 conf.do_hyperbin_and_transred = true;
40 //conf.verbosity = 20;
41 s = new Solver(&conf, &must_inter);
42 s->new_vars(30);
43 inp = s->intree;
44 }
~intreeintree45 ~intree()
46 {
47 delete s;
48 }
49
50 Solver* s;
51 InTree* inp;
52 std::atomic<bool> must_inter;
53 };
54
55
56 //Fails
57
TEST_F(intree,fail_1)58 TEST_F(intree, fail_1)
59 {
60 //s->conf.verbosity = 20;
61 s->add_clause_outer(str_to_cl(" 1, 2"));
62 s->add_clause_outer(str_to_cl("-2, 3"));
63 s->add_clause_outer(str_to_cl("-2, -3"));
64
65 inp->intree_probe();
66 check_zero_assigned_lits_contains(s, "-2");
67 }
68
69
TEST_F(intree,fail_2)70 TEST_F(intree, fail_2)
71 {
72 //s->conf.verbosity = 20;
73 s->add_clause_outer(str_to_cl(" 1, 2"));
74 s->add_clause_outer(str_to_cl("-2, 3"));
75 s->add_clause_outer(str_to_cl("-2, 4"));
76 s->add_clause_outer(str_to_cl("-2, 5"));
77 s->add_clause_outer(str_to_cl("-3, -4, -5, 1"));
78
79 inp->intree_probe();
80 check_zero_assigned_lits_contains(s, "1");
81 }
82
TEST_F(intree,fail_3)83 TEST_F(intree, fail_3)
84 {
85 //s->conf.verbosity = 20;
86 s->add_clause_outer(str_to_cl(" 1, 2"));
87 s->add_clause_outer(str_to_cl("-2, 3"));
88 s->add_clause_outer(str_to_cl("-2, 4"));
89 s->add_clause_outer(str_to_cl("-2, 5"));
90 s->add_clause_outer(str_to_cl("-3, -4, -5, 6"));
91 s->add_clause_outer(str_to_cl("-4, -5, -6"));
92
93 inp->intree_probe();
94 check_zero_assigned_lits_contains(s, "1");
95 }
96
97 //Hyper-binary resolution
98
TEST_F(intree,hyper_bin_1)99 TEST_F(intree, hyper_bin_1)
100 {
101 //s->conf.verbosity = 20;
102 s->add_clause_outer(str_to_cl(" 1, 2"));
103 s->add_clause_outer(str_to_cl("-2, 3"));
104 s->add_clause_outer(str_to_cl("-2, 4"));
105 s->add_clause_outer(str_to_cl("-3, -4, 5"));
106
107 inp->intree_probe();
108 check_red_cls_contains(s, "-2, 5");
109 }
110
TEST_F(intree,hyper_bin_2)111 TEST_F(intree, hyper_bin_2)
112 {
113 //s->conf.verbosity = 20;
114 s->add_clause_outer(str_to_cl(" 1, 2"));
115 s->add_clause_outer(str_to_cl("-2, 3"));
116 s->add_clause_outer(str_to_cl("-2, 4"));
117 s->add_clause_outer(str_to_cl("-3, -4, 5"));
118 s->add_clause_outer(str_to_cl("-5, 6"));
119 s->add_clause_outer(str_to_cl("-5, 7"));
120 s->add_clause_outer(str_to_cl("-6, -7, 8"));
121
122 inp->intree_probe();
123 check_red_cls_contains(s, "-2, 5");
124 check_red_cls_contains(s, "-5, 8");
125 }
126
127 //Transitive reduction
128
TEST_F(intree,trans_red_1)129 TEST_F(intree, trans_red_1)
130 {
131 //s->conf.verbosity = 20;
132 s->add_clause_outer(str_to_cl(" 1, 2"));
133 s->add_clause_outer(str_to_cl("-2, 3"));
134 s->add_clause_outer(str_to_cl("-2, 4"));
135 s->add_clause_outer(str_to_cl("-3, -4, 5"));
136 s->add_clause_outer(str_to_cl("1, 5"), false);
137
138 inp->intree_probe();
139 check_red_cls_doesnt_contain(s, "1, 5");
140 }
141
TEST_F(intree,trans_red_2)142 TEST_F(intree, trans_red_2)
143 {
144 //s->conf.verbosity = 20;
145 s->add_clause_outer(str_to_cl(" 1, 2"));
146 s->add_clause_outer(str_to_cl("-2, 3"));
147 s->add_clause_outer(str_to_cl("-3, 4"));
148 s->add_clause_outer(str_to_cl("-4, 5"));
149 s->add_clause_outer(str_to_cl("1, 5"));
150
151 inp->intree_probe();
152 check_irred_cls_doesnt_contain(s, "1, 5");
153 }
154
155 //Transitive reduction and hyper-binary resolution
TEST_F(intree,trans_red_and_hyper_bin_1)156 TEST_F(intree, trans_red_and_hyper_bin_1)
157 {
158 //s->conf.verbosity = 20;
159 s->add_clause_outer(str_to_cl(" 1, 2"));
160 s->add_clause_outer(str_to_cl("-2, 3"));
161 s->add_clause_outer(str_to_cl("-3, 4"));
162 s->add_clause_outer(str_to_cl("-4, 5"));
163 s->add_clause_outer(str_to_cl("-3, -4, -5, 6"));
164 s->add_clause_outer(str_to_cl("1, 6"), false);
165
166 inp->intree_probe();
167 check_red_cls_doesnt_contain(s, "1, 6");
168 check_red_cls_contains(s, "-3, 6");
169 }
170
main(int argc,char ** argv)171 int main(int argc, char **argv) {
172 ::testing::InitGoogleTest(&argc, argv);
173 return RUN_ALL_TESTS();
174 }
175