View Javadoc

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