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 {
00042 class OccurBndsView {
00043 private:
00044 int _min;
00045 int _max;
00046 int c;
00047 int count;
00048 public:
00049 OccurBndsView(void);
00050 int min(void) const;
00051 int max(void) const;
00052 int card(void) const;
00053 int counter(void) const;
00054
00055 void min(int);
00056 void max(int);
00057 void card(int c);
00058 void counter(int c);
00059
00060 void init(Space* home, int min, int max, int c);
00061 ModEvent lq(Space* home, int n);
00062 ModEvent gq(Space* home, int n);
00063 ModEvent eq(Space* home, int n);
00064 bool assigned(void) const;
00065 bool range(void) const;
00066 ModEvent inc(void);
00067
00068 void cancel(Space*, Propagator* , PropCond ) {}
00069 void subscribe(Space*, Propagator* , PropCond, bool=true) {}
00070
00071 void cancel(Space*, Advisor*) {}
00072 void subscribe(Space*, Advisor*) {}
00073
00074 void update(Space*, bool, OccurBndsView&);
00075
00076 Reflection::Arg* spec(const Space* home, Reflection::VarMap& m) const;
00077 OccurBndsView(Space* home, const Reflection::VarMap& m,
00078 Reflection::Arg* arg);
00079 static Support::Symbol type(void);
00080
00081 };
00082
00083 forceinline
00084 OccurBndsView::OccurBndsView(void) {}
00085
00086 forceinline int
00087 OccurBndsView::min(void) const {
00088 return _min;
00089 }
00090
00091 forceinline int
00092 OccurBndsView::max(void) const {
00093 return _max;
00094 }
00095
00096 forceinline int
00097 OccurBndsView::card(void) const {
00098 return c;
00099 }
00100
00101 forceinline int
00102 OccurBndsView::counter(void) const {
00103 return count;
00104 }
00105
00106 forceinline void
00107 OccurBndsView::min(int m) {
00108 _min = m;
00109 }
00110
00111 forceinline void
00112 OccurBndsView::max(int m) {
00113 _max = m;
00114 }
00115
00116 forceinline void
00117 OccurBndsView::card(int ca) {
00118 c = ca;
00119 }
00120
00121 forceinline void
00122 OccurBndsView::counter(int count0) {
00123 count = count0;
00124 }
00125
00126 forceinline void
00127 OccurBndsView::init(Space*, int min, int max, int val) {
00128 _min = min; _max=max;
00129 c = val;
00130 count = 0;
00131 }
00132
00133 forceinline ModEvent
00134 OccurBndsView::inc(void) {
00135 count++;
00136 if (count > _max) {
00137 return ME_GEN_FAILED;
00138 } else {
00139 return ME_GEN_NONE;
00140 }
00141 }
00142
00143 forceinline bool
00144 OccurBndsView::assigned(void) const {
00145 return _min==_max;
00146 }
00147
00148 forceinline bool
00149 OccurBndsView::range(void) const {
00150 return true;
00151 }
00152
00153
00154 forceinline ModEvent
00155 OccurBndsView::lq(Space*, int i){
00156
00157 if (_min > i) {
00158 return ME_GEN_FAILED;
00159 } else {
00160 return ME_GEN_NONE;
00161 }
00162 }
00163
00164 forceinline ModEvent
00165 OccurBndsView::gq(Space*, int i){
00166
00167 if (_max < i) {
00168 return ME_GEN_FAILED;
00169 }
00170 return ME_GEN_NONE;
00171 }
00172
00173 forceinline ModEvent
00174 OccurBndsView::eq(Space*, int i){
00175 if (_min > i || _max < i) {
00176 return ME_GEN_FAILED;
00177 } else {
00178 return ME_GEN_NONE;
00179 }
00180 }
00181
00182 }}}
00183
00185 inline std::ostream&
00186 operator<<(std::ostream& os, Gecode::Int::GCC::OccurBndsView& xs) {
00187 os << xs.card() << "("<< xs.counter() <<")[";
00188 os << xs.min() << "," << xs.max() << "]";
00189 return os;
00190 }
00191
00192 namespace Gecode { namespace Int { namespace GCC {
00193
00194 forceinline void
00195 OccurBndsView::update(Space*, bool, OccurBndsView& oc) {
00196 _min = oc._min;
00197 _max = oc._max;
00198 c = oc.c;
00199 count = oc.count;
00200 }
00201
00202 forceinline Reflection::Arg*
00203 OccurBndsView::spec(const Space*, Reflection::VarMap&) const {
00204 return Reflection::Arg::newPair(
00205 Reflection::Arg::newPair(Reflection::Arg::newInt(_min),
00206 Reflection::Arg::newInt(_max)),
00207 Reflection::Arg::newPair(Reflection::Arg::newInt(c),
00208 Reflection::Arg::newInt(count)));
00209 }
00210 inline Support::Symbol
00211 OccurBndsView::type(void) {
00212 return Support::Symbol("Gecode::Int::GCC::OccurBndsView");
00213 }
00214
00215 forceinline
00216 OccurBndsView::OccurBndsView(Space*, const Reflection::VarMap&,
00217 Reflection::Arg* arg) {
00218 _min = arg->first()->first()->toInt();
00219 _max = arg->first()->second()->toInt();
00220 c = arg->second()->first()->toInt();
00221 count = arg->second()->second()->toInt();
00222 }
00223
00229 template <class T>
00230 forceinline int
00231 lookupValue(T& a, int v){
00232 int idx = -1;
00233
00234 int l = 0;
00235 int r = a.size() - 1;
00236
00237 if (r == 0) {
00238 if (a[0].card() == v) {
00239 return 0;
00240 } else {
00241 return -1;
00242 }
00243 }
00244
00245 while ( l < r ) {
00246 if ( a[l].card() == v) {
00247 idx = l;
00248 break;
00249 }
00250 if ( a[r].card() == v) {
00251 idx = r;
00252 break;
00253 }
00254 int p = (l + r) / 2;
00255 if ( v == a[p].card()) {
00256 idx = p;
00257 break;
00258 } else {
00259 if ( v < a[p].card()) {
00260 r = p;
00261 } else {
00262 l = p;
00263 }
00264 }
00265 if (l == r - 1) {
00266 break;
00267 }
00268 }
00269
00270 return idx;
00271 }
00272
00273
00278 class CardView : public DerivedViewBase<IntView> {
00279 protected:
00281 int c;
00283 int count;
00284 using DerivedViewBase<IntView>::view;
00285 public:
00286 CardView(void);
00288 CardView(const IntView& x, int c);
00290 void init(const IntView& x, int c);
00291 void init(Space* home, int mi, int ma , int c);
00292
00294 int card(void) const;
00295 void card(int ca);
00296
00298 ModEvent inc(void);
00300 void counter(int);
00302 int counter(void);
00303
00305
00306 void operator=(const IntView& x);
00307 void operator=(const Gecode::Int::GCC::CardView& x);
00309 int min(void) const;
00311 int max(void) const;
00313 int med(void) const;
00315 int val(void) const;
00317 IntView intview(void);
00319 unsigned int size(void) const;
00321 unsigned int width(void) const;
00323 unsigned int regret_min(void) const;
00325 unsigned int regret_max(void) const;
00327
00331 bool range(void) const;
00333 bool assigned(void) const;
00334
00336 bool in(int n) const;
00338 bool in(double n) const;
00340
00344 ModEvent lq(Space* home, int n);
00346 ModEvent lq(Space* home, double n);
00348 ModEvent le(Space* home, int n);
00350 ModEvent le(Space* home, double n);
00352 ModEvent gq(Space* home, int n);
00354 ModEvent gq(Space* home, double n);
00356 ModEvent gr(Space* home, int n);
00358 ModEvent gr(Space* home, double n);
00360 ModEvent nq(Space* home, int n);
00362 ModEvent nq(Space* home, double n);
00364 ModEvent eq(Space* home, int n);
00366 ModEvent eq(Space* home, double n);
00368
00384
00385 template <class I>
00386 ModEvent narrow_r(Space* home, I& i, bool depends=true);
00388 template <class I>
00389 ModEvent inter_r(Space* home, I& i, bool depends=true);
00391 template <class I>
00392 ModEvent minus_r(Space* home, I& i, bool depends=true);
00394 template <class I>
00395 ModEvent narrow_v(Space* home, I& i, bool depends=true);
00397 template <class I>
00398 ModEvent inter_v(Space* home, I& i, bool depends=true);
00400 template <class I>
00401 ModEvent minus_v(Space* home, I& i, bool depends=true);
00403
00407 static void schedule(Space* home, Propagator* p, ModEvent me);
00409 static ModEvent me(ModEventDelta med);
00411 static ModEventDelta med(ModEvent me);
00413
00417 void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00419 void cancel(Space* home, Propagator* p, PropCond pc);
00421 void subscribe(Space* home, Advisor* a);
00423 void cancel(Space* home, Advisor* a);
00424
00426
00430 void update(Space* home, bool share, CardView& x);
00432
00436 Reflection::Arg* spec(const Space* home, Reflection::VarMap& m) const;
00438 static Support::Symbol type(void);
00440 CardView(Space* home, const Reflection::VarMap& m,
00441 Reflection::Arg* arg);
00443
00447 bool operator ==(const CardView& x) const;
00449 bool operator !=(const CardView& x) const;
00451 bool operator < (const CardView& x) const;
00453 bool operator > (const CardView& x) const;
00455 };
00456
00457
00458
00459
00460
00461 forceinline
00462 CardView::CardView(void) {}
00463
00464 forceinline
00465 CardView::CardView(const IntView& x, int d)
00466 : DerivedViewBase<IntView>(x), c(d), count(0) {}
00467
00468 forceinline void
00469 CardView::init(const IntView& x, int d) {
00470 view = x;
00471 c = d;
00472 count = 0;
00473 }
00474
00475
00476 forceinline void
00477 CardView::init(Space* home, int mi, int ma, int d) {
00478 IntVar ivar(home, mi, ma);
00479 IntView iview(ivar);
00480 view = iview;
00481 c = d;
00482 count = 0;
00483 }
00484
00485 forceinline void
00486 CardView::card(int ca) {
00487 c = ca;
00488 }
00489
00490 forceinline int
00491 CardView::card(void) const {
00492 return c;
00493 }
00494
00495 forceinline ModEvent
00496 CardView::inc(void) {
00497 count++;
00498 if (count > this->max()) {
00499 return ME_GEN_FAILED;
00500 } else {
00501 return ME_GEN_NONE;
00502 }
00503 }
00504
00505 forceinline void
00506 CardView::counter(int c) {
00507 count = c;
00508 }
00509
00510 forceinline int
00511 CardView::counter(void) {
00512 return count;
00513 }
00514
00515
00516
00517
00518
00519
00520 forceinline void
00521 CardView::operator=(const IntView& x) {
00522 view = x;
00523 c = 0;
00524 count = 0;
00525 }
00526
00527 forceinline void
00528 CardView::operator=(const CardView& x) {
00529 view = x.view;
00530 c = x.c;
00531 count = x.count;
00532 }
00533
00534
00535 forceinline int
00536 CardView::min(void) const {
00537 return view.min();
00538 }
00539 forceinline int
00540 CardView::max(void) const {
00541 return view.max();
00542 }
00543 forceinline int
00544 CardView::med(void) const {
00545 return view.med();
00546 }
00547
00548 forceinline int
00549 CardView::val(void) const {
00550 return view.val();
00551 }
00552
00553 forceinline IntView
00554 CardView::intview(void){
00555 return view;
00556 }
00557
00558
00559 forceinline unsigned int
00560 CardView::width(void) const {
00561 return view.width();
00562 }
00563 forceinline unsigned int
00564 CardView::size(void) const {
00565 return view.size();
00566 }
00567 forceinline unsigned int
00568 CardView::regret_min(void) const {
00569 return view.regret_min();
00570 }
00571 forceinline unsigned int
00572 CardView::regret_max(void) const {
00573 return view.regret_max();
00574 }
00575
00576
00577
00578
00579
00580 forceinline bool
00581 CardView::range(void) const {
00582 return view.range();
00583 }
00584 forceinline bool
00585 CardView::assigned(void) const {
00586 return view.assigned();
00587 }
00588
00589 forceinline bool
00590 CardView::in(int n) const {
00591 return view.in(n);
00592 }
00593 forceinline bool
00594 CardView::in(double n) const {
00595 return view.in(n);
00596 }
00597
00598
00599
00600
00601
00602
00603 forceinline ModEvent
00604 CardView::lq(Space* home, int n) {
00605 return view.lq(home,n);
00606 }
00607 forceinline ModEvent
00608 CardView::lq(Space* home, double n) {
00609 return view.lq(home,n);
00610 }
00611 forceinline ModEvent
00612 CardView::le(Space* home, int n) {
00613 return view.le(home,n);
00614 }
00615 forceinline ModEvent
00616 CardView::le(Space* home, double n) {
00617 return view.le(home,n);
00618 }
00619 forceinline ModEvent
00620 CardView::gq(Space* home, int n) {
00621 return view.gq(home,n);
00622 }
00623 forceinline ModEvent
00624 CardView::gq(Space* home, double n) {
00625 return view.gq(home,n);
00626 }
00627 forceinline ModEvent
00628 CardView::gr(Space* home, int n) {
00629 return view.gr(home,n);
00630 }
00631 forceinline ModEvent
00632 CardView::gr(Space* home, double n) {
00633 return view.gr(home,n);
00634 }
00635 forceinline ModEvent
00636 CardView::nq(Space* home, int n) {
00637 return view.nq(home,n);
00638 }
00639 forceinline ModEvent
00640 CardView::nq(Space* home, double n) {
00641 return view.nq(home,n);
00642 }
00643 forceinline ModEvent
00644 CardView::eq(Space* home, int n) {
00645 return view.eq(home,n);
00646 }
00647 forceinline ModEvent
00648 CardView::eq(Space* home, double n) {
00649 return view.eq(home,n);
00650 }
00651
00652
00653
00654
00655
00656
00657 template <class I>
00658 ModEvent
00659 CardView::narrow_r(Space* home, I& i, bool depends) {
00660 return view.narrow_r(home,i,depends);
00661 }
00662 template <class I>
00663 ModEvent
00664 CardView::inter_r(Space* home, I& i, bool depends) {
00665 return view.inter_r(home,i,depends);
00666 }
00667 template <class I>
00668 ModEvent
00669 CardView::minus_r(Space* home, I& i, bool depends) {
00670 return view.minus_r(home,i,depends);
00671 }
00672 template <class I>
00673 ModEvent
00674 CardView::narrow_v(Space* home, I& i, bool depends) {
00675 return view.narrow_v(home,i,depends);
00676 }
00677 template <class I>
00678 ModEvent
00679 CardView::inter_v(Space* home, I& i, bool depends) {
00680 return view.inter_v(home,i,depends);
00681 }
00682 template <class I>
00683 ModEvent
00684 CardView::minus_v(Space* home, I& i, bool depends) {
00685 return view.minus_v(home,i,depends);
00686 }
00687
00688
00689
00690
00691
00692
00693
00694 forceinline void
00695 CardView::schedule(Space* home, Propagator* p, ModEvent me) {
00696 return IntView::schedule(home,p,me);
00697 }
00698 forceinline ModEvent
00699 CardView::me(ModEventDelta med) {
00700 return IntView::me(med);
00701 }
00702 forceinline ModEventDelta
00703 CardView::med(ModEvent me) {
00704 return IntView::med(me);
00705 }
00706
00707
00708
00709
00710
00711
00712 forceinline void
00713 CardView::subscribe(Space* home, Propagator* p, PropCond pc, bool process) {
00714 view.subscribe(home, p, pc, process);
00715 }
00716 forceinline void
00717 CardView::cancel(Space* home, Propagator* p, PropCond pc) {
00718 view.cancel(home,p, pc);
00719 }
00720 forceinline void
00721 CardView::subscribe(Space* home, Advisor* a) {
00722 view.subscribe(home, a);
00723 }
00724 forceinline void
00725 CardView::cancel(Space* home, Advisor* a) {
00726 view.cancel(home, a);
00727 }
00728
00729
00730
00731
00732
00733
00734 forceinline void
00735 CardView::update(Space* home, bool share, CardView& x) {
00736 c = x.c;
00737 count = x.count;
00738 view.update(home,share,x.view);
00739 }
00740
00741
00742
00743
00744
00745 forceinline Reflection::Arg*
00746 CardView::spec(const Space* home, Reflection::VarMap& m) const {
00747 return Reflection::Arg::newPair(
00748 Reflection::Arg::newPair(Reflection::Arg::newInt(c),
00749 Reflection::Arg::newInt(count)), view.spec(home, m));
00750 }
00751 inline Support::Symbol
00752 CardView::type(void) {
00753 return Support::Symbol("Gecode::Int::GCC::CardView");
00754 }
00755 forceinline
00756 CardView::CardView(Space* home, const Reflection::VarMap& m,
00757 Reflection::Arg* arg)
00758 : DerivedViewBase<IntView>(IntView(home, m, arg->second())) {
00759 c = arg->first()->first()->toInt();
00760 count = arg->first()->second()->toInt();
00761 }
00762
00763
00764 }
00765
00766
00770 template <>
00771 class ViewRanges<GCC::CardView>
00772 : public Gecode::Int::ViewRanges<IntView> {
00773 public:
00777 ViewRanges(void);
00779 ViewRanges(const GCC::CardView& x);
00781 void init(const GCC::CardView& x);
00783 };
00784
00785 }}
00786
00788 inline std::ostream&
00789 operator<<(std::ostream& os, Gecode::Int::GCC::CardView& v) {
00790 os << "("<<v.card() << ","<< v.counter() <<",";
00791 if (v.min() == v.max()) {
00792 os << v.min() <<" ";
00793 } else {
00794 if (v.range()){
00795 os << "["<<v.min() <<".."<<v.max()<<"] ";
00796 } else {
00797 os << "{";
00798 Gecode::Int::ViewValues<Gecode::Int::GCC::CardView> iter(v);
00799 while(iter()){
00800 os << iter.val() <<",";
00801 ++iter;
00802 }
00803 os << "}";
00804 }
00805 }
00806 os << ")";
00807 return os;
00808 }
00809
00810 namespace Gecode { namespace Int {
00811
00812 forceinline
00813 ViewRanges<GCC::CardView>::ViewRanges(void) :
00814 Gecode::Int::ViewRanges<IntView>() {}
00815
00816 forceinline
00817 ViewRanges<GCC::CardView>::ViewRanges (const GCC::CardView& x)
00818 : Gecode::Int::ViewRanges<IntView>(x.base()) {}
00819
00820 forceinline void
00821 ViewRanges<GCC::CardView>::init(const GCC::CardView& x) {
00822 Gecode::Int::ViewRanges<IntView> xi(x.base());
00823 }
00824
00825 }}
00826
00827
00828
00829