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