1 |
| package org.sat4j.minisat.constraints.pb; |
2 |
| |
3 |
| import java.math.BigInteger; |
4 |
| |
5 |
| import org.sat4j.minisat.constraints.card.AtLeast; |
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 AtLeastPB extends AtLeast implements PBConstr { |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| private static final long serialVersionUID = 1L; |
18 |
| |
19 |
| private final BigInteger degree; |
20 |
| |
21 |
11768
| private AtLeastPB(ILits voc, IVecInt ps, int degree) {
|
22 |
11768
| super(voc, ps, degree);
|
23 |
11768
| this.degree = new BigInteger(String.valueOf(degree));
|
24 |
| } |
25 |
| |
26 |
9206
| public static AtLeastPB atLeastNew(UnitPropagationListener s, ILits voc,
|
27 |
| IVecInt ps, int n) throws ContradictionException { |
28 |
9206
| int degree = niceParameters(s, voc, ps, n);
|
29 |
9206
| if (degree == 0)
|
30 |
0
| return null;
|
31 |
9206
| return new AtLeastPB(voc, ps, degree);
|
32 |
| } |
33 |
| |
34 |
2562
| public static AtLeastPB atLeastNew(ILits voc, IVecInt ps, int n) {
|
35 |
2562
| return new AtLeastPB(voc, ps, n);
|
36 |
| } |
37 |
| |
38 |
1125966
| public BigInteger getCoef(int literal) {
|
39 |
1125966
| return BigInteger.ONE;
|
40 |
| } |
41 |
| |
42 |
55772
| public BigInteger getDegree() {
|
43 |
55772
| return degree;
|
44 |
| } |
45 |
| |
46 |
325073
| public ILits getVocabulary() {
|
47 |
325073
| return voc;
|
48 |
| } |
49 |
| |
50 |
5611
| public int[] getLits() {
|
51 |
5611
| int[] tmp = new int[size()];
|
52 |
5611
| System.arraycopy(lits, 0, tmp, 0, size());
|
53 |
5611
| return tmp;
|
54 |
| } |
55 |
| |
56 |
5611
| public BigInteger[] getCoefs() {
|
57 |
5611
| BigInteger[] tmp = new BigInteger[size()];
|
58 |
5611
| for (int i = 0; i < tmp.length; i++)
|
59 |
65413
| tmp[i] = BigInteger.ONE;
|
60 |
5611
| return tmp;
|
61 |
| } |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| private boolean learnt = false; |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
0
| public boolean learnt() {
|
75 |
0
| return learnt;
|
76 |
| } |
77 |
| |
78 |
5124
| public void setLearnt() {
|
79 |
5124
| learnt = true;
|
80 |
| } |
81 |
| |
82 |
2562
| public void register() {
|
83 |
| assert learnt; |
84 |
| |
85 |
| } |
86 |
| |
87 |
2562
| public void assertConstraint(UnitPropagationListener s) {
|
88 |
2562
| for (int i = 0; i < size(); i++) {
|
89 |
319462
| if (getVocabulary().isUnassigned(get(i))) {
|
90 |
12301
| boolean ret = s.enqueue(get(i), this);
|
91 |
| assert ret; |
92 |
| } |
93 |
| } |
94 |
| } |
95 |
| |
96 |
0
| public IVecInt computeAnImpliedClause() {
|
97 |
0
| return null;
|
98 |
| } |
99 |
| |
100 |
| |
101 |
| } |