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 package org.sat4j.minisat.constraints.pb;
26
27 import java.math.BigInteger;
28
29 import org.sat4j.minisat.constraints.card.AtLeast;
30 import org.sat4j.minisat.core.ILits;
31 import org.sat4j.minisat.core.UnitPropagationListener;
32 import org.sat4j.specs.ContradictionException;
33 import org.sat4j.specs.IVecInt;
34
35 public class AtLeastPB extends AtLeast implements PBConstr {
36
37
38
39
40 private static final long serialVersionUID = 1L;
41
42 private final BigInteger degree;
43
44 private AtLeastPB(ILits voc, IVecInt ps, int degree) {
45 super(voc, ps, degree);
46 this.degree = BigInteger.valueOf(degree);
47 }
48
49 public static AtLeastPB atLeastNew(UnitPropagationListener s, ILits voc,
50 IVecInt ps, int n) throws ContradictionException {
51 int degree = niceParameters(s, voc, ps, n);
52 if (degree == 0)
53 return null;
54 return new AtLeastPB(voc, ps, degree);
55 }
56
57 public static AtLeastPB atLeastNew(ILits voc, IVecInt ps, int n) {
58 return new AtLeastPB(voc, ps, n);
59 }
60
61 public BigInteger getCoef(int literal) {
62 return BigInteger.ONE;
63 }
64
65 public BigInteger getDegree() {
66 return degree;
67 }
68
69 public ILits getVocabulary() {
70 return voc;
71 }
72
73 public int[] getLits() {
74 int[] tmp = new int[size()];
75 System.arraycopy(lits, 0, tmp, 0, size());
76 return tmp;
77 }
78
79 public BigInteger[] getCoefs() {
80 BigInteger[] tmp = new BigInteger[size()];
81 for (int i = 0; i < tmp.length; i++)
82 tmp[i] = BigInteger.ONE;
83 return tmp;
84 }
85
86
87
88
89 private boolean learnt = false;
90
91
92
93
94
95
96
97 @Override
98 public boolean learnt() {
99 return learnt;
100 }
101
102 @Override
103 public void setLearnt() {
104 learnt = true;
105 }
106
107 @Override
108 public void register() {
109 assert learnt;
110
111 }
112
113 @Override
114 public void assertConstraint(UnitPropagationListener s) {
115 for (int i = 0; i < size(); i++) {
116 if (getVocabulary().isUnassigned(get(i))) {
117 boolean ret = s.enqueue(get(i), this);
118 assert ret;
119 }
120 }
121 }
122
123 public IVecInt computeAnImpliedClause() {
124 return null;
125 }
126
127 }