1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.sat4j.minisat.constraints; |
8 |
| |
9 |
| import java.math.BigInteger; |
10 |
| |
11 |
| import org.sat4j.core.VecInt; |
12 |
| import org.sat4j.minisat.constraints.cnf.WLClause; |
13 |
| import org.sat4j.minisat.constraints.pb.IInternalPBConstraintCreator; |
14 |
| import org.sat4j.minisat.constraints.pb.PBConstr; |
15 |
| import org.sat4j.minisat.core.Constr; |
16 |
| import org.sat4j.specs.ContradictionException; |
17 |
| import org.sat4j.specs.IConstr; |
18 |
| import org.sat4j.specs.IVec; |
19 |
| import org.sat4j.specs.IVecInt; |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| public abstract class AbstractPBDataStructureFactory extends |
26 |
| AbstractDataStructureFactory implements IInternalPBConstraintCreator { |
27 |
| |
28 |
| |
29 |
| |
30 |
1003704
| public Constr createClause(IVecInt literals) throws ContradictionException {
|
31 |
1003704
| IVecInt v = WLClause.sanityCheck(literals, getVocabulary(), solver);
|
32 |
1003704
| if (v == null)
|
33 |
52
| return null;
|
34 |
1003652
| IVecInt coefs = new VecInt(v.size(), 1);
|
35 |
1003652
| return constraintFactory(v, coefs, true, 1);
|
36 |
| } |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
12860043
| public Constr createUnregisteredClause(IVecInt literals) {
|
42 |
12860043
| return new WLClause(literals, getVocabulary());
|
43 |
| } |
44 |
| |
45 |
0
| @Override
|
46 |
| public Constr createCardinalityConstraint(IVecInt literals, int degree) |
47 |
| throws ContradictionException { |
48 |
0
| IVecInt coefs = new VecInt(literals.size(), 1);
|
49 |
0
| return constraintFactory(literals, coefs, true, degree);
|
50 |
| } |
51 |
| |
52 |
1675145
| @Override
|
53 |
| public Constr createPseudoBooleanConstraint(IVecInt literals, |
54 |
| IVec<BigInteger> coefs, boolean moreThan, BigInteger degree) |
55 |
| throws ContradictionException { |
56 |
1675145
| return constraintFactory(literals, coefs, moreThan, degree);
|
57 |
| } |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| protected abstract PBConstr constraintFactory(IVecInt literals, |
67 |
| IVecInt coefs, boolean moreThan, int degree) |
68 |
| throws ContradictionException; |
69 |
| |
70 |
| protected abstract PBConstr constraintFactory(IVecInt literals, |
71 |
| IVec<BigInteger> coefs, boolean moreThan, BigInteger degree) |
72 |
| throws ContradictionException; |
73 |
| |
74 |
519009
| @Override
|
75 |
| public Constr createUnregisteredPseudoBooleanConstraint(IVecInt literals, |
76 |
| IVec<BigInteger> coefs, BigInteger degree) { |
77 |
519009
| return constraintFactory(literals, coefs, degree);
|
78 |
| } |
79 |
| |
80 |
0
| public IConstr createUnregisteredPseudoBooleanConstraint(IVecInt literals,
|
81 |
| IVec<BigInteger> coefs, boolean moreThan, BigInteger degree) |
82 |
| throws ContradictionException { |
83 |
0
| return constraintFactory(literals, coefs, moreThan, degree);
|
84 |
| } |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| protected abstract PBConstr constraintFactory(IVecInt literals, |
93 |
| IVecInt coefs, int degree); |
94 |
| |
95 |
| protected abstract PBConstr constraintFactory(IVecInt literals, |
96 |
| IVec<BigInteger> coefs, BigInteger degree); |
97 |
| |
98 |
| } |