Commit 05702b6c authored by Daniel Le Berre's avatar Daniel Le Berre
Browse files

Closing properly fwriter without using java7+ try on resources.

parent 15bd4355
...@@ -22,28 +22,33 @@ import org.sat4j.tools.encoding.Policy; ...@@ -22,28 +22,33 @@ import org.sat4j.tools.encoding.Policy;
*/ */
public class OpbToDimacsWriter { public class OpbToDimacsWriter {
public static void main(String args[]) throws ParseFormatException, public static void main(String args[])
IOException, ContradictionException { throws ParseFormatException, IOException, ContradictionException {
new OpbToDimacsWriter(args); new OpbToDimacsWriter(args);
} }
public OpbToDimacsWriter(String[] args) throws ParseFormatException, public OpbToDimacsWriter(String[] args)
IOException, ContradictionException { throws ParseFormatException, IOException, ContradictionException {
Set<EncodingStrategy> tabooEncodings = new HashSet<EncodingStrategy>(); Set<EncodingStrategy> tabooEncodings = new HashSet<>();
tabooEncodings.add(EncodingStrategy.NATIVE); tabooEncodings.add(EncodingStrategy.NATIVE);
for (EncodingStrategy strategy : EncodingStrategy.values()) { for (EncodingStrategy strategy : EncodingStrategy.values()) {
if (tabooEncodings.contains(strategy)) if (tabooEncodings.contains(strategy))
continue; continue;
DimacsStringSolver dss = new DimacsStringSolver(); DimacsStringSolver dss = new DimacsStringSolver();
IPBSolver solver = new ClausalConstraintsDecorator(new PBAdapter( IPBSolver solver = new ClausalConstraintsDecorator(
dss), Policy.getAdapterFromEncodingName(strategy)); new PBAdapter(dss),
OPBReader2012 reader = new OPBReader2012(new PBSolverHandle(solver)); Policy.getAdapterFromEncodingName(strategy));
OPBReader2012 reader = new OPBReader2012(
new PBSolverHandle(solver));
solver.setVerbose(false); solver.setVerbose(false);
reader.parseInstance(args[0]); reader.parseInstance(args[0]);
FileWriter fwriter = new FileWriter(args[0] + ".cardEncoding." FileWriter fwriter = new FileWriter(
+ strategy.name() + ".cnf"); args[0] + ".cardEncoding." + strategy.name() + ".cnf");
fwriter.write(dss.toString()); try {
fwriter.close(); fwriter.write(dss.toString());
} finally {
fwriter.close();
}
} }
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment