constint.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 {
00039
00040 namespace Int {
00041
00042
00043
00044
00045
00046 forceinline
00047 ConstIntView::ConstIntView(void) {}
00048 forceinline
00049 ConstIntView::ConstIntView(int n) : x(n) {}
00050 forceinline void
00051 ConstIntView::init(int n) {
00052 x=n;
00053 }
00054
00055
00056
00057
00058
00059
00060 forceinline int
00061 ConstIntView::min(void) const {
00062 return x;
00063 }
00064 forceinline int
00065 ConstIntView::max(void) const {
00066 return x;
00067 }
00068 forceinline int
00069 ConstIntView::med(void) const {
00070 return x;
00071 }
00072 forceinline int
00073 ConstIntView::val(void) const {
00074 return x;
00075 }
00076
00077 forceinline unsigned int
00078 ConstIntView::size(void) const {
00079 return 1;
00080 }
00081 forceinline unsigned int
00082 ConstIntView::width(void) const {
00083 return 1;
00084 }
00085 forceinline unsigned int
00086 ConstIntView::regret_min(void) const {
00087 return 0;
00088 }
00089 forceinline unsigned int
00090 ConstIntView::regret_max(void) const {
00091 return 0;
00092 }
00093
00094
00095
00096
00097
00098
00099 forceinline bool
00100 ConstIntView::range(void) const {
00101 return true;
00102 }
00103 forceinline bool
00104 ConstIntView::assigned(void) const {
00105 return true;
00106 }
00107
00108 forceinline bool
00109 ConstIntView::in(int n) const {
00110 return n == x;
00111 }
00112 forceinline bool
00113 ConstIntView::in(double n) const {
00114 return n == x;
00115 }
00116
00117
00118
00119
00120
00121
00122 forceinline ModEvent
00123 ConstIntView::lq(Space&, int n) {
00124 return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
00125 }
00126 forceinline ModEvent
00127 ConstIntView::lq(Space&, double n) {
00128 return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
00129 }
00130
00131 forceinline ModEvent
00132 ConstIntView::le(Space&, int n) {
00133 return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
00134 }
00135 forceinline ModEvent
00136 ConstIntView::le(Space&, double n) {
00137 return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
00138 }
00139
00140 forceinline ModEvent
00141 ConstIntView::gq(Space&, int n) {
00142 return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
00143 }
00144 forceinline ModEvent
00145 ConstIntView::gq(Space&, double n) {
00146 return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
00147 }
00148
00149 forceinline ModEvent
00150 ConstIntView::gr(Space&, int n) {
00151 return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
00152 }
00153 forceinline ModEvent
00154 ConstIntView::gr(Space&, double n) {
00155 return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
00156 }
00157
00158 forceinline ModEvent
00159 ConstIntView::nq(Space&, int n) {
00160 return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
00161 }
00162 forceinline ModEvent
00163 ConstIntView::nq(Space&, double n) {
00164 return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
00165 }
00166
00167 forceinline ModEvent
00168 ConstIntView::eq(Space&, int n) {
00169 return (x == n) ? ME_INT_NONE : ME_INT_FAILED;
00170 }
00171 forceinline ModEvent
00172 ConstIntView::eq(Space&, double n) {
00173 return (x == n) ? ME_INT_NONE : ME_INT_FAILED;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182 template<class I>
00183 forceinline ModEvent
00184 ConstIntView::narrow_r(Space&, I& i, bool) {
00185 Iter::Ranges::IsRangeIter<I>();
00186 return i() ? ME_INT_NONE : ME_INT_FAILED;
00187 }
00188 template<class I>
00189 forceinline ModEvent
00190 ConstIntView::inter_r(Space&, I& i, bool) {
00191 Iter::Ranges::IsRangeIter<I>();
00192 while (i() && (i.max() < x))
00193 ++i;
00194 return (i() && (i.min() <= x)) ? ME_INT_NONE : ME_INT_FAILED;
00195 }
00196 template<class I>
00197 forceinline ModEvent
00198 ConstIntView::minus_r(Space&, I& i, bool) {
00199 Iter::Ranges::IsRangeIter<I>();
00200 while (i() && (i.max() < x))
00201 ++i;
00202 return (i() && (i.min() <= x)) ? ME_INT_FAILED : ME_INT_NONE;
00203 }
00204 template<class I>
00205 forceinline ModEvent
00206 ConstIntView::narrow_v(Space&, I& i, bool) {
00207 Iter::Values::IsValueIter<I>();
00208 return i() ? ME_INT_NONE : ME_INT_FAILED;
00209 }
00210 template<class I>
00211 forceinline ModEvent
00212 ConstIntView::inter_v(Space&, I& i, bool) {
00213 Iter::Values::IsValueIter<I>();
00214 while (i() && (i.val() < x))
00215 ++i;
00216 return (i() && (i.val() == x)) ? ME_INT_NONE : ME_INT_FAILED;
00217 }
00218 template<class I>
00219 forceinline ModEvent
00220 ConstIntView::minus_v(Space&, I& i, bool) {
00221 Iter::Values::IsValueIter<I>();
00222 while (i() && (i.val() < x))
00223 ++i;
00224 return (i() && (i.val() == x)) ? ME_INT_FAILED : ME_INT_NONE;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233 forceinline void
00234 ConstIntView::schedule(Space& home, Propagator& p, ModEvent me) {
00235 return IntView::schedule(home,p,me);
00236 }
00237 forceinline ModEvent
00238 ConstIntView::me(const ModEventDelta&) {
00239 return ME_INT_NONE;
00240 }
00241 forceinline ModEventDelta
00242 ConstIntView::med(ModEvent me) {
00243 return static_cast<ModEventDelta>(me);
00244 }
00245
00246
00247
00248
00249
00250
00251 forceinline void
00252 ConstIntView::subscribe(Space& home, Propagator& p, PropCond,bool) {
00253 schedule(home,p,ME_INT_VAL);
00254 }
00255 forceinline void
00256 ConstIntView::cancel(Space&,Propagator&,PropCond) {}
00257 forceinline void
00258 ConstIntView::subscribe(Space&, Advisor&) {}
00259 forceinline void
00260 ConstIntView::cancel(Space&,Advisor&) {}
00261
00262
00263
00264
00265
00266
00267
00268 forceinline ModEvent
00269 ConstIntView::modevent(const Delta&) {
00270 return ME_INT_NONE;
00271 }
00272 forceinline int
00273 ConstIntView::min(const Delta&) const {
00274 return 1;
00275 }
00276 forceinline int
00277 ConstIntView::max(const Delta&) const {
00278 return 0;
00279 }
00280 forceinline bool
00281 ConstIntView::any(const Delta&) const {
00282 return true;
00283 }
00284
00285
00286
00287
00288
00289
00290
00291 forceinline void
00292 ConstIntView::update(Space&, bool, ConstIntView& y) {
00293 x = y.x;
00294 }
00295
00296
00301 template<>
00302 class ViewRanges<ConstIntView> {
00303 private:
00305 int n;
00306 public:
00308
00309
00310 ViewRanges(void);
00312 ViewRanges(const ConstIntView& x);
00314 void init(const ConstIntView& x);
00316
00318
00319
00320 bool operator ()(void) const;
00322 void operator ++(void);
00324
00326
00327
00328 int min(void) const;
00330 int max(void) const;
00332 unsigned int width(void) const;
00334 };
00335
00336 forceinline
00337 ViewRanges<ConstIntView>::ViewRanges(void) {}
00338
00339 forceinline
00340 ViewRanges<ConstIntView>::ViewRanges(const ConstIntView& x)
00341 : n(x.val()) {}
00342
00343 forceinline bool
00344 ViewRanges<ConstIntView>::operator ()(void) const {
00345 return n <= Limits::max;
00346 }
00347 forceinline void
00348 ViewRanges<ConstIntView>::operator ++(void) {
00349 n = Limits::max+1;
00350 }
00351
00352 forceinline int
00353 ViewRanges<ConstIntView>::min(void) const {
00354 return n;
00355 }
00356 forceinline int
00357 ViewRanges<ConstIntView>::max(void) const {
00358 return n;
00359 }
00360 forceinline unsigned int
00361 ViewRanges<ConstIntView>::width(void) const {
00362 return 1;
00363 }
00364
00365 }
00366
00367
00368
00369
00370
00371 forceinline bool
00372 same(const Int::ConstIntView& x, const Int::ConstIntView& y) {
00373 return x.min() == y.min();
00374 }
00375 forceinline bool
00376 same(const Int::IntView&, const Int::ConstIntView&) {
00377 return false;
00378 }
00379 forceinline bool
00380 same(const Int::BoolView&, const Int::ConstIntView&) {
00381 return false;
00382 }
00383 forceinline bool
00384 before(const Int::ConstIntView& x, const Int::ConstIntView& y) {
00385 return x.min() < y.min();
00386 }
00387
00388 }
00389
00390
00391