|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ASolverFactory | Line # 39 | 14 | 5 | 90% |
0.9
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 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.core; | |
| 27 | ||
| 28 | import java.lang.reflect.Method; | |
| 29 | import java.util.ArrayList; | |
| 30 | import java.util.List; | |
| 31 | ||
| 32 | import org.sat4j.specs.ISolver; | |
| 33 | ||
| 34 | /** | |
| 35 | * A solver factory is responsible to provide prebuilt solvers to the end user. | |
| 36 | * | |
| 37 | * @author bourgeois | |
| 38 | */ | |
| 39 | public abstract class ASolverFactory { | |
| 40 | ||
| 41 | /** | |
| 42 | * This methods returns names of solvers to be used with the method | |
| 43 | * getSolverByName(). | |
| 44 | * | |
| 45 | * @return an array containing the names of all the solvers available in the | |
| 46 | * library. | |
| 47 | * @see #createSolverByName(String) | |
| 48 | */ | |
| 49 | 1 |
public String[] solverNames() { |
| 50 | 1 | List<String> l = new ArrayList<String>(); |
| 51 | 1 | Method[] solvers = this.getClass().getDeclaredMethods(); |
| 52 | 70 | for (int i = 0; i < solvers.length; i++) { |
| 53 | 69 | if (solvers[i].getParameterTypes().length == 0 |
| 54 | && solvers[i].getName().startsWith("new")) { //$NON-NLS-1$ | |
| 55 | 57 | l.add(solvers[i].getName().substring(3)); |
| 56 | } | |
| 57 | } | |
| 58 | 1 | String[] names = new String[l.size()]; |
| 59 | 1 | l.toArray(names); |
| 60 | 1 | return names; |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * create a solver from its String name. the solvername Xxxx must map one of | |
| 65 | * the newXxxx methods. | |
| 66 | * | |
| 67 | * @param solvername | |
| 68 | * the name of the solver | |
| 69 | * @return an ISolver built using newSolvername. <code>null</code> if the | |
| 70 | * solvername doesn't map one of the method of the factory. | |
| 71 | */ | |
| 72 | 57 |
public ISolver createSolverByName(String solvername) { |
| 73 | 57 | Class[] paramtypes = {}; |
| 74 | 57 | try { |
| 75 | 57 | Method m = this.getClass() |
| 76 | .getMethod("new" + solvername, paramtypes); //$NON-NLS-1$ | |
| 77 | 57 | return (ISolver) m.invoke(null, (Object[]) null); |
| 78 | } catch (Exception e) { | |
| 79 | 0 | e.printStackTrace(); |
| 80 | } | |
| 81 | 0 | return null; |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * To obtain the default solver of the library. The solver is suitable to | |
| 86 | * solve huge SAT benchmarks. It should reflect state-of-the-art SAT | |
| 87 | * technologies. | |
| 88 | * | |
| 89 | * For solving small/easy SAT benchmarks, use lightSolver() instead. | |
| 90 | * | |
| 91 | * @return a solver from the factory | |
| 92 | * @see #lightSolver() | |
| 93 | */ | |
| 94 | public abstract ISolver defaultSolver(); | |
| 95 | ||
| 96 | /** | |
| 97 | * To obtain a solver that is suitable for solving many small instances of | |
| 98 | * SAT problems. | |
| 99 | * | |
| 100 | * The solver is not using sophisticated but costly reasoning and avoids to | |
| 101 | * allocate too much memory. | |
| 102 | * | |
| 103 | * For solving bigger SAT benchmarks, use defaultSolver() instead. | |
| 104 | * | |
| 105 | * @return a solver from the factory | |
| 106 | * @see #defaultSolver() | |
| 107 | */ | |
| 108 | public abstract ISolver lightSolver(); | |
| 109 | } | |
|
||||||||||