1 |
| package org.sat4j.minisat.constraints.pb; |
2 |
| |
3 |
| import java.math.BigInteger; |
4 |
| |
5 |
| import org.sat4j.minisat.constraints.card.MinWatchCard; |
6 |
| import org.sat4j.minisat.core.Constr; |
7 |
| import org.sat4j.minisat.core.ILits; |
8 |
| import org.sat4j.minisat.core.UnitPropagationListener; |
9 |
| import org.sat4j.specs.ContradictionException; |
10 |
| import org.sat4j.specs.IVecInt; |
11 |
| |
12 |
| public class MinWatchCardPB extends MinWatchCard implements PBConstr { |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| private static final long serialVersionUID = 1L; |
18 |
| |
19 |
| private final BigInteger degree; |
20 |
| |
21 |
2544
| public MinWatchCardPB(ILits voc, IVecInt ps, boolean moreThan, int degree) {
|
22 |
2544
| super(voc, ps, moreThan, degree);
|
23 |
2544
| this.degree = new BigInteger(String.valueOf(degree));
|
24 |
| } |
25 |
| |
26 |
18412
| public MinWatchCardPB(ILits voc, IVecInt ps, int degree) {
|
27 |
18412
| super(voc, ps, degree);
|
28 |
18412
| this.degree = new BigInteger(String.valueOf(degree));
|
29 |
| } |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
2418979
| public BigInteger getCoef(int literal) {
|
37 |
2418979
| return BigInteger.ONE;
|
38 |
| } |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
76975
| public BigInteger getDegree() {
|
46 |
76975
| return degree;
|
47 |
| } |
48 |
| |
49 |
8362
| public BigInteger[] getCoefs() {
|
50 |
8362
| BigInteger[] tmp = new BigInteger[size()];
|
51 |
8362
| for (int i = 0; i < tmp.length; i++)
|
52 |
317358
| tmp[i] = BigInteger.ONE;
|
53 |
8362
| return tmp;
|
54 |
| } |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
18412
| public static MinWatchCardPB normalizedMinWatchCardPBNew(
|
71 |
| UnitPropagationListener s, ILits voc, IVecInt ps, int degree) |
72 |
| throws ContradictionException { |
73 |
18412
| return minWatchCardPBNew(s, voc, ps, ATLEAST, degree, true);
|
74 |
| } |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
0
| public static MinWatchCardPB minWatchCardPBNew(UnitPropagationListener s,
|
93 |
| ILits voc, IVecInt ps, boolean moreThan, int degree) |
94 |
| throws ContradictionException { |
95 |
0
| return minWatchCardPBNew(s, voc, ps, moreThan, degree, false);
|
96 |
| } |
97 |
| |
98 |
18412
| private static MinWatchCardPB minWatchCardPBNew(UnitPropagationListener s,
|
99 |
| ILits voc, IVecInt ps, boolean moreThan, int degree, |
100 |
| boolean normalized) throws ContradictionException { |
101 |
18412
| int mydegree = degree + linearisation(voc, ps);
|
102 |
| |
103 |
18412
| if (ps.size() == 0 && mydegree > 0) {
|
104 |
0
| throw new ContradictionException();
|
105 |
18412
| } else if (ps.size() == mydegree || ps.size() <= 0) {
|
106 |
0
| for (int i = 0; i < ps.size(); i++)
|
107 |
0
| if (!s.enqueue(ps.get(i))) {
|
108 |
0
| throw new ContradictionException();
|
109 |
| } |
110 |
0
| return null;
|
111 |
| } |
112 |
| |
113 |
| |
114 |
18412
| MinWatchCardPB retour = null;
|
115 |
18412
| if (normalized)
|
116 |
18412
| retour = new MinWatchCardPB(voc, ps, mydegree);
|
117 |
| else |
118 |
0
| retour = new MinWatchCardPB(voc, ps, moreThan, mydegree);
|
119 |
| |
120 |
18412
| if (retour.degree.signum() <= 0)
|
121 |
0
| return null;
|
122 |
| |
123 |
18412
| retour.computeWatches();
|
124 |
| |
125 |
18412
| return ((MinWatchCardPB) retour.computePropagation(s));
|
126 |
| } |
127 |
| |
128 |
| |
129 |
| |
130 |
| |
131 |
| private boolean learnt = false; |
132 |
| |
133 |
| |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
20956
| public boolean learnt() {
|
140 |
20956
| return learnt;
|
141 |
| } |
142 |
| |
143 |
5088
| public void setLearnt() {
|
144 |
5088
| learnt = true;
|
145 |
| } |
146 |
| |
147 |
2544
| public void register() {
|
148 |
| assert learnt; |
149 |
2544
| computeWatches();
|
150 |
| } |
151 |
| |
152 |
2544
| public void assertConstraint(UnitPropagationListener s) {
|
153 |
2544
| for (int i = 0; i < size(); i++) {
|
154 |
486546
| if (getVocabulary().isUnassigned(get(i))) {
|
155 |
19459
| boolean ret = s.enqueue(get(i), this);
|
156 |
| assert ret; |
157 |
| } |
158 |
| } |
159 |
| } |
160 |
| |
161 |
0
| public IVecInt computeAnImpliedClause() {
|
162 |
0
| return null;
|
163 |
| } |
164 |
| |
165 |
| } |