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.minisat.core; 31 32 import org.sat4j.specs.IConstr; 33 import org.sat4j.specs.IVecInt; 34 import org.sat4j.specs.UnitPropagationListener; 35 36 /* 37 * Created on 16 oct. 2003 38 */ 39 40 /** 41 * Basic constraint abstraction used in Solver. 42 * 43 * Any new constraint type should implement that interface. 44 * 45 * @author leberre 46 */ 47 public interface Constr extends IConstr { 48 49 /** 50 * Remove a constraint from the solver. 51 * 52 * @param upl 53 * @since 2.1 54 */ 55 void remove(UnitPropagationListener upl); 56 57 /** 58 * Simplifies a constraint, by removing top level falsified literals for 59 * instance. 60 * 61 * @return true iff the constraint is satisfied and can be removed from the 62 * database. 63 */ 64 boolean simplify(); 65 66 /** 67 * Compute the reason for a given assignment. 68 * 69 * If the constraint is a clause, it is supposed to be either a unit clause 70 * or a falsified one. It is expected that the falsification of the 71 * constraint has been detected as soon at is occurs (e.g. using 72 * {@link Propagatable#propagate(UnitPropagationListener, int)}. 73 * 74 * 75 * @param p 76 * a satisfied literal (or Lit.UNDEFINED) 77 * @param outReason 78 * the list of falsified literals whose negation is the reason of 79 * the assignment of p to true. 80 */ 81 void calcReason(int p, IVecInt outReason); 82 83 /** 84 * Compute the reason for a given assignment in a the constraint created on 85 * the fly in the solver. Compared to the method 86 * {@link #calcReason(int, IVecInt)}, the falsification may not have been 87 * detected as soon as possible. As such, it is necessary to take into 88 * account the order of the literals in the trail. 89 * 90 * @param p 91 * a satisfied literal (or Lit.UNDEFINED) 92 * @param trail 93 * all the literals satisfied in the solvers, should not be 94 * modified. 95 * @param outReason 96 * a list of falsified literals whose negation is the reason of 97 * the assignment of p to true. 98 * @since 2.3.3 99 */ 100 void calcReasonOnTheFly(int p, IVecInt trail, IVecInt outReason); 101 102 /** 103 * Increase the constraint activity. 104 * 105 * @param claInc 106 * the value to increase the activity with 107 */ 108 void incActivity(double claInc); 109 110 /** 111 * 112 * @param claInc 113 * @since 2.1 114 * 115 */ 116 @Deprecated 117 void forwardActivity(double claInc); 118 119 /** 120 * Indicate wether a constraint is responsible from an assignment. 121 * 122 * @return true if a constraint is a "reason" for an assignment. 123 */ 124 boolean locked(); 125 126 /** 127 * Mark a constraint as learnt. 128 */ 129 130 void setLearnt(); 131 132 /** 133 * Register the constraint to the solver. 134 */ 135 void register(); 136 137 /** 138 * Rescale the clause activity by a value. 139 * 140 * @param d 141 * the value to rescale the clause activity with. 142 */ 143 void rescaleBy(double d); 144 145 /** 146 * Set the activity at a specific value 147 * 148 * @param d 149 * the new activity 150 * @since 2.3.1 151 */ 152 void setActivity(double d); 153 154 /** 155 * Method called when the constraint is to be asserted. It means that the 156 * constraint was learned during the search and it should now propagate some 157 * truth values. In the clausal case, only one literal should be propagated. 158 * In other cases, it might be different. 159 * 160 * @param s 161 * a UnitPropagationListener to use for unit propagation. 162 */ 163 void assertConstraint(UnitPropagationListener s); 164 165 /** 166 * Method called when the constraint is added to the solver "on the fly". In 167 * that case, the constraint may or may not have to propagate some literals, 168 * unlike the {@link #assertConstraint(UnitPropagationListener)} method. 169 * 170 * @param s 171 * a UnitPropagationListener to use for unit propagation. 172 * @since 2.3.4 173 */ 174 void assertConstraintIfNeeded(UnitPropagationListener s); 175 176 }