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.IConstr;
29  import org.sat4j.specs.IVecInt;
30  
31  /*
32   * Created on 16 oct. 2003
33   */
34  
35  /**
36   * Basic constraint abstraction used in Solver.
37   * 
38   * Any new constraint type should implement that interface.
39   * 
40   * @author leberre
41   */
42  public interface Constr extends Propagatable, IConstr {
43  
44      /**
45       * Remove a constraint from the solver.
46       * 
47       */
48      void remove();
49  
50      /**
51       * Simplifies a constraint, by removing top level falsified literals for
52       * instance.
53       * 
54       * @return true iff the constraint is satisfied.
55       */
56      boolean simplify();
57  
58      /**
59       * Compute the reason for a given assignment.
60       * 
61       * If the constraint is a clause, it is supposed to be either a unit clause
62       * or a falsified one.
63       * 
64       * @param p
65       *            a satisfied literal (or Lit.UNDEFINED)
66       * @param outReason
67       *            the list of falsified literals whose negation is the reason of
68       *            the assignment of p to true.
69       */
70      void calcReason(int p, IVecInt outReason);
71  
72      /**
73       * Increase the constraint activity.
74       * 
75       * @param claInc
76       *            the value to increase the activity with
77       */
78      void incActivity(double claInc);
79  
80      /**
81       * To obtain the activity of the constraint.
82       * 
83       * @return the activity of the clause.
84       */
85      double getActivity();
86  
87      /**
88       * Indicate wether a constraint is responsible from an assignment.
89       * 
90       * @return true if a constraint is a "reason" for an assignment.
91       */
92      boolean locked();
93  
94      /**
95       * Mark a constraint as learnt.
96       */
97  
98      void setLearnt();
99  
100     /**
101      * Register the constraint to the solver.
102      */
103     void register();
104 
105     /**
106      * Rescale the clause activity by a value.
107      * 
108      * @param d
109      *            the value to rescale the clause activity with.
110      */
111     void rescaleBy(double d);
112 
113     /**
114      * Method called when the constraint is to be asserted. It means that the
115      * constraint was learnt during the search and it should now propagate some
116      * truth values. In the clausal case, only one literal should be propagated.
117      * In other cases, it might be different.
118      * 
119      * @param s
120      *            a UnitPropagationListener to use for unit propagation.
121      */
122     void assertConstraint(UnitPropagationListener s);
123 }