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 31 package org.sat4j.pb.tools; 32 33 import org.sat4j.core.Vec; 34 import org.sat4j.specs.ContradictionException; 35 import org.sat4j.specs.IConstr; 36 import org.sat4j.specs.IVec; 37 import org.sat4j.specs.IVecInt; 38 39 /** 40 * That class represents the RHS of an implication. 41 * 42 * @author daniel 43 * 44 * @param <T> 45 * @param <C> 46 */ 47 public class ImplicationRHS<T, C> { 48 49 private final IVecInt clause; 50 private final DependencyHelper<T, C> helper; 51 52 private final IVec<IConstr> toName = new Vec<IConstr>(); 53 54 public ImplicationRHS(DependencyHelper<T, C> helper, IVecInt clause) { 55 this.clause = clause; 56 this.helper = helper; 57 } 58 59 /** 60 * Build an implication with a conjunction of literals in the RHS. 61 * 62 * @param thing 63 * a domain object that will appear positively. 64 * @return a RHS conjunction of literals. 65 * @throws ContradictionException 66 */ 67 public ImplicationAnd<T, C> implies(T thing) throws ContradictionException { 68 ImplicationAnd<T, C> and = new ImplicationAnd<T, C>(this.helper, 69 this.clause); 70 and.and(thing); 71 return and; 72 } 73 74 /** 75 * Build an implication with a disjunction of literals in the RHS. 76 * 77 * @param thing 78 * a domain object 79 * @return an object used to name the constraint. The constraint MUST BE 80 * NAMED. 81 * @throws ContradictionException 82 */ 83 public ImplicationNamer<T, C> implies(T... things) 84 throws ContradictionException { 85 for (T t : things) { 86 this.clause.push(this.helper.getIntValue(t)); 87 } 88 this.toName.push(this.helper.solver.addClause(this.clause)); 89 return new ImplicationNamer<T, C>(this.helper, this.toName); 90 } 91 92 /** 93 * Build an implication with a conjunction of literals in the RHS. 94 * 95 * @param thing 96 * a domain object that will appear negatively. 97 * @return a RHS conjunction of literals. 98 * @throws ContradictionException 99 */ 100 public ImplicationAnd<T, C> impliesNot(T thing) 101 throws ContradictionException { 102 ImplicationAnd<T, C> and = new ImplicationAnd<T, C>(this.helper, 103 this.clause); 104 and.andNot(thing); 105 return and; 106 } 107 108 }