rel-test.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Int {
00039
00040
00041
00042
00043
00044
00045 template<class VX, class VY>
00046 forceinline RelTest
00047 rtest_eq_bnd(VX x, VY y) {
00048 if ((x.min() > y.max()) || (x.max() < y.min())) return RT_FALSE;
00049 return (x.assigned() && y.assigned()) ? RT_TRUE : RT_MAYBE;
00050 }
00051
00052 template<class VX, class VY>
00053 RelTest
00054 rtest_eq_dom_check(VX x, VY y) {
00055 ViewRanges<VX> rx(x);
00056 ViewRanges<VY> ry(y);
00057 while (rx() && ry()) {
00058 if (rx.max() < ry.min()) {
00059 ++rx;
00060 } else if (ry.max() < rx.min()) {
00061 ++ry;
00062 } else return RT_MAYBE;
00063 }
00064 return RT_FALSE;
00065 }
00066
00067 template<class VX, class VY>
00068 forceinline RelTest
00069 rtest_eq_dom(VX x, VY y) {
00070 RelTest rt = rtest_eq_bnd(x,y);
00071 if (rt != RT_MAYBE) return rt;
00072 return (x.range() && y.range()) ? RT_MAYBE : rtest_eq_dom_check(x,y);
00073 }
00074
00075
00076 template<class VX>
00077 forceinline RelTest
00078 rtest_eq_bnd(VX x, int n) {
00079 if ((n > x.max()) || (n < x.min())) return RT_FALSE;
00080 return x.assigned() ? RT_TRUE : RT_MAYBE;
00081 }
00082
00083 template<class VX>
00084 RelTest
00085 rtest_eq_dom_check(VX x, int n) {
00086 ViewRanges<VX> rx(x);
00087 while (n > rx.max()) ++rx;
00088 return (n >= rx.min()) ? RT_MAYBE : RT_FALSE;
00089 }
00090
00091 template<class VX>
00092 forceinline RelTest
00093 rtest_eq_dom(VX x, int n) {
00094 RelTest rt = rtest_eq_bnd(x,n);
00095 if (rt != RT_MAYBE) return rt;
00096 return x.range() ? RT_MAYBE : rtest_eq_dom_check(x,n);
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106 template<class VX, class VY>
00107 forceinline RelTest
00108 rtest_nq_bnd(VX x, VY y) {
00109 if ((x.min() > y.max()) || (x.max() < y.min())) return RT_TRUE;
00110 return (x.assigned() && y.assigned()) ? RT_FALSE : RT_MAYBE;
00111 }
00112
00113 template<class VX, class VY>
00114 forceinline RelTest
00115 rtest_nq_dom_check(VX x, VY y) {
00116 ViewRanges<VX> rx(x);
00117 ViewRanges<VY> ry(y);
00118 while (rx() && ry()) {
00119 if (rx.max() < ry.min()) {
00120 ++rx;
00121 } else if (ry.max() < rx.min()) {
00122 ++ry;
00123 } else return RT_MAYBE;
00124 }
00125 return RT_TRUE;
00126 }
00127
00128 template<class VX, class VY>
00129 forceinline RelTest
00130 rtest_nq_dom(VX x, VY y) {
00131 RelTest rt = rtest_nq_bnd(x,y);
00132 if (rt != RT_MAYBE) return rt;
00133 return (x.range() && y.range()) ? RT_MAYBE : rtest_nq_dom_check(x,y);
00134 }
00135
00136
00137 template<class VX>
00138 forceinline RelTest
00139 rtest_nq_bnd(VX x, int n) {
00140 if ((n > x.max()) || (n < x.min())) return RT_TRUE;
00141 return (x.assigned()) ? RT_FALSE : RT_MAYBE;
00142 }
00143
00144 template<class VX>
00145 forceinline RelTest
00146 rtest_nq_dom_check(VX x, int n) {
00147 ViewRanges<VX> rx(x);
00148 while (n > rx.max()) ++rx;
00149 return (n >= rx.min()) ? RT_MAYBE : RT_TRUE;
00150 }
00151
00152 template<class VX>
00153 forceinline RelTest
00154 rtest_nq_dom(VX x, int n) {
00155 RelTest rt = rtest_nq_bnd(x,n);
00156 if (rt != RT_MAYBE) return rt;
00157 return x.range() ? RT_MAYBE : rtest_nq_dom_check(x,n);
00158 }
00159
00160
00161
00162
00163
00164
00165
00166 template<class VX, class VY>
00167 forceinline RelTest
00168 rtest_lq(VX x, VY y) {
00169 if (x.max() <= y.min()) return RT_TRUE;
00170 if (x.min() > y.max()) return RT_FALSE;
00171 return RT_MAYBE;
00172 }
00173
00174 template<class VX>
00175 forceinline RelTest
00176 rtest_lq(VX x, int n) {
00177 if (x.max() <= n) return RT_TRUE;
00178 if (x.min() > n) return RT_FALSE;
00179 return RT_MAYBE;
00180 }
00181
00182 template<class VX, class VY>
00183 forceinline RelTest
00184 rtest_le(VX x, VY y) {
00185 if (x.max() < y.min()) return RT_TRUE;
00186 if (x.min() >= y.max()) return RT_FALSE;
00187 return RT_MAYBE;
00188 }
00189
00190 template<class VX>
00191 forceinline RelTest
00192 rtest_le(VX x, int n) {
00193 if (x.max() < n) return RT_TRUE;
00194 if (x.min() >= n) return RT_FALSE;
00195 return RT_MAYBE;
00196 }
00197
00198 template<class VX, class VY>
00199 forceinline RelTest
00200 rtest_gq(VX x, VY y) {
00201 if (x.max() < y.min()) return RT_FALSE;
00202 if (x.min() >= y.max()) return RT_TRUE;
00203 return RT_MAYBE;
00204 }
00205
00206 template<class VX>
00207 forceinline RelTest
00208 rtest_gq(VX x, int n) {
00209 if (x.max() < n) return RT_FALSE;
00210 if (x.min() >= n) return RT_TRUE;
00211 return RT_MAYBE;
00212 }
00213
00214 template<class VX, class VY>
00215 forceinline RelTest
00216 rtest_gr(VX x, VY y) {
00217 if (x.max() <= y.min()) return RT_FALSE;
00218 if (x.min() > y.max()) return RT_TRUE;
00219 return RT_MAYBE;
00220 }
00221
00222 template<class VX>
00223 forceinline RelTest
00224 rtest_gr(VX x, int n) {
00225 if (x.max() <= n) return RT_FALSE;
00226 if (x.min() > n) return RT_TRUE;
00227 return RT_MAYBE;
00228 }
00229
00230 }}
00231
00232
00233