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 org.sat4j.minisat.constraints.cnf.LearntWLClause;
29 import org.sat4j.minisat.constraints.cnf.Lits23;
30 import org.sat4j.minisat.constraints.cnf.WLClause;
31 import org.sat4j.minisat.core.Constr;
32 import org.sat4j.minisat.core.ILits23;
33 import org.sat4j.specs.ContradictionException;
34 import org.sat4j.specs.IVecInt;
35
36
37
38
39
40 public class MixedDataStructureWithBinaryAndTernary extends
41 AbstractDataStructureFactory<ILits23> {
42
43 private static final long serialVersionUID = 1L;
44
45
46
47
48
49
50
51 public Constr createClause(IVecInt literals) throws ContradictionException {
52 IVecInt v = WLClause.sanityCheck(literals, lits, solver);
53 if (v == null)
54 return null;
55 if (v.size() == 2) {
56 lits.binaryClauses(v.get(0), v.get(1));
57 return null;
58 }
59 if (v.size() == 3) {
60 lits.ternaryClauses(v.get(0), v.get(1), v.get(2));
61 return null;
62 }
63 return WLClause.brandNewClause(solver, lits, v);
64 }
65
66
67
68
69
70
71 @Override
72 public void learnConstraint(Constr constr) {
73 if (constr.size() == 2) {
74 lits.binaryClauses(constr.get(0), constr.get(1));
75
76 } else if (constr.size() == 3) {
77 lits.ternaryClauses(constr.get(0), constr.get(1), constr.get(2));
78
79 } else {
80 super.learnConstraint(constr);
81 }
82 }
83
84 @Override
85 protected ILits23 createLits() {
86 return new Lits23();
87 }
88
89 public Constr createUnregisteredClause(IVecInt literals) {
90 return new LearntWLClause(literals, getVocabulary());
91 }
92
93 }