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