1 /*******************************************************************************
2 * SAT4J: a SATisfiability library for Java Copyright (C) 2004, 2012 Artois University and CNRS
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 * Contributors:
28 * CRIL - initial API and implementation
29 *******************************************************************************/
30 package org.sat4j.specs;
31
32 import java.io.PrintWriter;
33
34 /**
35 * Access to the information related to a given problem instance.
36 *
37 * @author leberre
38 */
39 public interface IProblem extends RandomAccessModel {
40 /**
41 * Provide a model (if any) for a satisfiable formula. That method should be
42 * called AFTER isSatisfiable() or isSatisfiable(IVecInt) if the formula is
43 * satisfiable. Else an exception UnsupportedOperationException is launched.
44 *
45 * @return a model of the formula as an array of literals to satisfy.
46 * @see #isSatisfiable()
47 * @see #isSatisfiable(IVecInt)
48 */
49 int[] model();
50
51 /**
52 * Provide a prime implicant, i.e. a set of literal that is sufficient to
53 * satisfy all constraints of the problem.
54 *
55 *
56 * @return a prime implicant of the formula as an array of literal, Dimacs
57 * format.
58 * @since 2.3
59 */
60 int[] primeImplicant();
61
62 /**
63 * Check if a given literal is part of the prime implicant computed by the
64 * {@link #primeImplicant()} method.
65 *
66 * @param p
67 * a literal in Dimacs format
68 * @return true iff p belongs to {@link #primeImplicant()}
69 */
70 boolean primeImplicant(int p);
71
72 /**
73 * Check the satisfiability of the set of constraints contained inside the
74 * solver.
75 *
76 * @return true if the set of constraints is satisfiable, else false.
77 */
78 boolean isSatisfiable() throws TimeoutException;
79
80 /**
81 * Check the satisfiability of the set of constraints contained inside the
82 * solver.
83 *
84 * @param assumps
85 * a set of literals (represented by usual non null integers in
86 * Dimacs format).
87 * @param globalTimeout
88 * whether that call is part of a global process (i.e.
89 * optimization) or not. if (global), the timeout will not be
90 * reset between each call.
91 * @return true if the set of constraints is satisfiable when literals are
92 * satisfied, else false.
93 */
94 boolean isSatisfiable(IVecInt assumps, boolean globalTimeout)
95 throws TimeoutException;
96
97 /**
98 * Check the satisfiability of the set of constraints contained inside the
99 * solver.
100 *
101 * @param globalTimeout
102 * whether that call is part of a global process (i.e.
103 * optimization) or not. if (global), the timeout will not be
104 * reset between each call.
105 * @return true if the set of constraints is satisfiable, else false.
106 */
107 boolean isSatisfiable(boolean globalTimeout) throws TimeoutException;
108
109 /**
110 * Check the satisfiability of the set of constraints contained inside the
111 * solver.
112 *
113 * @param assumps
114 * a set of literals (represented by usual non null integers in
115 * Dimacs format).
116 * @return true if the set of constraints is satisfiable when literals are
117 * satisfied, else false.
118 */
119 boolean isSatisfiable(IVecInt assumps) throws TimeoutException;
120
121 /**
122 * Look for a model satisfying all the clauses available in the problem. It
123 * is an alternative to isSatisfiable() and model() methods, as shown in the
124 * pseudo-code: <code>
125 if (isSatisfiable()) {
126 return model();
127 }
128 return null;
129 </code>
130 *
131 * @return a model of the formula as an array of literals to satisfy, or
132 * <code>null</code> if no model is found
133 * @throws TimeoutException
134 * if a model cannot be found within the given timeout.
135 * @since 1.7
136 */
137 int[] findModel() throws TimeoutException;
138
139 /**
140 * Look for a model satisfying all the clauses available in the problem. It
141 * is an alternative to isSatisfiable(IVecInt) and model() methods, as shown
142 * in the pseudo-code: <code>
143 if (isSatisfiable(assumpt)) {
144 return model();
145 }
146 return null;
147 </code>
148 *
149 * @return a model of the formula as an array of literals to satisfy, or
150 * <code>null</code> if no model is found
151 * @throws TimeoutException
152 * if a model cannot be found within the given timeout.
153 * @since 1.7
154 */
155 int[] findModel(IVecInt assumps) throws TimeoutException;
156
157 /**
158 * To know the number of constraints currently available in the solver.
159 * (without taking into account learned constraints).
160 *
161 * @return the number of constraints added to the solver
162 */
163 int nConstraints();
164
165 /**
166 * Declare <code>howmany</code> variables in the problem (and thus in the
167 * vocabulary), that will be represented using the Dimacs format by integers
168 * ranging from 1 to howmany. That feature allows encodings to create
169 * additional variables with identifier starting at howmany+1.
170 *
171 * @param howmany
172 * number of variables to create
173 * @return the total number of variables available in the solver (the
174 * highest variable number)
175 * @see #nVars()
176 */
177 int newVar(int howmany);
178
179 /**
180 * To know the number of variables used in the solver as declared by
181 * newVar()
182 *
183 * In case the method newVar() has not been used, the method returns the
184 * number of variables used in the solver.
185 *
186 * @return the number of variables created using newVar().
187 * @see #newVar(int)
188 */
189 int nVars();
190
191 /**
192 * To print additional informations regarding the problem.
193 *
194 * @param out
195 * the place to print the information
196 * @param prefix
197 * the prefix to put in front of each line
198 *
199 */
200 @Deprecated
201 void printInfos(PrintWriter out, String prefix);
202
203 /**
204 * To print additional informations regarding the problem.
205 *
206 * @param out
207 * the place to print the information
208 * @see #setLogPrefix(String)
209 * @since 2.3.3
210 *
211 */
212 void printInfos(PrintWriter out);
213 }