Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
rel-test.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2003
8  *
9  * Last modified:
10  * $Date: 2013-03-07 02:18:29 +0100 (Thu, 07 Mar 2013) $ by $Author: mears $
11  * $Revision: 13455 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode { namespace Int {
39 
40  /*
41  * Testing equality
42  *
43  */
44 
45  template<class View>
47  rtest_eq_bnd(View x, View y) {
48  if ((x.min() > y.max()) || (x.max() < y.min())) return RT_FALSE;
49  return (x.assigned() && y.assigned()) ? RT_TRUE : RT_MAYBE;
50  }
51 
52  template<class View>
53  RelTest
54  rtest_eq_dom_check(View x, View y) {
55  ViewRanges<View> rx(x), ry(y);
56  while (rx() && ry()) {
57  if (rx.max() < ry.min()) {
58  ++rx;
59  } else if (ry.max() < rx.min()) {
60  ++ry;
61  } else return RT_MAYBE;
62  }
63  return RT_FALSE;
64  }
65 
66  template<class View>
68  rtest_eq_dom(View x, View y) {
69  RelTest rt = rtest_eq_bnd(x,y);
70  if (rt != RT_MAYBE) return rt;
71  return (x.range() && y.range()) ? RT_MAYBE : rtest_eq_dom_check(x,y);
72  }
73 
74 
75  template<class View>
77  rtest_eq_bnd(View x, int n) {
78  if ((n > x.max()) || (n < x.min())) return RT_FALSE;
79  return x.assigned() ? RT_TRUE : RT_MAYBE;
80  }
81 
82  template<class View>
83  RelTest
84  rtest_eq_dom_check(View x, int n) {
85  ViewRanges<View> rx(x);
86  while (n > rx.max()) ++rx;
87  return (n >= rx.min()) ? RT_MAYBE : RT_FALSE;
88  }
89 
90  template<class View>
92  rtest_eq_dom(View x, int n) {
93  RelTest rt = rtest_eq_bnd(x,n);
94  if (rt != RT_MAYBE) return rt;
95  return x.range() ? RT_MAYBE : rtest_eq_dom_check(x,n);
96  }
97 
98 
99 
100  /*
101  * Testing disequality
102  *
103  */
104 
105  template<class View>
107  rtest_nq_bnd(View x, View y) {
108  if ((x.min() > y.max()) || (x.max() < y.min())) return RT_TRUE;
109  return (x.assigned() && y.assigned()) ? RT_FALSE : RT_MAYBE;
110  }
111 
112  template<class View>
114  rtest_nq_dom_check(View x, View y) {
115  ViewRanges<View> rx(x), ry(y);
116  while (rx() && ry()) {
117  if (rx.max() < ry.min()) {
118  ++rx;
119  } else if (ry.max() < rx.min()) {
120  ++ry;
121  } else return RT_MAYBE;
122  }
123  return RT_TRUE;
124  }
125 
126  template<class View>
128  rtest_nq_dom(View x, View y) {
129  RelTest rt = rtest_nq_bnd(x,y);
130  if (rt != RT_MAYBE) return rt;
131  return (x.range() && y.range()) ? RT_MAYBE : rtest_nq_dom_check(x,y);
132  }
133 
134 
135  template<class View>
137  rtest_nq_bnd(View x, int n) {
138  if ((n > x.max()) || (n < x.min())) return RT_TRUE;
139  return (x.assigned()) ? RT_FALSE : RT_MAYBE;
140  }
141 
142  template<class View>
144  rtest_nq_dom_check(View x, int n) {
145  ViewRanges<View> rx(x);
146  while (n > rx.max()) ++rx;
147  return (n >= rx.min()) ? RT_MAYBE : RT_TRUE;
148  }
149 
150  template<class View>
152  rtest_nq_dom(View x, int n) {
153  RelTest rt = rtest_nq_bnd(x,n);
154  if (rt != RT_MAYBE) return rt;
155  return x.range() ? RT_MAYBE : rtest_nq_dom_check(x,n);
156  }
157 
158 
159  /*
160  * Testing inequalities
161  *
162  */
163 
164  template<class View>
166  rtest_lq(View x, int n) {
167  if (x.max() <= n) return RT_TRUE;
168  if (x.min() > n) return RT_FALSE;
169  return RT_MAYBE;
170  }
171 
172  template<class View>
174  rtest_lq(View x, View y) {
175  if (x.max() <= y.min()) return RT_TRUE;
176  if (x.min() > y.max()) return RT_FALSE;
177  return RT_MAYBE;
178  }
179 
180  template<class View>
182  rtest_le(View x, int n) {
183  if (x.max() < n) return RT_TRUE;
184  if (x.min() >= n) return RT_FALSE;
185  return RT_MAYBE;
186  }
187 
188  template<class View>
190  rtest_le(View x, View y) {
191  if (x.max() < y.min()) return RT_TRUE;
192  if (x.min() >= y.max()) return RT_FALSE;
193  return RT_MAYBE;
194  }
195 
196  template<class View>
198  rtest_gq(View x, int n) {
199  if (x.max() < n) return RT_FALSE;
200  if (x.min() >= n) return RT_TRUE;
201  return RT_MAYBE;
202  }
203 
204  template<class View>
206  rtest_gq(View x, View y) {
207  if (x.max() < y.min()) return RT_FALSE;
208  if (x.min() >= y.max()) return RT_TRUE;
209  return RT_MAYBE;
210  }
211 
212  template<class View>
214  rtest_gr(View x, int n) {
215  if (x.max() <= n) return RT_FALSE;
216  if (x.min() > n) return RT_TRUE;
217  return RT_MAYBE;
218  }
219 
220  template<class View>
222  rtest_gr(View x, View y) {
223  if (x.max() <= y.min()) return RT_FALSE;
224  if (x.min() > y.max()) return RT_TRUE;
225  return RT_MAYBE;
226  }
227 
228 }}
229 
230 // STATISTICS: int-var
231 
Relation may hold or not.
Definition: view.hpp:1616
RelTest rtest_gr(View x, int n)
Test whether view x is greater than integer n.
Definition: rel-test.hpp:214
Range iterator for integer views.
Definition: view.hpp:54
RelTest rtest_gq(View x, int n)
Test whether view x is greater or equal than integer n.
Definition: rel-test.hpp:198
int min(void) const
Return smallest value of range.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Relation does not hold.
Definition: view.hpp:1615
RelTest
Result of testing relation.
Definition: view.hpp:1614
RelTest rtest_nq_dom(View x, View y)
Test whether views x and y are different (use full domain information)
Definition: rel-test.hpp:128
RelTest rtest_eq_dom(View x, View y)
Test whether views x and y are equal (use full domain information)
Definition: rel-test.hpp:68
RelTest rtest_eq_dom_check(View x, View y)
Definition: rel-test.hpp:54
RelTest rtest_nq_bnd(View x, View y)
Test whether views x and y are different (use bounds information)
Definition: rel-test.hpp:107
RelTest rtest_le(View x, int n)
Test whether view x is less than integer n.
Definition: rel-test.hpp:182
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
#define forceinline
Definition: config.hpp:132
RelTest rtest_eq_bnd(View x, View y)
Test whether views x and y are equal (use bounds information)
Definition: rel-test.hpp:47
int max(void) const
Return largest value of range.
Gecode toplevel namespace
RelTest rtest_nq_dom_check(View x, View y)
Definition: rel-test.hpp:114
Relation does hold.
Definition: view.hpp:1617
RelTest rtest_lq(View x, int n)
Test whether view x is less or equal than integer n.
Definition: rel-test.hpp:166