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.cnf;
29
30 import java.io.Serializable;
31
32 import org.sat4j.core.VecInt;
33 import org.sat4j.minisat.core.Constr;
34 import org.sat4j.minisat.core.ILits;
35 import org.sat4j.minisat.core.UnitPropagationListener;
36 import org.sat4j.specs.IVecInt;
37
38
39
40
41
42 public class TernaryClauses implements Constr, Serializable {
43
44 private static final long serialVersionUID = 1L;
45
46 private final IVecInt stubs = new VecInt();
47
48 private final ILits voc;
49
50 private final int phead;
51
52 public TernaryClauses(ILits voc, int p) {
53 this.voc = voc;
54 this.phead = p;
55 }
56
57 public void addTernaryClause(int a, int b) {
58 stubs.push(a);
59 stubs.push(b);
60 }
61
62
63
64
65
66
67 public void remove() {
68
69 }
70
71
72
73
74
75
76
77 public boolean propagate(UnitPropagationListener s, int p) {
78 assert voc.isSatisfied(p);
79 assert voc.isFalsified(phead);
80 voc.attach(p, this);
81 for (int i = 0; i < stubs.size(); i += 2) {
82 int a = stubs.get(i);
83 int b = stubs.get(i + 1);
84 if (voc.isSatisfied(a) || voc.isSatisfied(b)) {
85 continue;
86 }
87 if (voc.isFalsified(a) && !s.enqueue(b, this)) {
88 return false;
89 } else if (voc.isFalsified(b) && !s.enqueue(a, this)) {
90 return false;
91 }
92 }
93 return true;
94 }
95
96
97
98
99
100
101 public boolean simplify() {
102 return false;
103 }
104
105
106
107
108
109
110 public void undo(int p) {
111 }
112
113
114
115
116
117
118 public void calcReason(int p, IVecInt outReason) {
119 assert voc.isFalsified(this.phead);
120 if (p == ILits.UNDEFINED) {
121 int i = 0;
122 while (!voc.isFalsified(stubs.get(i))
123 || !voc.isFalsified(stubs.get(i + 1))) {
124 i += 2;
125 }
126 outReason.push(this.phead ^ 1);
127 outReason.push(stubs.get(i) ^ 1);
128 outReason.push(stubs.get(i + 1) ^ 1);
129 } else {
130 outReason.push(this.phead ^ 1);
131 int i = 0;
132 while ((stubs.get(i) != p) || (!voc.isFalsified(stubs.get(i ^ 1)))) {
133 i++;
134 }
135 assert !voc.isFalsified(stubs.get(i));
136 outReason.push(stubs.get(i ^ 1) ^ 1);
137 assert voc.isFalsified(stubs.get(i ^ 1));
138 }
139
140 }
141
142
143
144
145
146
147 public boolean learnt() {
148 return false;
149 }
150
151
152
153
154
155
156 public void incActivity(double claInc) {
157 }
158
159
160
161
162
163
164 public double getActivity() {
165 return 0;
166 }
167
168
169
170
171
172
173 public boolean locked() {
174
175 return false;
176 }
177
178
179
180
181
182
183 public void setLearnt() {
184
185 }
186
187
188
189
190
191
192 public void register() {
193
194 }
195
196
197
198
199
200
201 public void rescaleBy(double d) {
202
203 }
204
205
206
207
208
209
210 public int size() {
211 return stubs.size();
212 }
213
214
215
216
217
218
219 public int get(int i) {
220 throw new UnsupportedOperationException();
221 }
222
223 public void assertConstraint(UnitPropagationListener s) {
224 throw new UnsupportedOperationException();
225 }
226 }