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 package org.sat4j.pb.constraints.pb;
29
30 import java.math.BigInteger;
31
32 import org.sat4j.core.Vec;
33 import org.sat4j.core.VecInt;
34 import org.sat4j.minisat.core.ILits;
35 import org.sat4j.minisat.core.UnitPropagationListener;
36 import org.sat4j.specs.ContradictionException;
37 import org.sat4j.specs.IVec;
38 import org.sat4j.specs.IVecInt;
39
40 public class PuebloMinWatchPb extends MinWatchPb {
41
42 private static final long serialVersionUID = 1L;
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 private PuebloMinWatchPb(ILits voc, IDataStructurePB mpb) {
59
60 super(voc, mpb);
61 }
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public static PuebloMinWatchPb minWatchPbNew(UnitPropagationListener s,
78 ILits voc, IVecInt ps, IVecInt coefs, boolean moreThan, int degree)
79 throws ContradictionException {
80 return minWatchPbNew(s, voc, ps, Pseudos.toVecBigInt(coefs), moreThan,
81 BigInteger.valueOf(degree));
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 public static PuebloMinWatchPb minWatchPbNew(UnitPropagationListener s,
99 ILits voc, IVecInt ps, IVec<BigInteger> coefs, boolean moreThan,
100 BigInteger degree) throws ContradictionException {
101
102 VecInt litsVec = new VecInt(ps.size());
103 IVec<BigInteger> coefsVec = new Vec<BigInteger>(coefs.size());
104 ps.copyTo(litsVec);
105 coefs.copyTo(coefsVec);
106
107
108 IDataStructurePB mpb = Pseudos.niceParameters(litsVec, coefsVec, moreThan,
109 degree, voc);
110 PuebloMinWatchPb outclause = new PuebloMinWatchPb(voc, mpb);
111
112 if (outclause.degree.signum() <= 0) {
113 return null;
114 }
115
116 outclause.computeWatches();
117
118 outclause.computePropagation(s);
119
120 return outclause;
121
122 }
123
124 public static PuebloMinWatchPb minWatchPbNew(UnitPropagationListener s,
125 ILits voc, IDataStructurePB mpb) throws ContradictionException {
126 PuebloMinWatchPb outclause = new PuebloMinWatchPb(voc, mpb);
127
128 if (outclause.degree.signum() <= 0) {
129 return null;
130 }
131
132 outclause.computeWatches();
133
134 outclause.computePropagation(s);
135
136 return outclause;
137
138 }
139
140
141
142
143 public static WatchPb watchPbNew(ILits voc, IVecInt lits, IVecInt coefs,
144 boolean moreThan, int degree) {
145 return watchPbNew(voc, lits, Pseudos.toVecBigInt(coefs), moreThan,
146 BigInteger.valueOf(degree));
147 }
148
149
150
151
152 public static WatchPb watchPbNew(ILits voc, IVecInt lits,
153 IVec<BigInteger> coefs, boolean moreThan, BigInteger degree) {
154 IDataStructurePB mpb = null;
155 mpb = Pseudos.niceCheckedParameters(lits, coefs, moreThan, degree, voc);
156 return new PuebloMinWatchPb(voc, mpb);
157 }
158
159 public static WatchPb normalizedWatchPbNew(ILits voc, IDataStructurePB mpb) {
160 return new PuebloMinWatchPb(voc, mpb);
161 }
162
163 @Override
164 protected BigInteger maximalCoefficient(int pIndice) {
165 return coefs[0];
166 }
167
168 @Override
169 protected BigInteger updateWatched(BigInteger mc, int pIndice) {
170 BigInteger maxCoef = mc;
171 if (watchingCount < size()) {
172 BigInteger upWatchCumul = watchCumul.subtract(coefs[pIndice]);
173 BigInteger borneSup = degree.add(maxCoef);
174 for (int ind = 0; ind < lits.length
175 && upWatchCumul.compareTo(borneSup) < 0; ind++) {
176 if (!voc.isFalsified(lits[ind]) && !watched[ind]) {
177 upWatchCumul = upWatchCumul.add(coefs[ind]);
178 watched[ind] = true;
179 assert watchingCount < size();
180 watching[watchingCount++] = ind;
181 voc.attach(lits[ind] ^ 1, this);
182 }
183 }
184 watchCumul = upWatchCumul.add(coefs[pIndice]);
185 }
186 return maxCoef;
187 }
188
189 }