| 1 |  |  | 
| 2 |  |  | 
| 3 |  |  | 
| 4 |  |  | 
| 5 |  |  | 
| 6 |  |  | 
| 7 |  | package org.sat4j.reader; | 
| 8 |  |  | 
| 9 |  | import java.io.FileNotFoundException; | 
| 10 |  | import java.io.IOException; | 
| 11 |  |  | 
| 12 |  | import org.sat4j.specs.ContradictionException; | 
| 13 |  | import org.sat4j.specs.IProblem; | 
| 14 |  | import org.sat4j.specs.ISolver; | 
| 15 |  |  | 
| 16 |  |  | 
| 17 |  |  | 
| 18 |  |  | 
| 19 |  |  | 
| 20 |  |  | 
| 21 |  |  | 
| 22 |  | public class InstanceReader implements Reader { | 
| 23 |  |  | 
| 24 |  |  | 
| 25 |  | private final LecteurDimacs dimacs; | 
| 26 |  |  | 
| 27 |  | private final GoodOPBReader opb; | 
| 28 |  |  | 
| 29 |  | private final ExtendedDimacsReader edimacs; | 
| 30 |  |  | 
| 31 |  | private final CSPReader csp; | 
| 32 |  |  | 
| 33 |  | private final CSPReader csp2; | 
| 34 |  |  | 
| 35 |  | private Reader reader = null; | 
| 36 |  |  | 
| 37 | 2026 | public InstanceReader(ISolver solver) { | 
| 38 |  |  | 
| 39 | 2026 | dimacs = new LecteurDimacs(solver); | 
| 40 | 2026 | opb = new GoodOPBReader(solver); | 
| 41 | 2026 | edimacs = new ExtendedDimacsReader(solver); | 
| 42 | 2026 | csp = new CSPReader(solver); | 
| 43 | 2026 | csp2 = new CSPSupportReader(solver); | 
| 44 |  | } | 
| 45 |  |  | 
| 46 | 2018 | public IProblem parseInstance(String filename) | 
| 47 |  | throws FileNotFoundException, ParseFormatException, IOException, | 
| 48 |  | ContradictionException { | 
| 49 | 2018 | String fname; | 
| 50 | 2018 | String prefix = ""; | 
| 51 | 2018 | if (filename.indexOf(':') != -1) { | 
| 52 | 0 | String[] parts = filename.split(":"); | 
| 53 | 0 | filename = parts[1]; | 
| 54 | 0 | prefix = parts[0].toUpperCase(); | 
| 55 |  | } | 
| 56 | 2018 | if (filename.endsWith(".gz")) { | 
| 57 | 0 | fname = filename.substring(0, filename.lastIndexOf('.')); | 
| 58 |  | } else { | 
| 59 | 2018 | fname = filename; | 
| 60 |  | } | 
| 61 | 2018 | if (prefix.equals("CSP")) { | 
| 62 | 0 | reader = csp; | 
| 63 | 2018 | } else if (fname.endsWith(".txt") || prefix.equals("CSP2")) { | 
| 64 | 0 | reader = csp2; | 
| 65 | 2018 | } else if (fname.endsWith(".opb") || prefix.equals("PB")) { | 
| 66 | 372 | reader = opb; | 
| 67 | 1646 | } else if (fname.endsWith(".edimacs") || fname.endsWith(".ncnf") | 
| 68 |  | || prefix.equals("EDIMACS")) { | 
| 69 | 0 | reader = edimacs; | 
| 70 |  | } else { | 
| 71 | 1646 | reader = dimacs; | 
| 72 |  | } | 
| 73 | 2018 | return reader.parseInstance(filename); | 
| 74 |  | } | 
| 75 |  |  | 
| 76 | 0 | public String decode(int[] model) { | 
| 77 | 0 | return reader.decode(model); | 
| 78 |  | } | 
| 79 |  | } |