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 package org.sat4j.minisat.constraints;
27
28 import java.math.BigInteger;
29
30 import org.sat4j.core.VecInt;
31 import org.sat4j.minisat.constraints.cnf.LearntWLClause;
32 import org.sat4j.minisat.constraints.cnf.Lits;
33 import org.sat4j.minisat.constraints.cnf.WLClause;
34 import org.sat4j.minisat.constraints.pb.IInternalPBConstraintCreator;
35 import org.sat4j.minisat.constraints.pb.PBConstr;
36 import org.sat4j.minisat.core.Constr;
37 import org.sat4j.minisat.core.ILits;
38 import org.sat4j.specs.ContradictionException;
39 import org.sat4j.specs.IConstr;
40 import org.sat4j.specs.IVec;
41 import org.sat4j.specs.IVecInt;
42
43
44
45
46
47 public abstract class AbstractPBDataStructureFactory extends
48 AbstractDataStructureFactory<ILits> implements IInternalPBConstraintCreator {
49
50 public Constr createClause(IVecInt literals) throws ContradictionException {
51 IVecInt v = WLClause.sanityCheck(literals, getVocabulary(), solver);
52 if (v == null)
53 return null;
54 IVecInt coefs = new VecInt(v.size(), 1);
55 return constraintFactory(v, coefs, true, 1);
56 }
57
58 public Constr createUnregisteredClause(IVecInt literals) {
59 return new LearntWLClause(literals, getVocabulary());
60 }
61
62 @Override
63 public Constr createCardinalityConstraint(IVecInt literals, int degree)
64 throws ContradictionException {
65 IVecInt coefs = new VecInt(literals.size(), 1);
66 return constraintFactory(literals, coefs, true, degree);
67 }
68
69 @Override
70 public Constr createPseudoBooleanConstraint(IVecInt literals,
71 IVec<BigInteger> coefs, boolean moreThan, BigInteger degree)
72 throws ContradictionException {
73 return constraintFactory(literals, coefs, moreThan, degree);
74 }
75
76
77
78
79
80
81
82
83 protected abstract PBConstr constraintFactory(IVecInt literals,
84 IVecInt coefs, boolean moreThan, int degree)
85 throws ContradictionException;
86
87 protected abstract PBConstr constraintFactory(IVecInt literals,
88 IVec<BigInteger> coefs, boolean moreThan, BigInteger degree)
89 throws ContradictionException;
90
91 @Override
92 public Constr createUnregisteredPseudoBooleanConstraint(IVecInt literals,
93 IVec<BigInteger> coefs, BigInteger degree) {
94 return constraintFactory(literals, coefs, degree);
95 }
96
97 public IConstr createUnregisteredPseudoBooleanConstraint(IVecInt literals,
98 IVec<BigInteger> coefs, boolean moreThan, BigInteger degree)
99 throws ContradictionException {
100 return constraintFactory(literals, coefs, moreThan, degree);
101 }
102
103
104
105
106
107
108
109 protected abstract PBConstr constraintFactory(IVecInt literals,
110 IVecInt coefs, int degree);
111
112 protected abstract PBConstr constraintFactory(IVecInt literals,
113 IVec<BigInteger> coefs, BigInteger degree);
114
115 @Override
116 protected ILits createLits() {
117 return new Lits();
118 }
119
120 }