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
27
28
29
30 package org.sat4j.pb.constraints.pb;
31
32 import java.math.BigInteger;
33
34 import org.sat4j.minisat.core.ILits;
35 import org.sat4j.specs.ContradictionException;
36 import org.sat4j.specs.UnitPropagationListener;
37
38 public final class PuebloMinWatchPb extends MinWatchPb {
39
40 private static final long serialVersionUID = 1L;
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 private PuebloMinWatchPb(ILits voc, int[] lits, BigInteger[] coefs,
57 BigInteger degree, BigInteger sumCoefs) {
58 super(voc, lits, coefs, degree, sumCoefs);
59 }
60
61 private PuebloMinWatchPb(ILits voc, IDataStructurePB mpb) {
62
63 super(voc, mpb);
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 public static PuebloMinWatchPb normalizedMinWatchPbNew(
81 UnitPropagationListener s, ILits voc, int[] lits,
82 BigInteger[] coefs, BigInteger degree)
83 throws ContradictionException {
84
85 BigInteger sumCoefs = BigInteger.ZERO;
86 for (BigInteger c : coefs) {
87 sumCoefs = sumCoefs.add(c);
88 }
89 PuebloMinWatchPb outclause = new PuebloMinWatchPb(voc, lits, coefs,
90 degree, sumCoefs);
91
92 if (outclause.degree.signum() <= 0) {
93 return null;
94 }
95
96 outclause.computeWatches();
97
98 outclause.computePropagation(s);
99
100 return outclause;
101
102 }
103
104 public static WatchPb normalizedWatchPbNew(ILits voc, IDataStructurePB mpb) {
105 return new PuebloMinWatchPb(voc, mpb);
106 }
107
108 @Override
109 protected BigInteger maximalCoefficient(int pIndice) {
110 return this.coefs[0];
111 }
112
113 @Override
114 protected BigInteger updateWatched(BigInteger mc, int pIndice) {
115 BigInteger maxCoef = mc;
116 if (this.watchingCount < size()) {
117 BigInteger upWatchCumul = this.watchCumul
118 .subtract(this.coefs[pIndice]);
119 BigInteger borneSup = this.degree.add(maxCoef);
120 for (int ind = 0; ind < this.lits.length
121 && upWatchCumul.compareTo(borneSup) < 0; ind++) {
122 if (!this.voc.isFalsified(this.lits[ind]) && !this.watched[ind]) {
123 upWatchCumul = upWatchCumul.add(this.coefs[ind]);
124 this.watched[ind] = true;
125 assert this.watchingCount < size();
126 this.watching[this.watchingCount++] = ind;
127 this.voc.watch(this.lits[ind] ^ 1, this);
128 }
129 }
130 this.watchCumul = upWatchCumul.add(this.coefs[pIndice]);
131 }
132 return maxCoef;
133 }
134
135 }