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 namespace Gecode { namespace Int { namespace GCC {
00038
00043 class OccurBndsView {
00044 private:
00045 int _min;
00046 int _max;
00047 int c;
00048 int count;
00049 public:
00050 OccurBndsView(void);
00051 int min(void) const;
00052 int max(void) const;
00053 int card(void) const;
00054 int counter(void) const;
00055
00056 void min(int);
00057 void max(int);
00058 void card(int c);
00059 void counter(int c);
00060
00061 void init(Space& home, int min, int max, int c);
00062 ModEvent lq(Space& home, int n);
00063 ModEvent gq(Space& home, int n);
00064 ModEvent eq(Space& home, int n);
00065 bool assigned(void) const;
00066 bool range(void) const;
00067 ModEvent inc(void);
00068
00069 void cancel(Space&, Propagator& , PropCond ) {}
00070 void subscribe(Space&, Propagator& , PropCond, bool=true) {}
00071
00072 void cancel(Space&, Advisor&) {}
00073 void subscribe(Space&, Advisor&) {}
00074
00075 void update(Space&, bool, OccurBndsView&);
00076 };
00077
00078 forceinline
00079 OccurBndsView::OccurBndsView(void) {}
00080
00081 forceinline int
00082 OccurBndsView::min(void) const {
00083 return _min;
00084 }
00085
00086 forceinline int
00087 OccurBndsView::max(void) const {
00088 return _max;
00089 }
00090
00091 forceinline int
00092 OccurBndsView::card(void) const {
00093 return c;
00094 }
00095
00096 forceinline int
00097 OccurBndsView::counter(void) const {
00098 return count;
00099 }
00100
00101 forceinline void
00102 OccurBndsView::min(int m) {
00103 _min = m;
00104 }
00105
00106 forceinline void
00107 OccurBndsView::max(int m) {
00108 _max = m;
00109 }
00110
00111 forceinline void
00112 OccurBndsView::card(int ca) {
00113 c = ca;
00114 }
00115
00116 forceinline void
00117 OccurBndsView::counter(int count0) {
00118 count = count0;
00119 }
00120
00121 forceinline void
00122 OccurBndsView::init(Space&, int min, int max, int val) {
00123 _min = min; _max=max;
00124 c = val;
00125 count = 0;
00126 }
00127
00128 forceinline ModEvent
00129 OccurBndsView::inc(void) {
00130 count++;
00131 if (count > _max) {
00132 return ME_GEN_FAILED;
00133 } else {
00134 return ME_GEN_NONE;
00135 }
00136 }
00137
00138 forceinline bool
00139 OccurBndsView::assigned(void) const {
00140 return _min==_max;
00141 }
00142
00143 forceinline bool
00144 OccurBndsView::range(void) const {
00145 return true;
00146 }
00147
00148
00149 forceinline ModEvent
00150 OccurBndsView::lq(Space&, int i){
00151
00152 if (_min > i) {
00153 return ME_GEN_FAILED;
00154 } else {
00155 return ME_GEN_NONE;
00156 }
00157 }
00158
00159 forceinline ModEvent
00160 OccurBndsView::gq(Space&, int i){
00161
00162 if (_max < i) {
00163 return ME_GEN_FAILED;
00164 }
00165 return ME_GEN_NONE;
00166 }
00167
00168 forceinline ModEvent
00169 OccurBndsView::eq(Space&, int i){
00170 if (_min > i || _max < i) {
00171 return ME_GEN_FAILED;
00172 } else {
00173 return ME_GEN_NONE;
00174 }
00175 }
00176
00177 forceinline void
00178 OccurBndsView::update(Space&, bool, OccurBndsView& oc) {
00179 _min = oc._min;
00180 _max = oc._max;
00181 c = oc.c;
00182 count = oc.count;
00183 }
00184
00185
00191 template <class T>
00192 forceinline int
00193 lookupValue(T& a, int v){
00194 int idx = -1;
00195
00196 int l = 0;
00197 int r = a.size() - 1;
00198
00199 if (r == 0) {
00200 if (a[0].card() == v) {
00201 return 0;
00202 } else {
00203 return -1;
00204 }
00205 }
00206
00207 while ( l < r ) {
00208 if ( a[l].card() == v) {
00209 idx = l;
00210 break;
00211 }
00212 if ( a[r].card() == v) {
00213 idx = r;
00214 break;
00215 }
00216 int p = (l + r) / 2;
00217 if ( v == a[p].card()) {
00218 idx = p;
00219 break;
00220 } else {
00221 if ( v < a[p].card()) {
00222 r = p;
00223 } else {
00224 l = p;
00225 }
00226 }
00227 if (l == r - 1) {
00228 break;
00229 }
00230 }
00231
00232 return idx;
00233 }
00234
00235
00240 class CardView : public DerivedViewBase<IntView> {
00241 protected:
00243 int c;
00245 int count;
00246 using DerivedViewBase<IntView>::view;
00247 public:
00248 CardView(void);
00250 CardView(const IntView& x, int c);
00252 void init(const IntView& x, int c);
00253 void init(Space& home, int mi, int ma , int c);
00254
00256 int card(void) const;
00257 void card(int ca);
00258
00260 ModEvent inc(void);
00262 void counter(int);
00264 int counter(void);
00265
00267
00268
00269 void operator =(const IntView& x);
00271 void operator =(const Gecode::Int::GCC::CardView& x);
00273 int min(void) const;
00275 int max(void) const;
00277 int med(void) const;
00279 int val(void) const;
00281 IntView intview(void);
00283 unsigned int size(void) const;
00285 unsigned int width(void) const;
00287 unsigned int regret_min(void) const;
00289 unsigned int regret_max(void) const;
00291
00295 bool range(void) const;
00297 bool assigned(void) const;
00298
00300 bool in(int n) const;
00302 bool in(double n) const;
00304
00308 ModEvent lq(Space& home, int n);
00310 ModEvent lq(Space& home, double n);
00312 ModEvent le(Space& home, int n);
00314 ModEvent le(Space& home, double n);
00316 ModEvent gq(Space& home, int n);
00318 ModEvent gq(Space& home, double n);
00320 ModEvent gr(Space& home, int n);
00322 ModEvent gr(Space& home, double n);
00324 ModEvent nq(Space& home, int n);
00326 ModEvent nq(Space& home, double n);
00328 ModEvent eq(Space& home, int n);
00330 ModEvent eq(Space& home, double n);
00332
00348
00349 template <class I>
00350 ModEvent narrow_r(Space& home, I& i, bool depends=true);
00352 template <class I>
00353 ModEvent inter_r(Space& home, I& i, bool depends=true);
00355 template <class I>
00356 ModEvent minus_r(Space& home, I& i, bool depends=true);
00358 template <class I>
00359 ModEvent narrow_v(Space& home, I& i, bool depends=true);
00361 template <class I>
00362 ModEvent inter_v(Space& home, I& i, bool depends=true);
00364 template <class I>
00365 ModEvent minus_v(Space& home, I& i, bool depends=true);
00367
00371 static void schedule(Space& home, Propagator& p, ModEvent me);
00373 static ModEvent me(const ModEventDelta& med);
00375 static ModEventDelta med(ModEvent me);
00377
00381 void subscribe(Space& home, Propagator& p, PropCond pc, bool process=true);
00383 void cancel(Space& home, Propagator& p, PropCond pc);
00385 void subscribe(Space& home, Advisor& a);
00387 void cancel(Space& home, Advisor& a);
00388
00390
00394 void update(Space& home, bool share, CardView& x);
00396
00400 bool operator ==(const CardView& x) const;
00402 bool operator !=(const CardView& x) const;
00404 bool operator < (const CardView& x) const;
00406 bool operator > (const CardView& x) const;
00408 };
00409
00410
00411
00412
00413
00414 forceinline
00415 CardView::CardView(void) {}
00416
00417 forceinline
00418 CardView::CardView(const IntView& x, int d)
00419 : DerivedViewBase<IntView>(x), c(d), count(0) {}
00420
00421 forceinline void
00422 CardView::init(const IntView& x, int d) {
00423 view = x;
00424 c = d;
00425 count = 0;
00426 }
00427
00428
00429 forceinline void
00430 CardView::init(Space& home, int mi, int ma, int d) {
00431 IntVar ivar(home, mi, ma);
00432 IntView iview(ivar);
00433 view = iview;
00434 c = d;
00435 count = 0;
00436 }
00437
00438 forceinline void
00439 CardView::card(int ca) {
00440 c = ca;
00441 }
00442
00443 forceinline int
00444 CardView::card(void) const {
00445 return c;
00446 }
00447
00448 forceinline ModEvent
00449 CardView::inc(void) {
00450 count++;
00451 if (count > this->max()) {
00452 return ME_GEN_FAILED;
00453 } else {
00454 return ME_GEN_NONE;
00455 }
00456 }
00457
00458 forceinline void
00459 CardView::counter(int c) {
00460 count = c;
00461 }
00462
00463 forceinline int
00464 CardView::counter(void) {
00465 return count;
00466 }
00467
00468
00469
00470
00471
00472
00473 forceinline void
00474 CardView::operator =(const IntView& x) {
00475 view = x;
00476 c = 0;
00477 count = 0;
00478 }
00479
00480 forceinline void
00481 CardView::operator =(const CardView& x) {
00482 view = x.view;
00483 c = x.c;
00484 count = x.count;
00485 }
00486
00487
00488 forceinline int
00489 CardView::min(void) const {
00490 return view.min();
00491 }
00492 forceinline int
00493 CardView::max(void) const {
00494 return view.max();
00495 }
00496 forceinline int
00497 CardView::med(void) const {
00498 return view.med();
00499 }
00500
00501 forceinline int
00502 CardView::val(void) const {
00503 return view.val();
00504 }
00505
00506 forceinline IntView
00507 CardView::intview(void){
00508 return view;
00509 }
00510
00511
00512 forceinline unsigned int
00513 CardView::width(void) const {
00514 return view.width();
00515 }
00516 forceinline unsigned int
00517 CardView::size(void) const {
00518 return view.size();
00519 }
00520 forceinline unsigned int
00521 CardView::regret_min(void) const {
00522 return view.regret_min();
00523 }
00524 forceinline unsigned int
00525 CardView::regret_max(void) const {
00526 return view.regret_max();
00527 }
00528
00529
00530
00531
00532
00533 forceinline bool
00534 CardView::range(void) const {
00535 return view.range();
00536 }
00537 forceinline bool
00538 CardView::assigned(void) const {
00539 return view.assigned();
00540 }
00541
00542 forceinline bool
00543 CardView::in(int n) const {
00544 return view.in(n);
00545 }
00546 forceinline bool
00547 CardView::in(double n) const {
00548 return view.in(n);
00549 }
00550
00551
00552
00553
00554
00555
00556 forceinline ModEvent
00557 CardView::lq(Space& home, int n) {
00558 return view.lq(home,n);
00559 }
00560 forceinline ModEvent
00561 CardView::lq(Space& home, double n) {
00562 return view.lq(home,n);
00563 }
00564 forceinline ModEvent
00565 CardView::le(Space& home, int n) {
00566 return view.le(home,n);
00567 }
00568 forceinline ModEvent
00569 CardView::le(Space& home, double n) {
00570 return view.le(home,n);
00571 }
00572 forceinline ModEvent
00573 CardView::gq(Space& home, int n) {
00574 return view.gq(home,n);
00575 }
00576 forceinline ModEvent
00577 CardView::gq(Space& home, double n) {
00578 return view.gq(home,n);
00579 }
00580 forceinline ModEvent
00581 CardView::gr(Space& home, int n) {
00582 return view.gr(home,n);
00583 }
00584 forceinline ModEvent
00585 CardView::gr(Space& home, double n) {
00586 return view.gr(home,n);
00587 }
00588 forceinline ModEvent
00589 CardView::nq(Space& home, int n) {
00590 return view.nq(home,n);
00591 }
00592 forceinline ModEvent
00593 CardView::nq(Space& home, double n) {
00594 return view.nq(home,n);
00595 }
00596 forceinline ModEvent
00597 CardView::eq(Space& home, int n) {
00598 return view.eq(home,n);
00599 }
00600 forceinline ModEvent
00601 CardView::eq(Space& home, double n) {
00602 return view.eq(home,n);
00603 }
00604
00605
00606
00607
00608
00609
00610 template <class I>
00611 ModEvent
00612 CardView::narrow_r(Space& home, I& i, bool depends) {
00613 return view.narrow_r(home,i,depends);
00614 }
00615 template <class I>
00616 ModEvent
00617 CardView::inter_r(Space& home, I& i, bool depends) {
00618 return view.inter_r(home,i,depends);
00619 }
00620 template <class I>
00621 ModEvent
00622 CardView::minus_r(Space& home, I& i, bool depends) {
00623 return view.minus_r(home,i,depends);
00624 }
00625 template <class I>
00626 ModEvent
00627 CardView::narrow_v(Space& home, I& i, bool depends) {
00628 return view.narrow_v(home,i,depends);
00629 }
00630 template <class I>
00631 ModEvent
00632 CardView::inter_v(Space& home, I& i, bool depends) {
00633 return view.inter_v(home,i,depends);
00634 }
00635 template <class I>
00636 ModEvent
00637 CardView::minus_v(Space& home, I& i, bool depends) {
00638 return view.minus_v(home,i,depends);
00639 }
00640
00641
00642
00643
00644
00645
00646
00647 forceinline void
00648 CardView::schedule(Space& home, Propagator& p, ModEvent me) {
00649 return IntView::schedule(home,p,me);
00650 }
00651 forceinline ModEvent
00652 CardView::me(const ModEventDelta& med) {
00653 return IntView::me(med);
00654 }
00655 forceinline ModEventDelta
00656 CardView::med(ModEvent me) {
00657 return IntView::med(me);
00658 }
00659
00660
00661
00662
00663
00664
00665 forceinline void
00666 CardView::subscribe(Space& home, Propagator& p, PropCond pc, bool process) {
00667 view.subscribe(home, p, pc, process);
00668 }
00669 forceinline void
00670 CardView::cancel(Space& home, Propagator& p, PropCond pc) {
00671 view.cancel(home,p, pc);
00672 }
00673 forceinline void
00674 CardView::subscribe(Space& home, Advisor& a) {
00675 view.subscribe(home, a);
00676 }
00677 forceinline void
00678 CardView::cancel(Space& home, Advisor& a) {
00679 view.cancel(home, a);
00680 }
00681
00682
00683
00684
00685
00686
00687 forceinline void
00688 CardView::update(Space& home, bool share, CardView& x) {
00689 c = x.c;
00690 count = x.count;
00691 view.update(home,share,x.view);
00692 }
00693
00694 }
00695
00696
00700 template <>
00701 class ViewRanges<GCC::CardView>
00702 : public Gecode::Int::ViewRanges<IntView> {
00703 public:
00707 ViewRanges(void);
00709 ViewRanges(const GCC::CardView& x);
00711 void init(const GCC::CardView& x);
00713 };
00714
00715 forceinline
00716 ViewRanges<GCC::CardView>::ViewRanges(void) :
00717 Gecode::Int::ViewRanges<IntView>() {}
00718
00719 forceinline
00720 ViewRanges<GCC::CardView>::ViewRanges (const GCC::CardView& x)
00721 : Gecode::Int::ViewRanges<IntView>(x.base()) {}
00722
00723 forceinline void
00724 ViewRanges<GCC::CardView>::init(const GCC::CardView& x) {
00725 Gecode::Int::ViewRanges<IntView> xi(x.base());
00726 }
00727
00728 }}
00729
00730
00731
00732