1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| package org.sat4j.minisat.constraints.pb; |
27 |
| |
28 |
| import java.io.Serializable; |
29 |
| import java.math.BigInteger; |
30 |
| |
31 |
| import org.sat4j.core.Vec; |
32 |
| import org.sat4j.core.VecInt; |
33 |
| import org.sat4j.minisat.core.ILits; |
34 |
| import org.sat4j.minisat.core.UnitPropagationListener; |
35 |
| import org.sat4j.specs.ContradictionException; |
36 |
| import org.sat4j.specs.IVec; |
37 |
| import org.sat4j.specs.IVecInt; |
38 |
| |
39 |
| public class MaxWatchPb extends WatchPb implements Serializable { |
40 |
| |
41 |
| private static final long serialVersionUID = 1L; |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
1214677
| private MaxWatchPb(ILits voc, IDataStructurePB mpb) {
|
58 |
| |
59 |
1214677
| super(mpb);
|
60 |
1214677
| this.voc = voc;
|
61 |
| |
62 |
1214677
| activity = 0;
|
63 |
1214677
| watchCumul = BigInteger.ZERO;
|
64 |
1214677
| locked = false;
|
65 |
| } |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
1214587
| @Override
|
73 |
| protected void computeWatches() throws ContradictionException { |
74 |
| assert watchCumul.equals(BigInteger.ZERO); |
75 |
1214587
| for (int i = 0; i < lits.length; i++) {
|
76 |
12023495
| if (voc.isFalsified(lits[i])) {
|
77 |
4726222
| if (learnt)
|
78 |
4726091
| voc.undos(lits[i] ^ 1).push(this);
|
79 |
| } else { |
80 |
| |
81 |
7297273
| voc.watch(lits[i] ^ 1, this);
|
82 |
7297273
| watchCumul = watchCumul.add(coefs[i]);
|
83 |
| } |
84 |
| } |
85 |
| |
86 |
| assert watchCumul.compareTo(recalcLeftSide()) >= 0; |
87 |
1214587
| if (!learnt && watchCumul.compareTo(degree) < 0) {
|
88 |
17
| throw new ContradictionException("non satisfiable constraint");
|
89 |
| } |
90 |
| } |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
1025312
| @Override
|
98 |
| protected void computePropagation(UnitPropagationListener s) |
99 |
| throws ContradictionException { |
100 |
| |
101 |
1025312
| int ind = 0;
|
102 |
1025312
| while (ind < coefs.length
|
103 |
| && watchCumul.subtract(coefs[ind]).compareTo(degree) < 0) { |
104 |
266
| if (voc.isUnassigned(lits[ind]) && !s.enqueue(lits[ind], this)) {
|
105 |
0
| throw new ContradictionException("non satisfiable constraint");
|
106 |
| } |
107 |
266
| ind++;
|
108 |
| } |
109 |
| assert watchCumul.compareTo(recalcLeftSide()) >= 0; |
110 |
| } |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
499336
| public static MaxWatchPb maxWatchPbNew(UnitPropagationListener s,
|
127 |
| ILits voc, IVecInt ps, IVecInt coefs, boolean moreThan, int degree) |
128 |
| throws ContradictionException { |
129 |
499336
| return maxWatchPbNew(s, voc, ps, toVecBigInt(coefs), moreThan,
|
130 |
| toBigInt(degree)); |
131 |
| } |
132 |
| |
133 |
| |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
| |
141 |
| |
142 |
| |
143 |
| |
144 |
| |
145 |
| |
146 |
| |
147 |
778801
| public static MaxWatchPb maxWatchPbNew(UnitPropagationListener s,
|
148 |
| ILits voc, IVecInt ps, IVec<BigInteger> coefs, boolean moreThan, |
149 |
| BigInteger degree) throws ContradictionException { |
150 |
| |
151 |
| |
152 |
778801
| VecInt litsVec = new VecInt();
|
153 |
778801
| IVec<BigInteger> coefsVec = new Vec<BigInteger>();
|
154 |
778801
| ps.copyTo(litsVec);
|
155 |
778801
| coefs.copyTo(coefsVec);
|
156 |
| |
157 |
778801
| IDataStructurePB mpb = niceParameters(litsVec, coefsVec, moreThan,
|
158 |
| degree, voc); |
159 |
| |
160 |
778801
| if (mpb == null) {
|
161 |
0
| return null;
|
162 |
| } |
163 |
778801
| MaxWatchPb outclause = new MaxWatchPb(voc, mpb);
|
164 |
| |
165 |
778801
| if (outclause.degree.signum() <= 0)
|
166 |
0
| return null;
|
167 |
778801
| outclause.computeWatches();
|
168 |
778784
| outclause.computePropagation(s);
|
169 |
| |
170 |
778784
| return outclause;
|
171 |
| |
172 |
| } |
173 |
| |
174 |
0
| public static MaxWatchPb normalizedMaxWatchPbNew(UnitPropagationListener s,
|
175 |
| ILits voc, ArrayPb mpb) throws ContradictionException { |
176 |
0
| MaxWatchPb outclause = new MaxWatchPb(voc, mpb);
|
177 |
| |
178 |
0
| if (outclause.degree.signum() <= 0)
|
179 |
0
| return null;
|
180 |
0
| outclause.computeWatches();
|
181 |
0
| outclause.computePropagation(s);
|
182 |
| |
183 |
0
| return outclause;
|
184 |
| } |
185 |
| |
186 |
| |
187 |
| |
188 |
| |
189 |
| |
190 |
| |
191 |
| |
192 |
| |
193 |
| |
194 |
| |
195 |
327296634
| public boolean propagate(UnitPropagationListener s, int p) {
|
196 |
327296634
| voc.watch(p, this);
|
197 |
| |
198 |
| assert watchCumul.compareTo(recalcLeftSide()) >= 0 : "" + watchCumul |
199 |
| + "/" + recalcLeftSide() + ":" + learnt; |
200 |
| |
201 |
| |
202 |
327296634
| int indiceP = 0;
|
203 |
327296634
| while ((lits[indiceP] ^ 1) != p)
|
204 |
| indiceP++; |
205 |
| |
206 |
327296634
| BigInteger coefP = coefs[indiceP];
|
207 |
| |
208 |
327296634
| BigInteger newcumul = watchCumul.subtract(coefP);
|
209 |
327296634
| if (newcumul.compareTo(degree) < 0) {
|
210 |
| |
211 |
| |
212 |
| assert !isSatisfiable(); |
213 |
3579899
| return false;
|
214 |
| } |
215 |
| |
216 |
| |
217 |
323716735
| voc.undos(p).push(this);
|
218 |
323716735
| watchCumul = newcumul;
|
219 |
| |
220 |
| |
221 |
323716735
| int ind = 0;
|
222 |
323716735
| BigInteger limit = watchCumul.subtract(degree);
|
223 |
323716735
| while (ind < coefs.length
|
224 |
| && limit.compareTo(coefs[ind]) < 0) { |
225 |
460383117
| if (voc.isUnassigned(lits[ind]) && (!s.enqueue(lits[ind], this))) {
|
226 |
| assert !isSatisfiable(); |
227 |
0
| return false;
|
228 |
| } |
229 |
460383117
| ind++;
|
230 |
| } |
231 |
| |
232 |
| assert learnt || watchCumul.compareTo(recalcLeftSide()) >= 0; |
233 |
| assert watchCumul.compareTo(recalcLeftSide()) >= 0; |
234 |
323716735
| return true;
|
235 |
| } |
236 |
| |
237 |
| |
238 |
| |
239 |
| |
240 |
0
| public void remove() {
|
241 |
0
| for (int i = 0; i < lits.length; i++) {
|
242 |
0
| if (!voc.isFalsified(lits[i]))
|
243 |
0
| voc.watches(lits[i] ^ 1).remove(this);
|
244 |
| } |
245 |
| } |
246 |
| |
247 |
| |
248 |
| |
249 |
| |
250 |
| |
251 |
| |
252 |
| |
253 |
328334175
| public void undo(int p) {
|
254 |
328334175
| int indiceP = 0;
|
255 |
328334175
| while ((lits[indiceP] ^ 1) != p)
|
256 |
| indiceP++; |
257 |
| |
258 |
| assert coefs[indiceP].signum() > 0; |
259 |
| |
260 |
328334175
| watchCumul = watchCumul.add(coefs[indiceP]);
|
261 |
| } |
262 |
| |
263 |
| |
264 |
| |
265 |
| |
266 |
0
| public static WatchPb watchPbNew(ILits voc, IVecInt lits, IVecInt coefs,
|
267 |
| boolean moreThan, int degree) { |
268 |
0
| return watchPbNew(voc, lits, toVecBigInt(coefs), moreThan,
|
269 |
| toBigInt(degree)); |
270 |
| } |
271 |
| |
272 |
| |
273 |
| |
274 |
| |
275 |
189348
| public static WatchPb watchPbNew(ILits voc, IVecInt lits,
|
276 |
| IVec<BigInteger> coefs, boolean moreThan, BigInteger degree) { |
277 |
189348
| IDataStructurePB mpb = null;
|
278 |
189348
| mpb = niceCheckedParameters(lits, coefs, moreThan, degree, voc);
|
279 |
189348
| return new MaxWatchPb(voc, mpb);
|
280 |
| } |
281 |
| |
282 |
| |
283 |
| |
284 |
| |
285 |
| |
286 |
| |
287 |
| |
288 |
| |
289 |
| |
290 |
| |
291 |
246528
| public static MaxWatchPb normalizedMaxWatchPbNew(UnitPropagationListener s,
|
292 |
| ILits voc, IDataStructurePB mpb) throws ContradictionException { |
293 |
| |
294 |
246528
| MaxWatchPb outclause = new MaxWatchPb(voc, mpb);
|
295 |
| |
296 |
246528
| if (outclause.degree.signum() <= 0) {
|
297 |
0
| return null;
|
298 |
| } |
299 |
| |
300 |
246528
| outclause.computeWatches();
|
301 |
| |
302 |
246528
| outclause.computePropagation(s);
|
303 |
| |
304 |
246528
| return outclause;
|
305 |
| |
306 |
| } |
307 |
| |
308 |
| } |