| 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 |
|
package org.sat4j.tools; |
| 26 |
|
|
| 27 |
|
import java.io.Serializable; |
| 28 |
|
|
| 29 |
|
import org.sat4j.specs.ContradictionException; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@author |
| 38 |
|
@author |
| 39 |
|
@author |
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 5 |
Complexity Density: 0,29 |
|
| 41 |
|
public class DimacsArrayToDimacsConverter implements Serializable { |
| 42 |
|
|
| 43 |
|
private static final long serialVersionUID = 1L; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
protected int clauses; |
| 47 |
|
|
| 48 |
|
protected StringBuilder dimacs; |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
private final int bufSize; |
| 52 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 53 |
0
|
public DimacsArrayToDimacsConverter(int bufSize) {... |
| 54 |
0
|
this.bufSize = bufSize; |
| 55 |
|
} |
| 56 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,33 |
|
| 57 |
0
|
protected boolean handleConstr(int gateType, int output, int[] inputs)... |
| 58 |
|
throws ContradictionException { |
| 59 |
0
|
for (int var : inputs) { |
| 60 |
0
|
this.dimacs.append(var); |
| 61 |
0
|
this.dimacs.append(" "); |
| 62 |
|
} |
| 63 |
0
|
this.dimacs.append("0\n"); |
| 64 |
0
|
++this.clauses; |
| 65 |
0
|
return true; |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
@param |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
@param |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
@param |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
@param |
| 81 |
|
|
| 82 |
|
@throws |
| 83 |
|
|
| 84 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 3 |
Complexity Density: 0,2 |
|
| 85 |
0
|
public String parseInstance(int[] gateType, int[] outputs, int[][] inputs,... |
| 86 |
|
int maxVar) throws ContradictionException { |
| 87 |
0
|
init(); |
| 88 |
0
|
this.dimacs.append(maxVar); |
| 89 |
0
|
this.dimacs.append(" "); |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
0
|
int firstCharPos = 7 + Integer.toString(maxVar).length(); |
| 94 |
|
|
| 95 |
0
|
this.dimacs.append(" "); |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
0
|
this.dimacs.append("\n"); |
| 100 |
0
|
for (int i = 0; i < outputs.length; ++i) { |
| 101 |
0
|
handleConstr(gateType[i], outputs[i], inputs[i]); |
| 102 |
|
} |
| 103 |
0
|
String numClauses = Integer.toString(this.clauses); |
| 104 |
0
|
int numClausesLength = numClauses.length(); |
| 105 |
0
|
for (int i = 0; i < numClausesLength; ++i) { |
| 106 |
0
|
this.dimacs.setCharAt(firstCharPos + i, numClauses.charAt(i)); |
| 107 |
|
} |
| 108 |
0
|
String result = this.dimacs.toString(); |
| 109 |
0
|
this.dimacs = null; |
| 110 |
0
|
return result; |
| 111 |
|
} |
| 112 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 113 |
0
|
protected void init() {... |
| 114 |
0
|
this.dimacs = new StringBuilder(this.bufSize); |
| 115 |
0
|
this.dimacs.append("p cnf "); |
| 116 |
0
|
this.clauses = 0; |
| 117 |
|
} |
| 118 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
| 119 |
0
|
public String decode(int[] model) {... |
| 120 |
0
|
StringBuilder stb = new StringBuilder(); |
| 121 |
0
|
for (int i = 0; i < model.length; i++) { |
| 122 |
0
|
stb.append(model[i]); |
| 123 |
0
|
stb.append(" "); |
| 124 |
|
} |
| 125 |
0
|
stb.append("0"); |
| 126 |
0
|
return stb.toString(); |
| 127 |
|
} |
| 128 |
|
} |