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.BufferedReader; |
28 |
|
import java.io.IOException; |
29 |
|
import java.io.LineNumberReader; |
30 |
|
import java.io.PrintWriter; |
31 |
|
import java.io.Serializable; |
32 |
|
import java.math.BigInteger; |
33 |
|
|
34 |
|
import org.sat4j.core.Vec; |
35 |
|
import org.sat4j.core.VecInt; |
36 |
|
import org.sat4j.specs.ContradictionException; |
37 |
|
import org.sat4j.specs.IConstr; |
38 |
|
import org.sat4j.specs.IProblem; |
39 |
|
import org.sat4j.specs.ISolver; |
40 |
|
import org.sat4j.specs.IVec; |
41 |
|
import org.sat4j.specs.IVecInt; |
42 |
|
import org.sat4j.minisat.constraints.pb.PBConstr; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@author |
48 |
|
@author |
49 |
|
@author |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 349 (349) |
Complexity: 65 |
Complexity Density: 0,46 |
|
51 |
|
public class OPBReader2005 extends Reader implements Serializable { |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private static final long serialVersionUID = 1L; |
57 |
|
|
58 |
|
protected final ISolver solver; |
59 |
|
|
60 |
|
private final IVecInt lits; |
61 |
|
|
62 |
|
private final IVec<BigInteger> coeffs; |
63 |
|
|
64 |
|
private BigInteger d; |
65 |
|
|
66 |
|
private String operator; |
67 |
|
|
68 |
|
private final IVecInt objectiveVars = new VecInt(); |
69 |
|
|
70 |
|
private final IVec<BigInteger> objectiveCoeffs = new Vec<BigInteger>(); |
71 |
|
|
72 |
|
|
73 |
|
private boolean hasObjFunc = false; |
74 |
|
|
75 |
|
protected int nbVars, nbConstr; |
76 |
|
|
77 |
|
protected int nbConstraintsRead; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
@param |
83 |
|
|
84 |
|
@param |
85 |
|
|
86 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
0
|
protected void metaData(int nbvar, int nbconstr) {... |
88 |
0
|
solver.newVar(nbvar); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
94 |
0
|
protected void beginObjective() {... |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0,67 |
|
100 |
0
|
protected void endObjective() {... |
101 |
0
|
assert lits.size() == coeffs.size(); |
102 |
0
|
assert lits.size() == coeffs.size(); |
103 |
0
|
for (int i = 0; i < lits.size(); i++) { |
104 |
0
|
objectiveVars.push(lits.get(i)); |
105 |
0
|
objectiveCoeffs.push(coeffs.get(i)); |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0,5 |
|
112 |
0
|
protected void beginConstraint() {... |
113 |
0
|
lits.clear(); |
114 |
0
|
coeffs.clear(); |
115 |
0
|
assert lits.size() == 0; |
116 |
0
|
assert coeffs.size() == 0; |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
@throws |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 1 |
|
125 |
0
|
protected void endConstraint() throws ContradictionException {... |
126 |
|
|
127 |
0
|
assert !(lits.size() == 0); |
128 |
0
|
assert !(coeffs.size() == 0); |
129 |
0
|
assert lits.size() == coeffs.size(); |
130 |
|
|
131 |
0
|
if ("<=".equals(operator) || "=".equals(operator)){ |
132 |
0
|
solver.addPseudoBoolean(lits, coeffs, false, d); |
133 |
|
} |
134 |
0
|
if (">=".equals(operator) || "=".equals(operator)){ |
135 |
0
|
solver.addPseudoBoolean(lits, coeffs, true, d); |
136 |
|
} |
137 |
0
|
nbConstraintsRead++; |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
@param |
144 |
|
|
145 |
|
@param |
146 |
|
|
147 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
148 |
0
|
private void constraintTerm(BigInteger coeff, String var) {... |
149 |
0
|
coeffs.push(coeff); |
150 |
0
|
lits.push(translateVarToId(var)); |
151 |
|
} |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,5 |
|
153 |
0
|
protected int translateVarToId(String var) { ... |
154 |
0
|
int id = Integer.parseInt(var.substring(1)); |
155 |
0
|
return ((savedChar == '-') ? -1 : 1) * id; |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
@param |
162 |
|
|
163 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
164 |
0
|
protected void constraintRelOp(String relop) {... |
165 |
0
|
operator = relop; |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
|
174 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
0
|
protected void constraintRightTerm(BigInteger val) {... |
176 |
0
|
d = val; |
177 |
|
} |
178 |
|
|
179 |
|
transient BufferedReader in; |
180 |
|
|
181 |
|
char savedChar; |
182 |
|
|
183 |
|
boolean charAvailable = false; |
184 |
|
|
185 |
|
boolean eofReached = false; |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
@throws |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0,38 |
|
192 |
0
|
protected char get() throws IOException {... |
193 |
0
|
int c; |
194 |
|
|
195 |
0
|
if (charAvailable) { |
196 |
0
|
charAvailable = false; |
197 |
0
|
return savedChar; |
198 |
|
} |
199 |
|
|
200 |
0
|
c = in.read(); |
201 |
0
|
if (c == -1) |
202 |
0
|
eofReached = true; |
203 |
|
|
204 |
0
|
return (char) c; |
205 |
|
} |
206 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
207 |
0
|
public IVecInt getVars() {... |
208 |
0
|
return objectiveVars; |
209 |
|
} |
210 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
211 |
0
|
public IVec<BigInteger> getCoeffs() {... |
212 |
0
|
return objectiveCoeffs; |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
218 |
0
|
private void putback(char c) {... |
219 |
0
|
savedChar = c; |
220 |
0
|
charAvailable = true; |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
0
|
protected boolean eof() {... |
227 |
0
|
return eofReached; |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
@throws |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
235 |
0
|
protected void skipSpaces() throws IOException {... |
236 |
0
|
char c; |
237 |
|
|
238 |
0
|
while (Character.isWhitespace(c = get())) |
239 |
0
|
; |
240 |
|
|
241 |
0
|
putback(c); |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
@return |
248 |
|
@throws |
249 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0,5 |
|
250 |
0
|
public String readWord() throws IOException {... |
251 |
0
|
StringBuffer s = new StringBuffer(); |
252 |
0
|
char c; |
253 |
|
|
254 |
0
|
skipSpaces(); |
255 |
|
|
256 |
0
|
while (!Character.isWhitespace(c = get()) && !eof()) |
257 |
0
|
s.append(c); |
258 |
|
|
259 |
0
|
return s.toString(); |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
@param |
266 |
|
|
267 |
|
@throws |
268 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 5 |
Complexity Density: 0,56 |
|
269 |
0
|
public void readInteger(StringBuffer s) throws IOException {... |
270 |
0
|
char c; |
271 |
|
|
272 |
0
|
skipSpaces(); |
273 |
0
|
s.setLength(0); |
274 |
|
|
275 |
0
|
c = get(); |
276 |
0
|
if (c == '-' || Character.isDigit(c)) |
277 |
0
|
s.append(c); |
278 |
|
|
279 |
|
|
280 |
0
|
while (Character.isDigit(c = get()) && !eof()) |
281 |
0
|
s.append(c); |
282 |
|
|
283 |
0
|
putback(c); |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
@return |
290 |
|
@throws |
291 |
|
@throws |
292 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 6 |
Complexity Density: 0,3 |
|
293 |
0
|
protected boolean readIdentifier(StringBuffer s) throws IOException,... |
294 |
|
ParseFormatException { |
295 |
0
|
char c; |
296 |
|
|
297 |
0
|
s.setLength(0); |
298 |
|
|
299 |
0
|
skipSpaces(); |
300 |
|
|
301 |
|
|
302 |
0
|
c = get(); |
303 |
0
|
if (eof()) |
304 |
0
|
return false; |
305 |
|
|
306 |
0
|
if (!isGoodFirstCharacter(c)) { |
307 |
0
|
putback(c); |
308 |
0
|
return false; |
309 |
|
} |
310 |
|
|
311 |
0
|
s.append(c); |
312 |
|
|
313 |
|
|
314 |
0
|
while (true) { |
315 |
0
|
c = get(); |
316 |
0
|
if (eof()) |
317 |
0
|
break; |
318 |
|
|
319 |
0
|
if (isGoodFollowingCharacter(c)) |
320 |
0
|
s.append(c); |
321 |
|
else { |
322 |
0
|
putback(c); |
323 |
0
|
break; |
324 |
|
} |
325 |
|
} |
326 |
0
|
checkId(s); |
327 |
0
|
return true; |
328 |
|
} |
329 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
330 |
0
|
protected boolean isGoodFirstCharacter(char c){... |
331 |
0
|
return Character.isLetter(c) || c == '_'; |
332 |
|
} |
333 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
334 |
0
|
protected boolean isGoodFollowingCharacter(char c){... |
335 |
0
|
return Character.isLetter(c) || Character.isDigit(c) || c == '_'; |
336 |
|
} |
337 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
338 |
0
|
protected void checkId(StringBuffer s) throws ParseFormatException{... |
339 |
|
|
340 |
0
|
int varID = Integer.parseInt(s.substring(1)); |
341 |
0
|
if (varID > nbVars) { |
342 |
0
|
throw new ParseFormatException( |
343 |
|
"Variable identifier larger than #variables in metadata."); |
344 |
|
} |
345 |
|
} |
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
@return |
350 |
|
@throws |
351 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0,5 |
|
352 |
0
|
private String readRelOp() throws IOException {... |
353 |
0
|
char c; |
354 |
|
|
355 |
0
|
skipSpaces(); |
356 |
|
|
357 |
0
|
c = get(); |
358 |
0
|
if (eof()) |
359 |
0
|
return null; |
360 |
|
|
361 |
0
|
if (c == '=') |
362 |
0
|
return "="; |
363 |
|
|
364 |
0
|
if (c == '>' && get() == '=') |
365 |
0
|
return ">="; |
366 |
|
|
367 |
0
|
return null; |
368 |
|
} |
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
@throws |
375 |
|
@throws |
376 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 6 |
Complexity Density: 0,4 |
|
377 |
0
|
protected void readMetaData() throws IOException, ParseFormatException {... |
378 |
0
|
char c; |
379 |
0
|
String s; |
380 |
|
|
381 |
|
|
382 |
0
|
c = get(); |
383 |
0
|
if (c != '*') |
384 |
0
|
throw new ParseFormatException( |
385 |
|
"First line of input file should be a comment"); |
386 |
|
|
387 |
0
|
s = readWord(); |
388 |
0
|
if (eof() || !"#variable=".equals(s)) |
389 |
0
|
throw new ParseFormatException( |
390 |
|
"First line should contain #variable= as first keyword"); |
391 |
|
|
392 |
0
|
nbVars = Integer.parseInt(readWord()); |
393 |
|
|
394 |
0
|
s = readWord(); |
395 |
0
|
if (eof() || !"#constraint=".equals(s)) |
396 |
0
|
throw new ParseFormatException( |
397 |
|
"First line should contain #constraint= as second keyword"); |
398 |
|
|
399 |
0
|
nbConstr = Integer.parseInt(readWord()); |
400 |
|
|
401 |
|
|
402 |
0
|
in.readLine(); |
403 |
|
|
404 |
|
|
405 |
0
|
metaData(nbVars, nbConstr); |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
@throws |
412 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
413 |
0
|
private void skipComments() throws IOException {... |
414 |
0
|
char c = ' '; |
415 |
|
|
416 |
|
|
417 |
|
|
418 |
0
|
while (!eof() && (c = get()) == '*') { |
419 |
0
|
in.readLine(); |
420 |
|
} |
421 |
|
|
422 |
0
|
putback(c); |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
@param |
429 |
|
|
430 |
|
@param |
431 |
|
|
432 |
|
@throws |
433 |
|
@throws |
434 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0,38 |
|
435 |
0
|
protected void readTerm(StringBuffer coeff, StringBuffer var)... |
436 |
|
throws IOException, ParseFormatException, ContradictionException { |
437 |
0
|
char c; |
438 |
|
|
439 |
0
|
readInteger(coeff); |
440 |
|
|
441 |
0
|
skipSpaces(); |
442 |
0
|
c = get(); |
443 |
0
|
if (c != '*') |
444 |
0
|
throw new ParseFormatException( |
445 |
|
"'*' expected between a coefficient and a variable"); |
446 |
|
|
447 |
0
|
if (!readIdentifier(var)) |
448 |
0
|
throw new ParseFormatException("identifier expected"); |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
|
|
453 |
|
|
454 |
|
|
455 |
|
@throws |
456 |
|
@throws |
457 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 11 |
Complexity Density: 0,44 |
|
458 |
0
|
private void readObjective() throws IOException, ParseFormatException {... |
459 |
0
|
char c; |
460 |
0
|
StringBuffer var = new StringBuffer(); |
461 |
0
|
StringBuffer coeff = new StringBuffer(); |
462 |
|
|
463 |
|
|
464 |
|
|
465 |
0
|
skipSpaces(); |
466 |
0
|
c = get(); |
467 |
0
|
if (c != 'm') { |
468 |
|
|
469 |
0
|
putback(c); |
470 |
0
|
return; |
471 |
|
} |
472 |
|
|
473 |
0
|
hasObjFunc = true; |
474 |
0
|
if (get() == 'i' && get() == 'n' && get() == ':') { |
475 |
0
|
beginObjective(); |
476 |
|
|
477 |
0
|
while (!eof()) { |
478 |
0
|
try { |
479 |
0
|
readTerm(coeff, var); |
480 |
|
} catch (ContradictionException e) { |
481 |
|
|
482 |
0
|
e.printStackTrace(); |
483 |
|
} |
484 |
0
|
constraintTerm(new BigInteger(coeff.toString()), var.toString()); |
485 |
|
|
486 |
0
|
skipSpaces(); |
487 |
0
|
c = get(); |
488 |
0
|
if (c == ';') |
489 |
0
|
break; |
490 |
|
|
491 |
0
|
else if (c == '-' || c == '+' || Character.isDigit(c)) |
492 |
0
|
putback(c); |
493 |
|
else |
494 |
0
|
throw new ParseFormatException( |
495 |
|
"unexpected character in objective function"); |
496 |
|
} |
497 |
|
|
498 |
0
|
endObjective(); |
499 |
|
} else |
500 |
0
|
throw new ParseFormatException( |
501 |
|
"input format error: 'min:' expected"); |
502 |
|
} |
503 |
|
|
504 |
|
|
505 |
|
|
506 |
|
|
507 |
|
@throws |
508 |
|
@throws |
509 |
|
@throws |
510 |
|
|
|
|
| 0% |
Uncovered Elements: 40 (40) |
Complexity: 11 |
Complexity Density: 0,39 |
|
511 |
0
|
private void readConstraint() throws IOException, ParseFormatException,... |
512 |
|
ContradictionException { |
513 |
0
|
StringBuffer var = new StringBuffer(); |
514 |
0
|
StringBuffer coeff = new StringBuffer(); |
515 |
0
|
char c; |
516 |
|
|
517 |
0
|
beginConstraint(); |
518 |
|
|
519 |
0
|
while (!eof()) { |
520 |
0
|
readTerm(coeff, var); |
521 |
0
|
constraintTerm(new BigInteger(coeff.toString()), var.toString()); |
522 |
|
|
523 |
0
|
skipSpaces(); |
524 |
0
|
c = get(); |
525 |
0
|
if (c == '>' || c == '=') { |
526 |
|
|
527 |
0
|
putback(c); |
528 |
0
|
break; |
529 |
0
|
} else if (c == '-' || c == '+' || Character.isDigit(c)) |
530 |
0
|
putback(c); |
531 |
|
else { |
532 |
0
|
throw new ParseFormatException( |
533 |
|
"unexpected character in constraint"); |
534 |
|
} |
535 |
|
} |
536 |
|
|
537 |
0
|
if (eof()) |
538 |
0
|
throw new ParseFormatException( |
539 |
|
"unexpected EOF before end of constraint"); |
540 |
|
|
541 |
0
|
String relop; |
542 |
0
|
if ((relop = readRelOp()) == null) { |
543 |
0
|
throw new ParseFormatException( |
544 |
|
"unexpected relational operator in constraint"); |
545 |
|
|
546 |
|
} |
547 |
0
|
constraintRelOp(relop); |
548 |
0
|
readInteger(coeff); |
549 |
0
|
constraintRightTerm(new BigInteger(coeff.toString())); |
550 |
|
|
551 |
0
|
skipSpaces(); |
552 |
0
|
c = get(); |
553 |
0
|
if (eof() || c != ';') |
554 |
0
|
throw new ParseFormatException( |
555 |
|
"semicolon expected at end of constraint"); |
556 |
|
|
557 |
0
|
endConstraint(); |
558 |
|
} |
559 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
560 |
0
|
public OPBReader2005(ISolver solver) {... |
561 |
0
|
this.solver = solver; |
562 |
0
|
lits = new VecInt(); |
563 |
0
|
coeffs = new Vec<BigInteger>(); |
564 |
|
} |
565 |
|
|
566 |
|
|
567 |
|
|
568 |
|
|
569 |
|
|
570 |
|
@throws |
571 |
|
@throws |
572 |
|
@throws |
573 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 6 |
Complexity Density: 0,33 |
|
574 |
0
|
public void parse() throws IOException, ParseFormatException,... |
575 |
|
ContradictionException { |
576 |
0
|
readMetaData(); |
577 |
|
|
578 |
0
|
skipComments(); |
579 |
|
|
580 |
0
|
readObjective(); |
581 |
|
|
582 |
|
|
583 |
0
|
nbConstraintsRead = 0; |
584 |
0
|
char c; |
585 |
0
|
while (!eof()) { |
586 |
0
|
skipSpaces(); |
587 |
0
|
if (eof()) |
588 |
0
|
break; |
589 |
|
|
590 |
0
|
c = get(); |
591 |
0
|
putback(c); |
592 |
0
|
if (c == '*') |
593 |
0
|
skipComments(); |
594 |
|
|
595 |
0
|
if (eof()) |
596 |
0
|
break; |
597 |
|
|
598 |
0
|
readConstraint(); |
599 |
|
|
600 |
|
} |
601 |
|
|
602 |
0
|
if (nbConstraintsRead != nbConstr) { |
603 |
0
|
throw new ParseFormatException( |
604 |
|
"Number of constraints read is different from metadata."); |
605 |
|
} |
606 |
|
} |
607 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
608 |
0
|
@Override... |
609 |
|
public final IProblem parseInstance(final java.io.Reader in) |
610 |
|
throws ParseFormatException, ContradictionException { |
611 |
0
|
return parseInstance(new LineNumberReader(in)); |
612 |
|
} |
613 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,33 |
|
614 |
0
|
private IProblem parseInstance(LineNumberReader in)... |
615 |
|
throws ParseFormatException, ContradictionException { |
616 |
0
|
solver.reset(); |
617 |
0
|
this.in = in; |
618 |
0
|
try { |
619 |
0
|
parse(); |
620 |
0
|
return solver; |
621 |
|
} catch (IOException e) { |
622 |
0
|
throw new ParseFormatException(e); |
623 |
|
} |
624 |
|
} |
625 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
626 |
0
|
@Override... |
627 |
|
public String decode(int[] model) { |
628 |
0
|
StringBuffer stb = new StringBuffer(); |
629 |
|
|
630 |
0
|
for (int i = 0; i < model.length; i++) { |
631 |
0
|
if (model[i] < 0) { |
632 |
0
|
stb.append("-x"); |
633 |
0
|
stb.append(-model[i]); |
634 |
|
} else { |
635 |
0
|
stb.append("x"); |
636 |
0
|
stb.append(model[i]); |
637 |
|
} |
638 |
0
|
stb.append(" "); |
639 |
|
} |
640 |
0
|
return stb.toString(); |
641 |
|
} |
642 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0,43 |
|
643 |
0
|
@Override... |
644 |
|
public void decode(int[] model, PrintWriter out) { |
645 |
0
|
for (int i = 0; i < model.length; i++) { |
646 |
0
|
if (model[i] < 0) { |
647 |
0
|
out.print("-x"); |
648 |
0
|
out.print(-model[i]); |
649 |
|
} else { |
650 |
0
|
out.print("x"); |
651 |
0
|
out.print(model[i]); |
652 |
|
} |
653 |
0
|
out.print(" "); |
654 |
|
} |
655 |
|
} |
656 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
657 |
0
|
public ObjectiveFunction getObjectiveFunction() {... |
658 |
0
|
if (hasObjFunc){ |
659 |
0
|
return new ObjectiveFunction(getVars(), getCoeffs()); |
660 |
|
} |
661 |
0
|
return null; |
662 |
|
} |
663 |
|
|
664 |
|
} |