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 template<class View>
00045 forceinline
00046 CachedView<View>::CachedView(void) : _size(0) {}
00047 template<class View>
00048 forceinline
00049 CachedView<View>::CachedView(const View& y)
00050 : DerivedView<View>(y), _firstRange(NULL), _lastRange(NULL),
00051 _size(0) {}
00052
00053
00054
00055
00056
00057
00058 template<class View>
00059 forceinline int
00060 CachedView<View>::min(void) const {
00061 return x.min();
00062 }
00063 template<class View>
00064 forceinline int
00065 CachedView<View>::max(void) const {
00066 return x.max();
00067 }
00068 template<class View>
00069 forceinline int
00070 CachedView<View>::med(void) const {
00071 return x.med();
00072 }
00073 template<class View>
00074 forceinline int
00075 CachedView<View>::val(void) const {
00076 return x.val();
00077 }
00078 #ifdef GECODE_HAS_CBS
00079 template<class View>
00080 forceinline int
00081 CachedView<View>::baseval(int val) const {
00082 return val;
00083 }
00084 #endif
00085
00086 template<class View>
00087 forceinline unsigned int
00088 CachedView<View>::width(void) const {
00089 return x.width();
00090 }
00091 template<class View>
00092 forceinline unsigned int
00093 CachedView<View>::size(void) const {
00094 return x.size();
00095 }
00096 template<class View>
00097 forceinline unsigned int
00098 CachedView<View>::regret_min(void) const {
00099 return x.regret_min();
00100 }
00101 template<class View>
00102 forceinline unsigned int
00103 CachedView<View>::regret_max(void) const {
00104 return x.regret_max();
00105 }
00106
00107
00108
00109
00110
00111 template<class View>
00112 forceinline bool
00113 CachedView<View>::range(void) const {
00114 return x.range();
00115 }
00116 template<class View>
00117 forceinline bool
00118 CachedView<View>::in(int n) const {
00119 return x.in(n);
00120 }
00121 template<class View>
00122 forceinline bool
00123 CachedView<View>::in(long long int n) const {
00124 return x.in(n);
00125 }
00126
00127
00128
00129
00130
00131
00132 template<class View>
00133 forceinline ModEvent
00134 CachedView<View>::lq(Space& home, int n) {
00135 return x.lq(home,n);
00136 }
00137 template<class View>
00138 forceinline ModEvent
00139 CachedView<View>::lq(Space& home, long long int n) {
00140 return x.lq(home,n);
00141 }
00142 template<class View>
00143 forceinline ModEvent
00144 CachedView<View>::le(Space& home, int n) {
00145 return x.le(home,n);
00146 }
00147 template<class View>
00148 forceinline ModEvent
00149 CachedView<View>::le(Space& home, long long int n) {
00150 return x.le(home,n);
00151 }
00152 template<class View>
00153 forceinline ModEvent
00154 CachedView<View>::gq(Space& home, int n) {
00155 return x.gq(home,n);
00156 }
00157 template<class View>
00158 forceinline ModEvent
00159 CachedView<View>::gq(Space& home, long long int n) {
00160 return x.gq(home,n);
00161 }
00162 template<class View>
00163 forceinline ModEvent
00164 CachedView<View>::gr(Space& home, int n) {
00165 return x.gr(home,n);
00166 }
00167 template<class View>
00168 forceinline ModEvent
00169 CachedView<View>::gr(Space& home, long long int n) {
00170 return x.gr(home,n);
00171 }
00172 template<class View>
00173 forceinline ModEvent
00174 CachedView<View>::nq(Space& home, int n) {
00175 return x.nq(home,n);
00176 }
00177 template<class View>
00178 forceinline ModEvent
00179 CachedView<View>::nq(Space& home, long long int n) {
00180 return x.nq(home,n);
00181 }
00182 template<class View>
00183 forceinline ModEvent
00184 CachedView<View>::eq(Space& home, int n) {
00185 return x.eq(home,n);
00186 }
00187 template<class View>
00188 forceinline ModEvent
00189 CachedView<View>::eq(Space& home, long long int n) {
00190 return x.eq(home,n);
00191 }
00192
00193
00194
00195
00196
00197
00198 template<class View>
00199 template<class I>
00200 forceinline ModEvent
00201 CachedView<View>::narrow_r(Space& home, I& i, bool depend) {
00202 return x.narrow_r(home,i,depend);
00203 }
00204 template<class View>
00205 template<class I>
00206 forceinline ModEvent
00207 CachedView<View>::inter_r(Space& home, I& i, bool depend) {
00208 return x.inter_r(home,i,depend);
00209 }
00210 template<class View>
00211 template<class I>
00212 forceinline ModEvent
00213 CachedView<View>::minus_r(Space& home, I& i, bool depend) {
00214 return x.minus_r(home,i,depend);
00215 }
00216 template<class View>
00217 template<class I>
00218 forceinline ModEvent
00219 CachedView<View>::narrow_v(Space& home, I& i, bool depend) {
00220 return x.narrow_v(home,i,depend);
00221 }
00222 template<class View>
00223 template<class I>
00224 forceinline ModEvent
00225 CachedView<View>::inter_v(Space& home, I& i, bool depend) {
00226 return x.inter_v(home,i,depend);
00227 }
00228 template<class View>
00229 template<class I>
00230 forceinline ModEvent
00231 CachedView<View>::minus_v(Space& home, I& i, bool depend) {
00232 return x.minus_v(home,i,depend);
00233 }
00234
00235
00236
00237
00238
00239
00240
00241 template<class View>
00242 forceinline ModEventDelta
00243 CachedView<View>::med(ModEvent me) {
00244 return View::med(me);
00245 }
00246
00247
00248
00249
00250
00251
00252 template<class View>
00253 forceinline int
00254 CachedView<View>::min(const Delta& d) const {
00255 return x.min(d);
00256 }
00257 template<class View>
00258 forceinline int
00259 CachedView<View>::max(const Delta& d) const {
00260 return x.max(d);
00261 }
00262 template<class View>
00263 forceinline unsigned int
00264 CachedView<View>::width(const Delta& d) const {
00265 return x.width(d);
00266 }
00267 template<class View>
00268 forceinline bool
00269 CachedView<View>::any(const Delta& d) const {
00270 return x.any(d);
00271 }
00272
00273
00274
00275
00276
00277
00278
00279 template<class View>
00280 void
00281 CachedView<View>::update(Space& home, CachedView<View>& y) {
00282 DerivedView<View>::update(home,y);
00283 if (y._firstRange) {
00284 _firstRange = new (home) RangeList(y._firstRange->min(),
00285 y._firstRange->max(),NULL);
00286 RangeList* cur = _firstRange;
00287
00288 for (RangeList* y_cur = y._firstRange->next(); y_cur != NULL;
00289 y_cur = y_cur->next()) {
00290 RangeList* next =
00291 new (home) RangeList(y_cur->min(),y_cur->max(),NULL);
00292 cur->next(next);
00293 cur = next;
00294 }
00295 _lastRange = cur;
00296 _size = y._size;
00297 }
00298 }
00299
00300
00301
00302
00303
00304
00305 template<class View>
00306 void
00307 CachedView<View>::initCache(Space& home, const IntSet& s) {
00308 _firstRange = NULL;
00309 for (int i=s.ranges(); i--;) {
00310 _firstRange = new (home) RangeList(s.min(i),s.max(i),_firstRange);
00311 if (i==s.ranges()-1)
00312 _lastRange = _firstRange;
00313 }
00314 _size = s.size();
00315 }
00316
00317 template<class View>
00318 void
00319 CachedView<View>::cache(Space& home) {
00320 _firstRange->dispose(home,_lastRange);
00321 ViewRanges<View> xr(x);
00322 _firstRange = new (home) RangeList(xr.min(),xr.max(),NULL);
00323 ++xr;
00324 RangeList* cur = _firstRange;
00325 for (; xr(); ++xr) {
00326 RangeList* next = new (home) RangeList(xr.min(),xr.max(),NULL);
00327 cur->next(next);
00328 cur = next;
00329 }
00330 _lastRange = cur;
00331 _size = x.size();
00332 }
00333
00334 template<class View>
00335 forceinline bool
00336 CachedView<View>::modified(void) const {
00337 return x.size() != _size;
00338 }
00339
00340
00345 template<class View>
00346 class ViewRanges<CachedView<View> >
00347 : public ViewRanges<View> {
00348 public:
00350
00351
00352 ViewRanges(void);
00354 ViewRanges(const CachedView<View>& x);
00356 void init(const CachedView<View>& x);
00358 };
00359
00360 template<class View>
00361 forceinline
00362 ViewRanges<CachedView<View> >::ViewRanges(void) {}
00363
00364 template<class View>
00365 forceinline
00366 ViewRanges<CachedView<View> >::ViewRanges(const CachedView<View>& x) {
00367 ViewRanges<IntView>::init(x.base());
00368 }
00369
00370 template<class View>
00371 forceinline void
00372 ViewRanges<CachedView<View> >::init(const CachedView<View>& x) {
00373 ViewRanges<View>::init(x.base());
00374 }
00375
00376 template<class View>
00377 forceinline
00378 ViewDiffRanges<View>::ViewDiffRanges(void) {}
00379
00380 template<class View>
00381 forceinline
00382 ViewDiffRanges<View>::ViewDiffRanges(const CachedView<View>& x)
00383 : cr(x._firstRange), dr(x.base()) {
00384 Super::init(cr,dr);
00385 }
00386
00387 template<class View>
00388 forceinline void
00389 ViewDiffRanges<View>::init(const CachedView<View>& x) {
00390 cr.init(x._firstRange);
00391 dr.init(x.base());
00392 Super::init(cr,dr);
00393 }
00394
00395
00396
00397
00398
00399 template<class View>
00400 forceinline bool
00401 operator ==(const CachedView<View>& x, const CachedView<View>& y) {
00402 return (x.base() == y.base()) && (x.offset() == y.offset());
00403 }
00404 template<class View>
00405 forceinline bool
00406 operator !=(const CachedView<View>& x, const CachedView<View>& y) {
00407 return !(x == y);
00408 }
00409
00410 }}
00411
00412
00413