1 /*******************************************************************************
2 * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2008 Daniel Le Berre
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Alternatively, the contents of this file may be used under the terms of
10 * either the GNU Lesser General Public License Version 2.1 or later (the
11 * "LGPL"), in which case the provisions of the LGPL are applicable instead
12 * of those above. If you wish to allow use of your version of this file only
13 * under the terms of the LGPL, and not to allow others to use your version of
14 * this file under the terms of the EPL, indicate your decision by deleting
15 * the provisions above and replace them with the notice and other provisions
16 * required by the LGPL. If you do not delete the provisions above, a recipient
17 * may use your version of this file under the terms of the EPL or the LGPL.
18 *
19 * Based on the original MiniSat specification from:
20 *
21 * An extensible SAT solver. Niklas Een and Niklas Sorensson. Proceedings of the
22 * Sixth International Conference on Theory and Applications of Satisfiability
23 * Testing, LNCS 2919, pp 502-518, 2003.
24 *
25 * See www.minisat.se for the original solver in C++.
26 *
27 *******************************************************************************/
28 package org.sat4j;
29
30 import org.sat4j.core.ASolverFactory;
31 import org.sat4j.minisat.SolverFactory;
32 import org.sat4j.reader.InstanceReader;
33 import org.sat4j.reader.Reader;
34 import org.sat4j.specs.ISolver;
35
36 /**
37 * Very simple launcher, to be used during the SAT competition or the SAT race
38 * for instance.
39 *
40 * @author daniel
41 *
42 */
43 public class BasicLauncher<T extends ISolver> extends AbstractLauncher {
44
45 /**
46 *
47 */
48 private static final long serialVersionUID = 1L;
49
50 private final ASolverFactory<T> factory;
51
52 public BasicLauncher(ASolverFactory<T> factory) {
53 this.factory = factory;
54 }
55
56 /**
57 * Lance le prouveur sur un fichier Dimacs.
58 *
59 * @param args
60 * doit contenir le nom d'un fichier Dimacs, eventuellement
61 * compress?.
62 */
63 public static void main(final String[] args) {
64 BasicLauncher<ISolver> lanceur = new BasicLauncher<ISolver>(
65 SolverFactory.instance());
66 if (args.length != 1) {
67 lanceur.usage();
68 return;
69 }
70 lanceur.run(args);
71 System.exit(lanceur.getExitCode().value());
72 }
73
74 @Override
75 protected ISolver configureSolver(String[] args) {
76 ISolver asolver = factory.defaultSolver();
77 asolver.setTimeout(Integer.MAX_VALUE);
78 asolver.setDBSimplificationAllowed(true);
79 getLogWriter().println(asolver.toString(COMMENT_PREFIX)); //$NON-NLS-1$
80 return asolver;
81 }
82
83 @Override
84 protected Reader createReader(ISolver theSolver, String problemname) {
85 return new InstanceReader(theSolver);
86 }
87
88 @Override
89 public void usage() {
90 log("java -jar org.sat4j.core.jar <cnffile>");
91 }
92
93 @Override
94 protected String getInstanceName(String[] args) {
95 if (args.length == 0) {
96 return null;
97 }
98 return args[0];
99 }
100 }