View Javadoc

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