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.reader; |
26 |
|
|
27 |
|
import java.io.IOException; |
28 |
|
import java.io.LineNumberReader; |
29 |
|
import java.util.StringTokenizer; |
30 |
|
|
31 |
|
import org.sat4j.core.VecInt; |
32 |
|
import org.sat4j.specs.ContradictionException; |
33 |
|
import org.sat4j.specs.ISolver; |
34 |
|
import org.sat4j.specs.IVecInt; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@author |
40 |
|
|
41 |
|
@Deprecated |
|
|
| 0% |
Uncovered Elements: 70 (70) |
Complexity: 16 |
Complexity Density: 0,42 |
|
42 |
|
public class CardDimacsReader extends DimacsReader { |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
private static final long serialVersionUID = 3258130241376368435L; |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
0
|
public CardDimacsReader(ISolver solver) {... |
50 |
0
|
super(solver); |
51 |
|
} |
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
|
56 |
|
@throws |
57 |
|
|
58 |
|
@throws |
59 |
|
|
60 |
|
@throws |
61 |
|
|
62 |
|
|
|
|
| 0% |
Uncovered Elements: 52 (52) |
Complexity: 13 |
Complexity Density: 0,38 |
|
63 |
0
|
@Override... |
64 |
|
protected void readConstrs(LineNumberReader in) throws IOException, |
65 |
|
ParseFormatException, ContradictionException { |
66 |
0
|
int lit; |
67 |
0
|
String line; |
68 |
0
|
StringTokenizer stk; |
69 |
|
|
70 |
0
|
int realNbOfClauses = 0; |
71 |
|
|
72 |
0
|
IVecInt literals = new VecInt(); |
73 |
|
|
74 |
0
|
while (true) { |
75 |
0
|
line = in.readLine(); |
76 |
|
|
77 |
0
|
if (line == null) { |
78 |
|
|
79 |
0
|
if (literals.size() > 0) { |
80 |
|
|
81 |
0
|
solver.addClause(literals); |
82 |
0
|
realNbOfClauses++; |
83 |
|
} |
84 |
|
|
85 |
0
|
break; |
86 |
|
} |
87 |
|
|
88 |
0
|
if (line.startsWith("c ")) { |
89 |
|
|
90 |
0
|
continue; |
91 |
|
} |
92 |
0
|
if (line.startsWith("%") && expectedNbOfConstr == realNbOfClauses) { |
93 |
0
|
System.out |
94 |
|
.println("Ignoring the rest of the file (SATLIB format"); |
95 |
0
|
break; |
96 |
|
} |
97 |
0
|
stk = new StringTokenizer(line); |
98 |
0
|
String token; |
99 |
|
|
100 |
0
|
while (stk.hasMoreTokens()) { |
101 |
|
|
102 |
0
|
token = stk.nextToken(); |
103 |
|
|
104 |
0
|
if ("<=".equals(token) || ">=".equals(token)) { |
105 |
|
|
106 |
0
|
readCardinalityConstr(token, stk, literals); |
107 |
0
|
literals.clear(); |
108 |
0
|
realNbOfClauses++; |
109 |
|
} else { |
110 |
0
|
lit = Integer.parseInt(token); |
111 |
0
|
if (lit == 0) { |
112 |
0
|
if (literals.size() > 0) { |
113 |
0
|
solver.addClause(literals); |
114 |
0
|
literals.clear(); |
115 |
0
|
realNbOfClauses++; |
116 |
|
} |
117 |
|
} else { |
118 |
0
|
literals.push(lit); |
119 |
|
} |
120 |
|
} |
121 |
|
} |
122 |
|
} |
123 |
0
|
if (expectedNbOfConstr != realNbOfClauses) { |
124 |
0
|
throw new ParseFormatException("wrong nbclauses parameter. Found " |
125 |
|
+ realNbOfClauses + ", " + expectedNbOfConstr + " expected"); |
126 |
|
} |
127 |
|
} |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0,5 |
|
129 |
0
|
private void readCardinalityConstr(String token, StringTokenizer stk,... |
130 |
|
IVecInt literals) throws ContradictionException, |
131 |
|
ParseFormatException { |
132 |
0
|
int card = Integer.parseInt(stk.nextToken()); |
133 |
0
|
int lit = Integer.parseInt(stk.nextToken()); |
134 |
0
|
if (lit == 0) { |
135 |
0
|
if ("<=".equals(token)) { |
136 |
0
|
solver.addAtMost(literals, card); |
137 |
0
|
} else if (">=".equals(token)) { |
138 |
0
|
solver.addAtLeast(literals, card); |
139 |
|
} |
140 |
|
} else |
141 |
0
|
throw new ParseFormatException(); |
142 |
|
} |
143 |
|
|
144 |
|
} |