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 #include <sstream>
00039
00040 namespace Gecode { namespace Set {
00041
00042 template<class View>
00043 forceinline
00044 ComplementView<View>::ComplementView(void) {}
00045
00046 template<class View>
00047 forceinline
00048 ComplementView<View>::ComplementView(View& y)
00049 : DerivedView<View>(y) {}
00050
00051 template<class View>
00052 forceinline ModEvent
00053 ComplementView<View>::me_negateset(ModEvent me) {
00054 switch(me) {
00055 case ME_SET_LUB : return ME_SET_GLB;
00056 case ME_SET_GLB : return ME_SET_LUB;
00057 case ME_SET_CLUB : return ME_SET_CGLB;
00058 case ME_SET_CGLB : return ME_SET_CLUB;
00059 default: return me;
00060 }
00061 }
00062
00063 template<class View>
00064 forceinline PropCond
00065 ComplementView<View>::pc_negateset(PropCond pc) {
00066 switch(pc) {
00067 case PC_SET_CLUB : return PC_SET_CGLB;
00068 case PC_SET_CGLB : return PC_SET_CLUB;
00069 default: return pc;
00070 }
00071 }
00072
00073 template<class View>
00074 forceinline unsigned int
00075 ComplementView<View>::glbSize(void) const {
00076 return Limits::card - x.lubSize();
00077 }
00078
00079 template<class View>
00080 forceinline unsigned int
00081 ComplementView<View>::lubSize(void) const {
00082 return Limits::card - x.glbSize();
00083 }
00084
00085 template<class View>
00086 forceinline unsigned int
00087 ComplementView<View>::unknownSize(void) const {
00088 return lubSize() - glbSize();
00089 }
00090
00091 template<class View>
00092 forceinline bool
00093 ComplementView<View>::contains(int n) const { return x.notContains(n); }
00094
00095 template<class View>
00096 forceinline bool
00097 ComplementView<View>::notContains(int n) const { return x.contains(n); }
00098
00099 template<class View>
00100 forceinline unsigned int
00101 ComplementView<View>::cardMin(void) const {
00102 return Limits::card - x.cardMax();
00103 }
00104
00105 template<class View>
00106 forceinline unsigned int
00107 ComplementView<View>::cardMax(void) const {
00108 return Limits::card - x.cardMin();
00109 }
00110
00111 template<class View>
00112 forceinline int
00113 ComplementView<View>::lubMin(void) const {
00114 GlbRanges<View> lb(x);
00115 RangesCompl<GlbRanges<View> > lbc(lb);
00116 if (lbc()) {
00117 return lbc.min();
00118 } else {
00119 return BndSet::MIN_OF_EMPTY;
00120 }
00121 }
00122
00123 template<class View>
00124 forceinline int
00125 ComplementView<View>::lubMax(void) const {
00126 GlbRanges<View> lb(x);
00127 RangesCompl<GlbRanges<View> > lbc(lb);
00128 if (lbc()) {
00129 while(lbc()) ++lbc;
00130 return lbc.max();
00131 } else {
00132 return BndSet::MAX_OF_EMPTY;
00133 }
00134 }
00135
00136 template<class View>
00137 forceinline int
00138 ComplementView<View>::glbMin(void) const {
00139 LubRanges<View> ub(x);
00140 RangesCompl<LubRanges<View> > ubc(ub);
00141 if (ubc()) {
00142 return ubc.min();
00143 } else {
00144 return BndSet::MIN_OF_EMPTY;
00145 }
00146 }
00147
00148 template<class View>
00149 forceinline int
00150 ComplementView<View>::glbMax(void) const {
00151 LubRanges<View> ub(x);
00152 RangesCompl<LubRanges<View> > ubc(ub);
00153 if (ubc()) {
00154 while (ubc()) ++ubc;
00155 return ubc.max();
00156 } else {
00157 return BndSet::MAX_OF_EMPTY;
00158 }
00159 }
00160
00161 template<class View>
00162 forceinline ModEvent
00163 ComplementView<View>::cardMin(Space& home, unsigned int c) {
00164 if (c < Limits::card)
00165 return me_negateset(x.cardMax(home, Limits::card - c));
00166 return ME_SET_NONE;
00167 }
00168
00169 template<class View>
00170 forceinline ModEvent
00171 ComplementView<View>::cardMax(Space& home, unsigned int c) {
00172 if (c < Limits::card)
00173 return me_negateset(x.cardMin(home, Limits::card - c));
00174 return ME_SET_NONE;
00175 }
00176
00177 template<class View>
00178 forceinline ModEvent
00179 ComplementView<View>::include(Space& home, int c) {
00180 return me_negateset((x.exclude(home, c)));
00181 }
00182
00183 template<class View>
00184 forceinline ModEvent
00185 ComplementView<View>::exclude(Space& home, int c) {
00186 return me_negateset((x.include(home, c)));
00187 }
00188
00189 template<class View>
00190 forceinline ModEvent
00191 ComplementView<View>::intersect(Space& home, int c) {
00192 Iter::Ranges::Singleton si(c,c);
00193 RangesCompl<Iter::Ranges::Singleton> csi(si);
00194 return me_negateset((x.includeI(home, csi)));
00195 }
00196
00197 template<class View>
00198 forceinline ModEvent
00199 ComplementView<View>::intersect(Space& home, int i, int j) {
00200 Iter::Ranges::Singleton si(i,j);
00201 RangesCompl<Iter::Ranges::Singleton> csi(si);
00202 return me_negateset((x.includeI(home, csi)));
00203 }
00204
00205 template<class View>
00206 forceinline ModEvent
00207 ComplementView<View>::include(Space& home, int j, int k) {
00208 return me_negateset(x.exclude(home,j,k));
00209 }
00210
00211 template<class View>
00212 forceinline ModEvent
00213 ComplementView<View>::exclude(Space& home, int j, int k) {
00214 return me_negateset(x.include(home,j,k));
00215 }
00216
00217 template<class View>
00218 template<class I> ModEvent
00219 ComplementView<View>::excludeI(Space& home,I& iter) {
00220 return me_negateset(x.includeI(home,iter));
00221 }
00222
00223 template<class View>
00224 template<class I> ModEvent
00225 ComplementView<View>::includeI(Space& home,I& iter) {
00226 return me_negateset(x.excludeI(home,iter));
00227 }
00228
00229 template<class View>
00230 template<class I> ModEvent
00231 ComplementView<View>::intersectI(Space& home,I& iter) {
00232 RangesCompl<I> c(iter);
00233 return me_negateset(x.includeI(home,c));
00234 }
00235
00236 template<class View>
00237 forceinline void
00238 ComplementView<View>::subscribe(Space& home, Propagator& p, PropCond pc,
00239 bool schedule) {
00240 x.subscribe(home,p, pc_negateset(pc),schedule);
00241 }
00242
00243 template<class View>
00244 forceinline void
00245 ComplementView<View>::cancel(Space& home, Propagator& p, PropCond pc) {
00246 x.cancel(home,p, pc_negateset(pc));
00247 }
00248
00249 template<class View>
00250 forceinline void
00251 ComplementView<View>::subscribe(Space& home, Advisor& a) {
00252 x.subscribe(home,a);
00253 }
00254
00255 template<class View>
00256 forceinline void
00257 ComplementView<View>::cancel(Space& home, Advisor& a) {
00258 x.cancel(home,a);
00259 }
00260
00261 template<class View>
00262 forceinline void
00263 ComplementView<View>::schedule(Space& home, Propagator& p, ModEvent me) {
00264 return View::schedule(home,p,me_negateset(me));
00265 }
00266 template<class View>
00267 forceinline ModEvent
00268 ComplementView<View>::me(const ModEventDelta& med) {
00269 return me_negateset(View::me(med));
00270 }
00271
00272 template<class View>
00273 forceinline ModEventDelta
00274 ComplementView<View>::med(ModEvent me) {
00275 return me_negateset(View::med(me));
00276 }
00277
00278
00279
00280
00281
00282
00283 template<class View>
00284 forceinline ModEvent
00285 ComplementView<View>::modevent(const Delta& d) {
00286 return me_negateset(View::modevent(d));
00287 }
00288
00289 template<class View>
00290 forceinline int
00291 ComplementView<View>::glbMin(const Delta& d) const {
00292 return x.lubMin(d);
00293 }
00294
00295 template<class View>
00296 forceinline int
00297 ComplementView<View>::glbMax(const Delta& d) const {
00298 return x.lubMax(d);
00299 }
00300
00301 template<class View>
00302 forceinline bool
00303 ComplementView<View>::glbAny(const Delta& d) const {
00304 return x.lubAny(d);
00305 }
00306
00307 template<class View>
00308 forceinline int
00309 ComplementView<View>::lubMin(const Delta& d) const {
00310 return x.glbMin(d);
00311 }
00312
00313 template<class View>
00314 forceinline int
00315 ComplementView<View>::lubMax(const Delta& d) const {
00316 return x.glbMax(d);
00317 }
00318
00319 template<class View>
00320 forceinline bool
00321 ComplementView<View>::lubAny(const Delta& d) const {
00322 return x.glbAny(d);
00323 }
00324
00325
00330 template<class View>
00331 class LubRanges<ComplementView<View> > {
00332 private:
00333 GlbRanges<View> lb;
00334 RangesCompl<GlbRanges<View> > lbc;
00335 public:
00337
00338
00339 LubRanges(void) {}
00341 LubRanges(const ComplementView<View>& x);
00343 void init(const ComplementView<View>& x);
00345
00347
00348
00349 bool operator ()(void) const;
00351 void operator ++(void);
00353
00355
00356
00357 int min(void) const;
00359 int max(void) const;
00361 unsigned int width(void) const;
00363 };
00364
00365 template<class View>
00366 forceinline
00367 LubRanges<ComplementView<View> >::LubRanges(const ComplementView<View>& s)
00368 : lb(s.base()), lbc(lb) {}
00369
00370 template<class View>
00371 forceinline void
00372 LubRanges<ComplementView<View> >::init(const ComplementView<View>& s) {
00373 lb.init(s.base());
00374 lbc.init(lb);
00375 }
00376
00377 template<class View>
00378 forceinline bool
00379 LubRanges<ComplementView<View> >::operator ()(void) const { return lbc(); }
00380
00381 template<class View>
00382 forceinline void
00383 LubRanges<ComplementView<View> >::operator ++(void) { return ++lbc; }
00384
00385 template<class View>
00386 forceinline int
00387 LubRanges<ComplementView<View> >::min(void) const { return lbc.min(); }
00388
00389 template<class View>
00390 forceinline int
00391 LubRanges<ComplementView<View> >::max(void) const { return lbc.max(); }
00392
00393 template<class View>
00394 forceinline unsigned int
00395 LubRanges<ComplementView<View> >::width(void) const { return lbc.width(); }
00396
00405 template<class View>
00406 class LubRanges<ComplementView<ComplementView<View> > > :
00407 public LubRanges<View> {
00408 public:
00410
00411
00412 LubRanges(void) {}
00414 LubRanges(const ComplementView<ComplementView<View> >& x);
00416 void init(const ComplementView<ComplementView<View> >& x);
00418 };
00419
00420 template<class View>
00421 forceinline
00422 LubRanges<ComplementView<ComplementView<View> > >::
00423 LubRanges(const ComplementView<ComplementView<View> >& x) :
00424 LubRanges<View>(x) {}
00425
00426 template<class View>
00427 forceinline void
00428 LubRanges<ComplementView<ComplementView<View> > >::
00429 init(const ComplementView<ComplementView<View> >& x) {
00430 LubRanges<View>::init(x);
00431 }
00432
00437 template<class View>
00438 class GlbRanges<ComplementView<View> > {
00439 private:
00440 LubRanges<View> ub;
00441 RangesCompl<LubRanges<View> > ubc;
00442 public:
00444
00445
00446 GlbRanges(void) {}
00448 GlbRanges(const ComplementView<View> & x);
00450 void init(const ComplementView<View> & x);
00452
00454
00455
00456 bool operator ()(void) const;
00458 void operator ++(void);
00460
00462
00463
00464 int min(void) const;
00466 int max(void) const;
00468 unsigned int width(void) const;
00470 };
00471
00472 template<class View>
00473 forceinline
00474 GlbRanges<ComplementView<View> >::GlbRanges(const ComplementView<View> & s)
00475 : ub(s.base()), ubc(ub) {}
00476
00477 template<class View>
00478 forceinline void
00479 GlbRanges<ComplementView<View> >::init(const ComplementView<View> & s) {
00480 ub.init(s.base());
00481 ubc.init(ub);
00482 }
00483
00484 template<class View>
00485 forceinline bool
00486 GlbRanges<ComplementView<View> >::operator ()(void) const { return ubc(); }
00487
00488 template<class View>
00489 forceinline void
00490 GlbRanges<ComplementView<View> >::operator ++(void) { return ++ubc; }
00491
00492 template<class View>
00493 forceinline int
00494 GlbRanges<ComplementView<View> >::min(void) const { return ubc.min(); }
00495
00496 template<class View>
00497 forceinline int
00498 GlbRanges<ComplementView<View> >::max(void) const { return ubc.max(); }
00499
00500 template<class View>
00501 forceinline unsigned int
00502 GlbRanges<ComplementView<View> >::width(void) const { return ubc.width(); }
00503
00512 template<class View>
00513 class GlbRanges<ComplementView<ComplementView<View> > > :
00514 public GlbRanges<View> {
00515 public:
00517
00518
00519 GlbRanges(void) {}
00521 GlbRanges(const ComplementView<ComplementView<View> >& x);
00523 void init(const ComplementView<ComplementView<View> >& x);
00525 };
00526
00527 template<class View>
00528 forceinline
00529 GlbRanges<ComplementView<ComplementView<View> > >::
00530 GlbRanges(const ComplementView<ComplementView<View> >& x) :
00531 GlbRanges<View>(x) {}
00532
00533 template<class View>
00534 forceinline void
00535 GlbRanges<ComplementView<ComplementView<View> > >::
00536 init(const ComplementView<ComplementView<View> >& x) {
00537 GlbRanges<View>::init(x);
00538 }
00539
00540 template<class Char, class Traits, class View>
00541 std::basic_ostream<Char,Traits>&
00542 operator <<(std::basic_ostream<Char,Traits>& os,
00543 const ComplementView<View>& x) {
00544 std::basic_ostringstream<Char,Traits> s;
00545 s.copyfmt(os); s.width(0);
00546 s << "(" << x.base() << ")^C";
00547 return os << s.str();
00548 }
00549
00550
00551 template<class View>
00552 forceinline bool
00553 operator ==(const ComplementView<View>& x, const ComplementView<View>& y) {
00554 return x.base() == y.base();
00555 }
00556
00557 template<class View>
00558 forceinline bool
00559 operator !=(const ComplementView<View>& x, const ComplementView<View>& y) {
00560 return x.base() != y.base();
00561 }
00562
00563 }}
00564
00565