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