Clover Coverage Report
Coverage timestamp: mer. juin 27 2007 07:27:16 CEST
71   219   28   4,73
46   150   0,59   15
15     2,8  
1    
 
  InstanceReader       Line # 44 71 28 36,4% 0.36363637
 
  (172)
 
1    /*
2    * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2006 Daniel Le Berre
3    *
4    * Based on the original minisat specification from:
5    *
6    * An extensible SAT solver. Niklas E?n and Niklas S?rensson. Proceedings of the
7    * Sixth International Conference on Theory and Applications of Satisfiability
8    * Testing, LNCS 2919, pp 502-518, 2003.
9    *
10    * This library is free software; you can redistribute it and/or modify it under
11    * the terms of the GNU Lesser General Public License as published by the Free
12    * Software Foundation; either version 2.1 of the License, or (at your option)
13    * any later version.
14    *
15    * This library is distributed in the hope that it will be useful, but WITHOUT
16    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17    * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18    * details.
19    *
20    * You should have received a copy of the GNU Lesser General Public License
21    * along with this library; if not, write to the Free Software Foundation, Inc.,
22    * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23    *
24    */
25   
26    package org.sat4j.reader;
27   
28    import java.io.FileNotFoundException;
29    import java.io.IOException;
30    import java.io.PrintWriter;
31    import java.net.URL;
32    import java.util.Locale;
33   
34    import org.sat4j.specs.ContradictionException;
35    import org.sat4j.specs.IProblem;
36    import org.sat4j.specs.ISolver;
37   
38    /**
39    * An reader having the responsability to choose the right reader according to
40    * the input.
41    *
42    * @author leberre
43    */
 
44    public class InstanceReader extends Reader {
45   
46    private AAGReader aag;
47   
48    private AIGReader aig;
49   
50    private DimacsReader ezdimacs;
51   
52    private LecteurDimacs dimacs;
53   
54    private GoodOPBReader opb;
55   
56    private ExtendedDimacsReader edimacs;
57   
58    private CSPReader csp;
59   
60    private CSPReader csp2;
61   
62    private CSPReader csp3;
63   
64    private XMLCSPReader xmlcsp;
65   
66    private Reader reader = null;
67   
68    private final ISolver solver;
69   
 
70  2509 toggle public InstanceReader(ISolver solver) {
71    // dimacs = new DimacsReader(solver);
72  2509 this.solver = solver;
73    }
74   
 
75  1673 toggle private Reader getDefaultSATReader() {
76  1673 if (dimacs == null) {
77  1673 dimacs = new LecteurDimacs(solver);// new LecteurDimacs(solver);
78    }
79  1673 return dimacs;
80    }
81   
 
82  0 toggle private Reader getEZSATReader() {
83  0 if (ezdimacs == null) {
84  0 ezdimacs = new DimacsReader(solver);// new LecteurDimacs(solver);
85    }
86  0 return ezdimacs;
87    }
88   
 
89  828 toggle private Reader getDefaultOPBReader() {
90  828 if (opb == null) {
91  828 opb = new GoodOPBReader(solver);
92    }
93  828 return opb;
94    }
95   
 
96  0 toggle private Reader getDefaultExtendedDimacsReader() {
97  0 if (edimacs == null) {
98  0 edimacs = new ExtendedDimacsReader(solver);
99    }
100  0 return edimacs;
101    }
102   
 
103  0 toggle private Reader getCSPReader1() {
104  0 if (csp == null) {
105  0 csp = new CSPReader(solver);
106    }
107  0 return csp;
108    }
109   
 
110  0 toggle private Reader getCSPReader2() {
111  0 if (csp2 == null) {
112  0 csp2 = new CSPSupportReader(solver);
113    }
114  0 return csp2;
115    }
116   
 
117  0 toggle private Reader getCSPReader3() {
118  0 if (csp3 == null) {
119  0 csp3 = new CSPExtSupportReader(solver);
120    }
121  0 return csp3;
122    }
123   
 
124  0 toggle private Reader getXMLCSPReader() {
125  0 if (xmlcsp == null) {
126  0 xmlcsp = new XMLCSPReader(solver);
127    }
128  0 return xmlcsp;
129    }
130   
 
131  0 toggle private Reader getAIGReader() {
132  0 if (aig == null) {
133  0 aig = new AIGReader(solver);
134    }
135  0 return aig;
136    }
137   
 
138  0 toggle private Reader getAAGReader() {
139  0 if (aag == null) {
140  0 aag = new AAGReader(solver);
141    }
142  0 return aag;
143    }
144   
 
145  2501 toggle @Override
146    public IProblem parseInstance(String filename)
147    throws FileNotFoundException, ParseFormatException, IOException,
148    ContradictionException {
149  2501 String fname;
150  2501 boolean isHttp = false;
151  2501 String tempFileName = "";
152  2501 String prefix = "";
153   
154  2501 if (filename.startsWith("http://")) {
155  0 isHttp = true;
156  0 tempFileName = filename;
157  0 filename = filename.substring(filename.lastIndexOf('/'), filename
158    .length() - 1);
159    }
160   
161  2501 if (filename.indexOf(':') != -1) {
162   
163  0 String[] parts = filename.split(":");
164  0 filename = parts[1];
165  0 prefix = parts[0].toUpperCase(Locale.getDefault());
166   
167    }
168   
169  2501 if (filename.endsWith(".gz")) {
170  0 fname = filename.substring(0, filename.lastIndexOf('.'));
171    } else {
172  2501 fname = filename;
173    }
174  2501 if ("EZCNF".equals(prefix)) {
175  0 reader = getEZSATReader();
176  2501 } else if ("CSP".equals(prefix)) {
177  0 reader = getCSPReader1();
178  2501 } else if ("CSP3".equals(prefix)) {
179  0 reader = getCSPReader3();
180  2501 } else if (fname.endsWith(".txt") || "CSP2".equals(prefix)) {
181  0 reader = getCSPReader2();
182  2501 } else if (fname.endsWith(".opb") || "PB".equals(prefix)) {
183  828 reader = getDefaultOPBReader();
184  1673 } else if (fname.endsWith(".edimacs") || fname.endsWith(".ncnf")
185    || "EDIMACS".equals(prefix)) {
186  0 reader = getDefaultExtendedDimacsReader();
187  1673 } else if (fname.endsWith(".xml")) {
188  0 reader = getXMLCSPReader();
189  1673 } else if (fname.endsWith(".aag")) {
190  0 reader = getAAGReader();
191  1673 } else if (fname.endsWith(".aig")) {
192  0 reader = getAIGReader();
193   
194    } else {
195  1673 reader = getDefaultSATReader();
196    }
197   
198  2501 if (isHttp) {
199  0 return reader.parseInstance((new URL(tempFileName)).openStream());
200    }
201  2501 return reader.parseInstance(filename);
202    }
203   
 
204  0 toggle @Override
205    public String decode(int[] model) {
206  0 return reader.decode(model);
207    }
208   
 
209  0 toggle @Override
210    public void decode(int[] model, PrintWriter out) {
211  0 reader.decode(model, out);
212    }
213   
 
214  0 toggle @Override
215    public IProblem parseInstance(java.io.Reader in)
216    throws ParseFormatException, ContradictionException, IOException {
217  0 throw new UnsupportedOperationException();
218    }
219    }