1 /*
2  * XlteqC.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.Domain;
34 import org.jacop.core.IntDomain;
35 import org.jacop.core.IntVar;
36 import org.jacop.core.Store;
37 
38 import java.util.concurrent.atomic.AtomicInteger;
39 
40 /**
41  * Constraint X {@literal <=} C
42  *
43  * @author Krzysztof Kuchcinski and Radoslaw Szymanek
44  * @version 4.8
45  */
46 
47 public class XlteqC extends PrimitiveConstraint {
48 
49     final static AtomicInteger idNumber = new AtomicInteger(0);
50 
51     /**
52      * It specifies variable x which must be smaller or equal to a given constant.
53      */
54     final public IntVar x;
55 
56     /**
57      * It specifies constant c from which a given variable must be smaller or equal.
58      */
59     final public int c;
60 
61     /**
62      * It constructs constraint X {@literal <=} C.
63      *
64      * @param x variable x.
65      * @param c constant c.
66      */
XlteqC(IntVar x, int c)67     public XlteqC(IntVar x, int c) {
68 
69         if (x == null)
70             throw new IllegalArgumentException("Constraint XlteqC has variable x that is null.");
71 
72         numberId = idNumber.incrementAndGet();
73 
74         this.x = x;
75         this.c = c;
76 
77         setScope(x);
78 
79     }
80 
consistency(final Store store)81     @Override public void consistency(final Store store) {
82         x.domain.inMax(store.level, x, c);
83     }
84 
getDefaultNestedNotConsistencyPruningEvent()85     @Override protected int getDefaultNestedNotConsistencyPruningEvent() {
86         return IntDomain.BOUND;
87     }
88 
getDefaultNestedConsistencyPruningEvent()89     @Override protected int getDefaultNestedConsistencyPruningEvent() {
90         return IntDomain.BOUND;
91     }
92 
getDefaultNotConsistencyPruningEvent()93     @Override protected int getDefaultNotConsistencyPruningEvent() {
94         return Domain.NONE;
95     }
96 
getDefaultConsistencyPruningEvent()97     @Override public int getDefaultConsistencyPruningEvent() {
98         return Domain.NONE;
99     }
100 
notConsistency(final Store store)101     @Override public void notConsistency(final Store store) {
102         x.domain.inMin(store.level, x, c + 1);
103     }
104 
notSatisfied()105     @Override public boolean notSatisfied() {
106         return x.min() > c;
107     }
108 
satisfied()109     @Override public boolean satisfied() {
110         return x.max() <= c;
111     }
112 
toString()113     @Override public String toString() {
114         return id() + " : XlteqC(" + x + ", " + c + " )";
115     }
116 
117 }
118