1 /* 2 * XplusYlteqZ.java 3 * This file is part of JaCoP. 4 * <p> 5 * JaCoP is a Java Constraint Programming solver. 6 * <p> 7 * Copyright (C) 2000-2008 Krzysztof Kuchcinski and Radoslaw Szymanek 8 * <p> 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU Affero General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * <p> 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Affero General Public License for more details. 18 * <p> 19 * Notwithstanding any other provision of this License, the copyright 20 * owners of this work supplement the terms of this License with terms 21 * prohibiting misrepresentation of the origin of this work and requiring 22 * that modified versions of this work be marked in reasonable ways as 23 * different from the original version. This supplement of the license 24 * terms is in accordance with Section 7 of GNU Affero General Public 25 * License version 3. 26 * <p> 27 * You should have received a copy of the GNU Affero General Public License 28 * along with this program. If not, see <http://www.gnu.org/licenses/>. 29 */ 30 31 package org.jacop.constraints; 32 33 import org.jacop.core.IntDomain; 34 import org.jacop.core.IntVar; 35 import org.jacop.core.Store; 36 37 import java.util.concurrent.atomic.AtomicInteger; 38 39 /** 40 * Constraint X + Y{@literal =<} Z 41 * <p> 42 * Bound consistency is used. 43 * 44 * @author Krzysztof Kuchcinski and Radoslaw Szymanek 45 * @version 4.8 46 */ 47 48 public class XplusYlteqZ extends PrimitiveConstraint { 49 50 final static AtomicInteger idNumber = new AtomicInteger(0); 51 52 /** 53 * It specifies variable x in constraint x + y{@literal <=} z. 54 */ 55 final public IntVar x; 56 57 /** 58 * It specifies variable x in constraint x + y{@literal <=} z. 59 */ 60 final public IntVar y; 61 62 /** 63 * It specifies variable x in constraint x + y{@literal <=} z. 64 */ 65 final public IntVar z; 66 67 /** 68 * It constructs X + Y{@literal <=} Z constraint. 69 * 70 * @param x variable x. 71 * @param y variable y. 72 * @param z variable z. 73 */ XplusYlteqZ(IntVar x, IntVar y, IntVar z)74 public XplusYlteqZ(IntVar x, IntVar y, IntVar z) { 75 76 checkInputForNullness(new String[] {"x", "y", "z"}, new Object[] {x, y, z}); 77 78 numberId = idNumber.incrementAndGet(); 79 80 this.x = x; 81 this.y = y; 82 this.z = z; 83 84 setScope(x, y, z); 85 } 86 consistency(final Store store)87 @Override public void consistency(final Store store) { 88 x.domain.inMax(store.level, x, z.max() - y.min()); 89 y.domain.inMax(store.level, y, z.max() - x.min()); 90 z.domain.inMin(store.level, z, x.min() + y.min()); 91 } 92 getDefaultNestedConsistencyPruningEvent()93 @Override protected int getDefaultNestedConsistencyPruningEvent() { 94 return IntDomain.BOUND; 95 } 96 getDefaultNestedNotConsistencyPruningEvent()97 @Override protected int getDefaultNestedNotConsistencyPruningEvent() { 98 return IntDomain.BOUND; 99 } 100 getDefaultNotConsistencyPruningEvent()101 @Override protected int getDefaultNotConsistencyPruningEvent() { 102 return IntDomain.BOUND; 103 } 104 getDefaultConsistencyPruningEvent()105 @Override public int getDefaultConsistencyPruningEvent() { 106 return IntDomain.BOUND; 107 } 108 notConsistency(final Store store)109 @Override public void notConsistency(final Store store) { 110 111 x.domain.inMin(store.level, x, z.min() - y.max() + 1); 112 113 y.domain.inMin(store.level, y, z.min() - x.max() + 1); 114 115 z.domain.inMax(store.level, z, x.max() + y.max() - 1); 116 117 118 } 119 notSatisfied()120 @Override public boolean notSatisfied() { 121 return x.min() + y.min() > z.max(); 122 } 123 satisfied()124 @Override public boolean satisfied() { 125 return x.max() + y.max() <= z.min(); 126 } 127 toString()128 @Override public String toString() { 129 130 return id() + " : XplusYlteqZ(" + x + ", " + y + ", " + z + " )"; 131 } 132 133 } 134