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.tools;
29
30 import java.io.ObjectInputStream;
31 import java.io.PrintStream;
32 import java.io.PrintWriter;
33 import java.util.Map;
34
35 import org.sat4j.specs.ContradictionException;
36 import org.sat4j.specs.IConstr;
37 import org.sat4j.specs.ISolver;
38 import org.sat4j.specs.IVec;
39 import org.sat4j.specs.IVecInt;
40 import org.sat4j.specs.IteratorInt;
41 import org.sat4j.specs.TimeoutException;
42
43
44
45
46
47
48
49
50
51 public class DimacsOutputSolver implements ISolver {
52
53
54
55
56 private static final long serialVersionUID = 1L;
57
58 private transient PrintWriter out;
59
60 private int nbvars;
61
62 private int nbclauses;
63
64 private boolean fixedNbClauses = false;
65
66 private boolean firstConstr = true;
67
68 public DimacsOutputSolver() {
69 this(new PrintWriter(System.out, true));
70 }
71
72 public DimacsOutputSolver(PrintWriter pw) {
73 out = pw;
74 }
75
76 private void readObject(ObjectInputStream stream) {
77 out = new PrintWriter(System.out, true);
78 }
79
80 public int newVar() {
81 return 0;
82 }
83
84 public int newVar(int howmany) {
85 out.print("p cnf " + howmany);
86 nbvars = howmany;
87 return 0;
88 }
89
90 public void setExpectedNumberOfClauses(int nb) {
91 out.println(" " + nb);
92 nbclauses = nb;
93 fixedNbClauses = true;
94 }
95
96 public IConstr addClause(IVecInt literals) throws ContradictionException {
97 if (firstConstr) {
98 if (!fixedNbClauses) {
99 out.println(" XXXXXX");
100 }
101 firstConstr = false;
102 }
103 for (IteratorInt iterator = literals.iterator();iterator.hasNext();)
104 out.print(iterator.next() + " ");
105 out.println("0");
106 return null;
107 }
108
109 public boolean removeConstr(IConstr c) {
110 throw new UnsupportedOperationException();
111 }
112
113 public void addAllClauses(IVec<IVecInt> clauses)
114 throws ContradictionException {
115 throw new UnsupportedOperationException();
116 }
117
118 public IConstr addAtMost(IVecInt literals, int degree)
119 throws ContradictionException {
120 if (degree > 1) {
121 throw new UnsupportedOperationException(
122 "Not a clausal problem! degree " + degree);
123 }
124 assert degree == 1;
125 if (firstConstr) {
126 if (!fixedNbClauses) {
127 out.println("XXXXXX");
128 }
129 firstConstr = false;
130 }
131 for (int i = 0; i <= literals.size(); i++) {
132 for (int j = i + 1; j < literals.size(); j++) {
133 out.println("" + (-literals.get(i)) + " " + (-literals.get(j))
134 + " 0");
135 }
136 }
137 return null;
138 }
139
140 public IConstr addAtLeast(IVecInt literals, int degree)
141 throws ContradictionException {
142 if (degree > 1) {
143 throw new UnsupportedOperationException(
144 "Not a clausal problem! degree " + degree);
145 }
146 assert degree == 1;
147 return addClause(literals);
148 }
149
150 public void setTimeout(int t) {
151
152 }
153
154 public void setTimeoutMs(long t) {
155
156 }
157
158 public int getTimeout() {
159 return 0;
160 }
161
162 public long getTimeoutMs() {
163 return 0L;
164 }
165
166 public void reset() {
167 fixedNbClauses = false;
168 firstConstr = true;
169
170 }
171
172 public void printStat(PrintStream output, String prefix) {
173
174
175 }
176
177 public void printStat(PrintWriter output, String prefix) {
178
179
180 }
181
182 public Map<String, Number> getStat() {
183
184 return null;
185 }
186
187 public String toString(String prefix) {
188 return "Dimacs output solver";
189 }
190
191 public void clearLearntClauses() {
192
193
194 }
195
196 public int[] model() {
197 throw new UnsupportedOperationException();
198 }
199
200 public boolean model(int var) {
201 throw new UnsupportedOperationException();
202 }
203
204 public boolean isSatisfiable() throws TimeoutException {
205 throw new TimeoutException("There is no real solver behind!");
206 }
207
208 public boolean isSatisfiable(IVecInt assumps) throws TimeoutException {
209 throw new TimeoutException("There is no real solver behind!");
210 }
211
212 public int[] findModel() throws TimeoutException {
213 throw new UnsupportedOperationException();
214 }
215
216 public int[] findModel(IVecInt assumps) throws TimeoutException {
217 throw new UnsupportedOperationException();
218 }
219
220 public int nConstraints() {
221 return nbclauses;
222 }
223
224 public int nVars() {
225 return nbvars;
226 }
227
228 public void expireTimeout() {
229
230
231 }
232
233 public boolean isSatisfiable(IVecInt assumps, boolean global)
234 throws TimeoutException {
235 throw new TimeoutException("There is no real solver behind!");
236 }
237
238 public boolean isSatisfiable(boolean global) throws TimeoutException {
239 throw new TimeoutException("There is no real solver behind!");
240 }
241
242 public void printInfos(PrintWriter output, String prefix) {
243 }
244
245 public void setTimeoutOnConflicts(int count) {
246 }
247
248 public boolean isDBSimplificationAllowed() {
249 return false;
250 }
251
252 public void setDBSimplificationAllowed(boolean status) {
253 }
254
255 }