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.minisat.core;
29
30 import org.sat4j.specs.IVec;
31
32 /**
33 * That interface manages the solver's internal vocabulary. Everything related
34 * to variables and literals is available from here.
35 *
36 * For sake of efficiency, literals and variables are not object in SAT4J. They
37 * are represented by numbers. If the vocabulary contains n variables, then
38 * variables should be accessed by numbers from 1 to n and literals by numbers
39 * from 2 to 2*n+1.
40 *
41 * For a Dimacs variable v, the variable index in SAT4J is v, it's positive
42 * literal is 2*v (v << 1) and it's negative literal is 2*v+1 ((v<<1)^1). Note
43 * that one can easily access to the complementary literal of p by using bitwise
44 * operation ^.
45 *
46 * In SAT4J, literals are usualy denoted by p or q and variables by v or x.
47 *
48 * @author leberre
49 */
50 public interface ILits {
51
52 public static int UNDEFINED = -1;
53
54 public abstract void init(int nvar);
55
56 /**
57 * Translates a Dimacs literal into an internal representation literal.
58 *
59 * @param x
60 * the Dimacs literal (a non null integer).
61 * @return the literal in the internal representation.
62 */
63 public abstract int getFromPool(int x);
64
65 /**
66 * Returns true iff the variable is used in the set of constraints.
67 *
68 * @param x
69 * @return true iff the variable belongs to the formula.
70 */
71 boolean belongsToPool(int x);
72
73 public abstract void resetPool();
74
75 public abstract void ensurePool(int howmany);
76
77 public abstract void unassign(int lit);
78
79 public abstract void satisfies(int lit);
80
81 public abstract boolean isSatisfied(int lit);
82
83 public abstract boolean isFalsified(int lit);
84
85 public abstract boolean isUnassigned(int lit);
86
87 /**
88 * @param lit
89 * @return true iff the truth value of that literal is due to a unit
90 * propagation or a decision.
91 */
92 public abstract boolean isImplied(int lit);
93
94 /**
95 * to obtain the max id of the variable
96 *
97 * @return the maximum number of variables in the formula
98 */
99 public abstract int nVars();
100
101 /**
102 * to obtain the real number of variables appearing in the formula
103 *
104 * @return the number of variables used in the pool
105 */
106 int realnVars();
107
108 /**
109 * Ask the solver for a free variable identifier, in Dimacs format (i.e. a
110 * positive number). Note that a previous call to ensurePool(max) will
111 * reserve in the solver the variable identifier from 1 to max, so
112 * nextFreeVarId() would return max+1, even if some variable identifiers
113 * smaller than max are not used.
114 *
115 * @return a variable identifier not in use in the constraints already
116 * inside the solver.
117 * @since 2.1
118 */
119 int nextFreeVarId(boolean reserve);
120
121 public abstract int not(int lit);
122
123 public abstract void reset(int lit);
124
125 public abstract int getLevel(int lit);
126
127 public abstract void setLevel(int lit, int l);
128
129 public abstract Constr getReason(int lit);
130
131 public abstract void setReason(int lit, Constr r);
132
133 public abstract IVec<Undoable> undos(int lit);
134
135 public abstract void watch(int lit, Propagatable c);
136
137 /**
138 * @param lit
139 * a literal
140 * @return the list of all the constraints that watch the negation of lit
141 */
142 public abstract IVec<Propagatable> watches(int lit);
143
144 public abstract String valueToString(int lit);
145 }