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
27
28
29
30 package org.sat4j.minisat.constraints;
31
32 import org.sat4j.minisat.constraints.card.AtLeast;
33 import org.sat4j.minisat.constraints.cnf.Clauses;
34 import org.sat4j.minisat.constraints.cnf.LearntWLClause;
35 import org.sat4j.minisat.constraints.cnf.Lits;
36 import org.sat4j.minisat.constraints.cnf.OriginalBinaryClause;
37 import org.sat4j.minisat.constraints.cnf.OriginalWLClause;
38 import org.sat4j.minisat.constraints.cnf.UnitClause;
39 import org.sat4j.minisat.core.Constr;
40 import org.sat4j.minisat.core.ILits;
41 import org.sat4j.specs.ContradictionException;
42 import org.sat4j.specs.IVecInt;
43
44
45
46
47
48 public class MixedDataStructureSingleWL extends AbstractDataStructureFactory {
49
50 private static final long serialVersionUID = 1L;
51
52
53
54
55
56
57
58
59 @Override
60 public Constr createCardinalityConstraint(IVecInt literals, int degree)
61 throws ContradictionException {
62 return AtLeast.atLeastNew(this.solver, getVocabulary(), literals,
63 degree);
64 }
65
66 @Override
67 public Constr createUnregisteredCardinalityConstraint(IVecInt literals,
68 int degree) {
69 return new AtLeast(getVocabulary(), literals, degree);
70 }
71
72
73
74
75
76
77
78
79 public Constr createClause(IVecInt literals) throws ContradictionException {
80 IVecInt v = Clauses.sanityCheck(literals, getVocabulary(), this.solver);
81 if (v == null) {
82
83 return null;
84 }
85 if (v.size() == 1) {
86 return new UnitClause(v.last());
87 }
88 if (v.size() == 2) {
89 return OriginalBinaryClause.brandNewClause(this.solver,
90 getVocabulary(), v);
91 }
92 return OriginalWLClause.brandNewClause(this.solver, getVocabulary(), v);
93 }
94
95 public Constr createUnregisteredClause(IVecInt literals) {
96 return new LearntWLClause(literals, getVocabulary());
97 }
98
99 @Override
100 protected ILits createLits() {
101 return new Lits();
102 }
103 }