View Javadoc

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 compress?.
61  	 */
62  	public static void main(final String[] args) {
63  		BasicLauncher<ISolver> lanceur = new BasicLauncher<ISolver>(
64  				SolverFactory.instance());
65  		if (args.length!=1) {
66  			lanceur.usage();
67  			return;
68  		}
69  		lanceur.run(args);
70  		System.exit(lanceur.getExitCode().value());
71  	}
72  
73  	@Override
74  	protected ISolver configureSolver(String[] args) {
75  		ISolver asolver = factory.defaultSolver();
76  		asolver.setTimeout(Integer.MAX_VALUE);
77  		asolver.setDBSimplificationAllowed(true);
78  		log(asolver.toString(COMMENT_PREFIX)); //$NON-NLS-1$
79  		return asolver;
80  	}
81  
82  	@Override
83  	protected Reader createReader(ISolver theSolver, String problemname) {
84  		return new InstanceReader(theSolver);
85  	}
86  
87  	@Override
88  	public void usage() {
89  		log("java -jar org.sat4j.core.jar <cnffile>");
90  	}
91  
92  	@Override
93  	protected String getInstanceName(String[] args) {
94  		assert args.length == 1;
95  		return args[0];
96  	}
97  }