1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.sat4j.minisat.constraints.cnf; |
8 |
| |
9 |
| import java.io.Serializable; |
10 |
| |
11 |
| import org.sat4j.core.VecInt; |
12 |
| import org.sat4j.minisat.core.Constr; |
13 |
| import org.sat4j.minisat.core.ILits; |
14 |
| import org.sat4j.minisat.core.UnitPropagationListener; |
15 |
| import org.sat4j.specs.IVecInt; |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| public class TernaryClauses implements Constr, Serializable { |
22 |
| |
23 |
| private static final long serialVersionUID = 1L; |
24 |
| |
25 |
| private final IVecInt stubs = new VecInt(); |
26 |
| |
27 |
| private final ILits voc; |
28 |
| |
29 |
| private final int phead; |
30 |
| |
31 |
11588
| public TernaryClauses(ILits voc, int p) {
|
32 |
11588
| this.voc = voc;
|
33 |
11588
| this.phead = p;
|
34 |
| } |
35 |
| |
36 |
33993
| public void addTernaryClause(int a, int b) {
|
37 |
33993
| stubs.push(a);
|
38 |
33993
| stubs.push(b);
|
39 |
| } |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
0
| public void remove() {
|
47 |
| |
48 |
| } |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
59286
| public boolean propagate(UnitPropagationListener s, int p) {
|
57 |
| assert voc.isSatisfied(p); |
58 |
| assert voc.isFalsified(phead); |
59 |
59286
| voc.watch(p, this);
|
60 |
59286
| for (int i = 0; i < stubs.size(); i += 2) {
|
61 |
150346
| int a = stubs.get(i);
|
62 |
150346
| int b = stubs.get(i + 1);
|
63 |
150346
| if (voc.isSatisfied(a) || voc.isSatisfied(b)) {
|
64 |
68018
| continue;
|
65 |
| } |
66 |
82328
| if (voc.isFalsified(a) && !s.enqueue(b, this)) {
|
67 |
1145
| return false;
|
68 |
81183
| } else if (voc.isFalsified(b) && !s.enqueue(a, this)) {
|
69 |
0
| return false;
|
70 |
| } |
71 |
| } |
72 |
58141
| return true;
|
73 |
| } |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
0
| public boolean simplify() {
|
81 |
0
| return false;
|
82 |
| } |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
0
| public void undo(int p) {
|
90 |
| } |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
14434
| public void calcReason(int p, IVecInt outReason) {
|
98 |
| assert voc.isFalsified(this.phead); |
99 |
14434
| if (p == ILits.UNDEFINED) {
|
100 |
1123
| int i = 0;
|
101 |
1123
| while (!voc.isFalsified(stubs.get(i))
|
102 |
| || !voc.isFalsified(stubs.get(i + 1))) { |
103 |
1509
| i += 2;
|
104 |
| } |
105 |
1123
| outReason.push(this.phead ^ 1);
|
106 |
1123
| outReason.push(stubs.get(i) ^ 1);
|
107 |
1123
| outReason.push(stubs.get(i + 1) ^ 1);
|
108 |
| } else { |
109 |
13311
| outReason.push(this.phead ^ 1);
|
110 |
13311
| int i = 0;
|
111 |
13311
| while ((stubs.get(i) != p) || (!voc.isFalsified(stubs.get(i ^ 1)))) {
|
112 |
37004
| i++;
|
113 |
| } |
114 |
| assert !voc.isFalsified(stubs.get(i)); |
115 |
13311
| outReason.push(stubs.get(i ^ 1) ^ 1);
|
116 |
| assert voc.isFalsified(stubs.get(i ^ 1)); |
117 |
| } |
118 |
| |
119 |
| } |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
14434
| public boolean learnt() {
|
127 |
14434
| return false;
|
128 |
| } |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
| |
135 |
0
| public void incActivity(double claInc) {
|
136 |
| } |
137 |
| |
138 |
| |
139 |
| |
140 |
| |
141 |
| |
142 |
| |
143 |
0
| public double getActivity() {
|
144 |
0
| return 0;
|
145 |
| } |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
| |
151 |
| |
152 |
0
| public boolean locked() {
|
153 |
| |
154 |
0
| return false;
|
155 |
| } |
156 |
| |
157 |
| |
158 |
| |
159 |
| |
160 |
| |
161 |
| |
162 |
0
| public void setLearnt() {
|
163 |
| |
164 |
| } |
165 |
| |
166 |
| |
167 |
| |
168 |
| |
169 |
| |
170 |
| |
171 |
0
| public void register() {
|
172 |
| |
173 |
| } |
174 |
| |
175 |
| |
176 |
| |
177 |
| |
178 |
| |
179 |
| |
180 |
0
| public void rescaleBy(double d) {
|
181 |
| |
182 |
| } |
183 |
| |
184 |
| |
185 |
| |
186 |
| |
187 |
| |
188 |
| |
189 |
234070
| public int size() {
|
190 |
234070
| return stubs.size();
|
191 |
| } |
192 |
| |
193 |
| |
194 |
| |
195 |
| |
196 |
| |
197 |
| |
198 |
0
| public int get(int i) {
|
199 |
0
| throw new UnsupportedOperationException();
|
200 |
| } |
201 |
| |
202 |
0
| public void assertConstraint(UnitPropagationListener s) {
|
203 |
0
| throw new UnsupportedOperationException();
|
204 |
| } |
205 |
| } |