Generated on Wed Jan 4 17:49:10 2006 for Gecode by doxygen 1.4.6

occur.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Patrick Pekczynski <pekczynski@ps.uni-sb.de>
00004  *
00005  *  Copyright:
00006  *     Patrick Pekczynski, 2004
00007  *
00008  *  Last modified: $Date: 2005-12-06 07:46:40 +0100 (Tue, 06 Dec 2005) $ by $Author: pekczynski $
00009  *  $Revision: 2696 $
00010  *
00011  *  This file is part of Gecode, the generic constrain
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  */
00020 
00021 #include "iter.hh"
00022 
00023 namespace Gecode { namespace Int { namespace GCC {
00028   template <class T, unsigned int n>
00029   class OccurBnds {
00030   private:
00031     // The views 
00032     // not supposed to have an array with size n larger 2
00033     T x[n];
00034     int c;
00035     int count;
00036   public:
00037     OccurBnds(void);
00038     T& operator[](unsigned int i);
00039     const T& operator[](unsigned int i) const;
00040      T& min(void);
00041      T& max(void);
00042     void init(Space* home, T min, T max, int c);
00043     ModEvent lq(Space* home, int n); 
00044     ModEvent gq(Space* home, int n); 
00045     ModEvent eq(Space* home, int n); 
00046     bool assigned(void);
00047     T& operator=(const T& o);
00048     int card(void);
00049     void card(int c);
00050     ModEvent inc(void);
00051     void counter(int c);
00052     int counter(void);
00053   };
00054 
00055   template <class T, unsigned int n>
00056   std::ostream&
00057   operator<<(std::ostream& os, const OccurBnds<T,n>& xy);
00058 
00059   template <class T, unsigned int n>
00060   forceinline
00061   OccurBnds<T,n>::OccurBnds(void) {}
00062 
00063   template <class T, unsigned int n>
00064   forceinline const T&
00065   OccurBnds<T,n>::operator[](unsigned int i) const {
00066     assert((i >= 0) && (i < n));
00067     return x[i];
00068   }
00069 
00070   template <class T, unsigned int n>
00071   forceinline T&
00072   OccurBnds<T,n>::operator[](unsigned int i) {
00073     assert((i >= 0) && (i < n));
00074     return x[i];
00075   }
00076 
00077   template <class T, unsigned int n>
00078   forceinline T&
00079   OccurBnds<T,n>::min(void) {
00080     return x[0];
00081   }
00082 
00083   template <class T, unsigned int n>
00084   forceinline void
00085   OccurBnds<T,n>::init(Space* home, T min, T max, int val) {
00086     x[0] = min; x[n - 1] = max;
00087     c = val;
00088     count = 0;
00089   }
00090 
00091   template <class T, unsigned int n>
00092   forceinline int
00093   OccurBnds<T,n>::card(void) {
00094     return c;
00095   }
00096 
00097   template <class T, unsigned int n>
00098   forceinline void
00099   OccurBnds<T,n>::card(int ca) {
00100     c = ca;
00101   }
00102 
00103   template <class T, unsigned int n>
00104   forceinline ModEvent
00105   OccurBnds<T,n>::inc(void) {
00106     count++;
00107     if (count > this->max()) {
00108       return ME_GEN_FAILED;
00109     } else {
00110       return ME_GEN_NONE;
00111     }
00112   }
00113 
00114   template <class T, unsigned int n>
00115   forceinline void
00116   OccurBnds<T,n>::counter(int c) {
00117     count = c;
00118   }
00119 
00120   template <class T, unsigned int n>
00121   forceinline int
00122   OccurBnds<T,n>::counter(void) {
00123     return count;
00124   }
00125 
00126   template <class T, unsigned int n>
00127   forceinline bool
00128   OccurBnds<T,n>::assigned(void) {
00129     return x[0] == x[1];
00130   }
00131 
00132   template <class T, unsigned int n> // template <class I>
00133   forceinline ModEvent 
00134   OccurBnds<T,n>::lq(Space* home, int i){
00135     // the maximum can be made consistent
00136     if (x[0] > i) {
00137       return ME_GEN_FAILED;
00138     } else {
00139       if (x[1] <= i) {
00140         return ME_GEN_NONE;
00141       } else {
00142         x[1] = i;
00143         return 2;
00144       }
00145     }
00146   }
00147 
00148   template <class T, unsigned int n> // template <class I>
00149   forceinline ModEvent 
00150   OccurBnds<T,n>::gq(Space* home, int i){
00151     // this bound is fix
00152     return ME_GEN_NONE;
00153   }
00154 
00155   template <class T, unsigned int n> // template <class I>
00156   forceinline ModEvent 
00157   OccurBnds<T,n>::eq(Space* home, int i){
00158     if (x[0] > i || x[1] < i) {
00159       return ME_GEN_FAILED;
00160     } else {
00161       x[0] = i;
00162       x[1] = i;
00163       return 2;
00164     }
00165   }
00166 
00167 
00168 
00169 
00170   template <class T, unsigned int n>
00171   forceinline T& 
00172   OccurBnds<T,n>::operator=(const T& o){
00173     (*this)[0]  = o[0];
00174     (*this)[1]  = o[1];
00175     this->c     = o.c;
00176     this->count = o.count;
00177   }
00178 
00179   template <class T, unsigned int n>
00180   forceinline  T&
00181   OccurBnds<T,n>::max(void) {
00182     return x[n - 1];
00183   }
00184 
00185   template <class T, unsigned int n>
00186   inline std::ostream&
00187   operator<<(std::ostream& os, const OccurBnds<T,n>& xs) {
00188     os << "[";
00189     for (unsigned int i=0; i<n-1; i++)
00190       os << xs[i] << ",";
00191     return os << xs[n-1] << "]";
00192   }
00193 
00198   template <class T>
00199   class OccurArray :public PrimArgArray<T>{
00200   private: 
00201     int l;
00202   public:
00203     OccurArray(int n);
00204     OccurArray(Space* home, int n);
00205     OccurArray(const OccurArray<T>& o);
00206     OccurArray(Space* home, const OccurArray<T>& o);
00207     template <class View>
00208     OccurArray(const IntArgs&, const ViewArray<View>&, 
00209                int, int, int, int, int, int, int);
00210     int  size(void);
00211     void size(int n);
00212     void update(Space*, bool, OccurArray<T>&);
00213     void cancel(Propagator* , PropCond );
00214     void subscribe(Space*, Propagator* , PropCond);
00215     int  lookup(int v);
00216   };
00217 
00218 
00219   template <class T>
00220   OccurArray<T>::OccurArray(int n) : PrimArgArray<T>(n), l(n){}
00221 
00222   template <class T>
00223   OccurArray<T>::OccurArray(Space* home, int n) : PrimArgArray<T>(n), l(n){}
00224 
00237   template <class T> template <class View>
00238   OccurArray<T>::OccurArray(const IntArgs& ia, const ViewArray<View>& x,
00239                             int iasize, int val, int nov,
00240                             int min, int max, 
00241                             int unspec_low, int unspec_up) : 
00242     PrimArgArray<T>(std::max(nov, val)), l(std::max(nov, val)) {
00243     
00244     int n = x.size();
00245 
00246     GECODE_AUTOARRAY(ViewRanges<View>, xrange, n);
00247     for (int i = n; i--; ){
00248       ViewRanges<View> iter(x[i]);
00249       xrange[i] = iter;
00250     }
00251 
00252     Gecode::Iter::Ranges::NaryUnion<ViewRanges<View> >     
00253       drl(&xrange[0], x.size());
00254     Gecode::Iter::Ranges::Cache<
00255       Gecode::Iter::Ranges::
00256       NaryUnion<ViewRanges<View> > > crl(drl);
00257        
00258     int c = 0; 
00259     int r = 0;
00260     
00261     GECODE_AUTOARRAY(bool, indom, (max - (min - 1)));
00262     for (int i = max - (min - 1); i--; ) {
00263       indom[i] = false;
00264     }
00265     for ( ; crl(); ++crl) {
00266       for (int v = crl.min(); v <= crl.max(); v++) {
00267         indom[v - min] = true;
00268       }
00269     }
00270 
00271     int xmin = min;
00272     int xmax = max;
00273     // mark those values that are specified
00274     min = std::min(xmin, ia[0]);
00275     max = std::max(xmax, ia[(val - 1) * 3]);
00276 
00277     for (int v = min; v <= max; v++) {
00278       if (c > l - 1) {
00279         break;
00280       }
00281       // value is in a variable domain
00282       if (v >= xmin && indom[v - xmin]) {
00283         if (r < iasize) {
00284           if (v == ia[r]) {
00285             // value is specified with cardinalities
00286             // checking should be outsourced to gcc.cc
00287             if (ia[r + 1] > ia[r + 2]) {
00288               throw ArgumentSizeMismatch("Int::gcc");
00289             }
00290             
00291             (*this)[c].card(v);
00292             (*this)[c].counter(0);
00293             (*this)[c][0] = ia[r + 1];
00294             (*this)[c][1] = ia[r + 2];
00295             c++;
00296             r += 3;
00297           } else {
00298             // value is not specified with cardinalities
00299             // the value is unspecified
00300             (*this)[c].card(v);
00301             (*this)[c].counter(0);
00302             (*this)[c][0] = unspec_low;
00303             (*this)[c][1] = unspec_up;
00304             c++;
00305           }
00306         } else {
00307           // there are more values in the variable domains
00308           // than specified 
00309             (*this)[c].card(v);
00310             (*this)[c].counter(0);
00311             (*this)[c][0] = unspec_low;
00312             (*this)[c][1] = unspec_up;
00313             c++;
00314         }
00315       } else {
00316         // the value is not in a variable domain of the current assignment
00317         if (r < iasize) {
00318           // but it is specified
00319           if (v == ia[r]) {
00320             // checking should be outsourced to gcc.cc
00321             if (ia[r + 1] > ia[r + 2]) {
00322               throw ArgumentSizeMismatch("Int::gcc");
00323             }
00324             
00325             (*this)[c].card(v);
00326             (*this)[c].counter(0);
00327             (*this)[c][0] = ia[r + 1];
00328             (*this)[c][1] = ia[r + 2];
00329             c++;
00330             r += 3;
00331           } else {
00332             // the value is unspecified
00333             (*this)[c].card(v);
00334             (*this)[c].counter(0);
00335             (*this)[c][0] = unspec_low;
00336             (*this)[c][1] = unspec_up;
00337             c++;
00338           }
00339         } else {
00340           // there are more values in the variable domains
00341           // than specified 
00342             (*this)[c].card(v);
00343             (*this)[c].counter(0);
00344             (*this)[c][0] = unspec_low;
00345             (*this)[c][1] = unspec_up;
00346             c++;
00347         }
00348       }
00349     }
00350     
00351     if (c < l) {
00352       for ( ; r < iasize; r+=3) {
00353         assert(0 <= c && c < l);
00354         (*this)[c].card(ia[r]);
00355         (*this)[c].counter(0);
00356         (*this)[c][0] = unspec_low;
00357         (*this)[c][1] = unspec_up;
00358         c++;
00359         r+=3;
00360       }
00361     }
00362       
00363   }
00364 
00365   template <class T>
00366   OccurArray<T>::OccurArray(const OccurArray<T>& o) 
00367     : PrimArgArray<T>(o), l(o.l) {}
00368 
00369   template <class T>
00370   OccurArray<T>::OccurArray(Space* home, const OccurArray<T>& o) 
00371     : PrimArgArray<T>(o), l(o.l) {}
00372 
00373   template <class T>
00374   forceinline int
00375   OccurArray<T>::size(void){
00376     return l;
00377   }
00378 
00379   template <class T>
00380   forceinline void
00381   OccurArray<T>::size(int n){
00382     l = n;
00383   }
00384 
00385   template <class T>
00386   forceinline void
00387   OccurArray<T>::update(Space* home, bool share, OccurArray<T>& o) {
00388     for (int i = this->size(); i--; ) {
00389       (*this)[i] = o[i];
00390     }
00391   }
00392 
00393   template <class T>
00394   forceinline void
00395   OccurArray<T>::cancel(Propagator* p, PropCond pc ) {
00396     
00397   }
00398 
00399   template <class T>
00400   forceinline void
00401   OccurArray<T>::subscribe(Space* home, Propagator* p, PropCond pc ) {
00402   }
00403 
00410   template <class T>
00411   forceinline int 
00412   OccurArray<T>::lookup(int v){
00413     int idx = -1;
00414     
00415     int l  = 0;
00416     int r  = this->size() - 1;
00417 
00418     if (r == 0) {
00419       if ((*this)[0].card() == v) {
00420         return 0;
00421       } else {
00422         return -1;
00423       }
00424     }
00425 
00426     while ( l < r ) {
00427       if ( (*this)[l].card() == v) {
00428         idx = l;
00429         break;
00430       }
00431       if ( (*this)[r].card() == v) {
00432         idx = r;
00433         break;
00434       }
00435       int p  = (l + r) / 2;
00436       if ( v == (*this)[p].card()) {
00437         idx = p;
00438         break;
00439       } else {
00440         if ( v < (*this)[p].card()) {
00441           r = p;
00442         } else {
00443           l = p;
00444         }
00445       }
00446       if (l == r - 1) {
00447         break;
00448       }
00449     }
00450 
00451     
00452 
00453     return idx;
00454   }
00455 
00456 
00457 
00462   class CardView : public DerivedViewBase<IntView> {
00463   protected:
00465     int c;
00467     int count;
00468     using DerivedViewBase<IntView>::view;
00469   public:
00470     CardView(void);
00472     CardView(const IntView& x, int c);
00474     void init(const IntView& x, int c);
00475     void init(Space* home, int mi, int ma , int c);
00476 
00478     int card(void) const;
00479     void card(int ca);
00480 
00482     ModEvent inc(void);
00484     void counter(int);
00486     int counter(void);
00487     
00489 
00490     void operator=(const IntView& x);
00491     void operator=(const Gecode::Int::GCC::CardView& x);
00493     int min(void) const;
00495     int max(void) const;
00497     int med(void) const;
00499     int val(void) const;
00500 
00502     unsigned int size(void) const;
00504     unsigned int width(void) const;
00506     unsigned int regret_min(void) const;
00508     unsigned int regret_max(void) const;
00510 
00514     bool range(void) const;
00516     bool assigned(void) const;
00517 
00519     bool in(int n) const;
00521     bool in(double n) const;
00523 
00527     ModEvent lq(Space* home, int n); 
00529     ModEvent lq(Space* home, double n);
00531     ModEvent le(Space* home, int n); 
00533     ModEvent le(Space* home, double n);
00535     ModEvent gq(Space* home, int n); 
00537     ModEvent gq(Space* home, double n);
00539     ModEvent gr(Space* home, int n); 
00541     ModEvent gr(Space* home, double n);
00543     ModEvent nq(Space* home, int n); 
00545     ModEvent nq(Space* home, double n);
00547     ModEvent eq(Space* home, int n); 
00549     ModEvent eq(Space* home, double n);
00551 
00556     template <class I> ModEvent inter(Space* home, I& i);
00558     template <class I> ModEvent minus(Space* home, I& i);
00560 
00564     static ModEvent     pme(const Propagator* p);
00566     static PropModEvent pme(ModEvent me);
00568 
00572     void subscribe(Space* home, Propagator* p, PropCond pc);
00574     void cancel(Propagator* p, PropCond pc);
00576 
00580     void update(Space* home, bool share, CardView& x);
00582 
00586     bool operator ==(const CardView& x) const;
00588     bool operator !=(const CardView& x) const;
00590     bool operator < (const CardView& x) const;
00592     bool operator > (const CardView& x) const;
00594   };
00595 
00596   /*
00597    * Constructors and initialization
00598    *
00599    */
00600   forceinline
00601   CardView::CardView(void) {}
00602 
00603   forceinline
00604   CardView::CardView(const IntView& x, int d)
00605     : DerivedViewBase<IntView>(x), c(d), count(0) {}
00606 
00607   forceinline void
00608   CardView::init(const IntView& x, int d) {
00609     view  = x; 
00610     c     = d; 
00611     count = 0;
00612   }
00613 
00614 
00615   forceinline void
00616   CardView::init(Space* home, int mi, int ma, int d) {
00617     IntVar ivar(home, mi, ma);
00618     IntView iview(ivar);
00619     view  = iview; 
00620     c     = d;
00621     count = 0;
00622   }
00623 
00624   forceinline void 
00625   CardView::card(int ca) {
00626     c = ca;
00627   }
00628 
00629   forceinline int
00630   CardView::card(void) const {
00631     return c;
00632   }
00633 
00634   forceinline ModEvent
00635   CardView::inc(void) {
00636     count++;
00637     if (count > this->max()) {
00638       return ME_GEN_FAILED;
00639     } else {
00640       return ME_GEN_NONE;
00641     }
00642   }
00643 
00644   forceinline void
00645   CardView::counter(int c) {
00646     count = c;
00647   }
00648 
00649   forceinline int
00650   CardView::counter(void) {
00651     return count;
00652   }
00653 
00654   /*
00655    * Value access
00656    *
00657    */
00658 
00659   forceinline void 
00660   CardView::operator=(const IntView& x) { 
00661     view  = x; 
00662     c     = 0; 
00663     count = 0;
00664   }
00665 
00666   forceinline void 
00667   CardView::operator=(const CardView& x) { 
00668     view  = x.view; 
00669     c     = x.c; 
00670     count = x.count;
00671   }
00672 
00673   forceinline int
00674   CardView::min(void) const { 
00675     return view.min(); 
00676   }
00677   forceinline int
00678   CardView::max(void) const { 
00679     return view.max(); 
00680   }
00681   forceinline int
00682   CardView::med(void) const { 
00683     return view.med(); 
00684   }
00685   forceinline int
00686   CardView::val(void) const { 
00687     return view.val(); 
00688   }
00689 
00690   forceinline unsigned int
00691   CardView::width(void) const { 
00692     return view.width(); 
00693   }
00694   forceinline unsigned int
00695   CardView::size(void) const { 
00696     return view.size(); 
00697   }
00698   forceinline unsigned int
00699   CardView::regret_min(void) const { 
00700     return view.regret_min(); 
00701   }
00702   forceinline unsigned int
00703   CardView::regret_max(void) const { 
00704     return view.regret_max(); 
00705   }
00706 
00707   /*
00708    * Domain tests
00709    *
00710    */
00711   forceinline bool
00712   CardView::range(void) const { 
00713     return view.range(); 
00714   }
00715   forceinline bool
00716   CardView::assigned(void) const { 
00717     return view.assigned(); 
00718   }
00719 
00720   forceinline bool
00721   CardView::in(int n) const { 
00722     return view.in(n); 
00723   }
00724   forceinline bool
00725   CardView::in(double n) const { 
00726     return view.in(n); 
00727   }
00728 
00729 
00730   /*
00731    * Domain update by value
00732    *
00733    */
00734   forceinline ModEvent
00735   CardView::lq(Space* home, int n) { 
00736     return view.lq(home,n); 
00737   }
00738   forceinline ModEvent
00739   CardView::lq(Space* home, double n) { 
00740     return view.lq(home,n); 
00741   }
00742   forceinline ModEvent
00743   CardView::le(Space* home, int n) { 
00744     return view.le(home,n); 
00745   }
00746   forceinline ModEvent
00747   CardView::le(Space* home, double n) { 
00748     return view.le(home,n); 
00749   }
00750   forceinline ModEvent
00751   CardView::gq(Space* home, int n) { 
00752     return view.gq(home,n); 
00753   }
00754   forceinline ModEvent
00755   CardView::gq(Space* home, double n) { 
00756     return view.gq(home,n); 
00757   }
00758   forceinline ModEvent
00759   CardView::gr(Space* home, int n) { 
00760     return view.gr(home,n); 
00761   }
00762   forceinline ModEvent
00763   CardView::gr(Space* home, double n) { 
00764     return view.gr(home,n); 
00765   }
00766   forceinline ModEvent
00767   CardView::nq(Space* home, int n) { 
00768     return view.nq(home,n); 
00769   }
00770   forceinline ModEvent
00771   CardView::nq(Space* home, double n) { 
00772     return view.nq(home,n); 
00773   }
00774   forceinline ModEvent
00775   CardView::eq(Space* home, int n) { 
00776     return view.eq(home,n); 
00777   }
00778   forceinline ModEvent
00779   CardView::eq(Space* home, double n) { 
00780     return view.eq(home,n); 
00781   }
00782 
00783 
00784   /*
00785    * Domain update by range iterator
00786    *
00787    */
00788   template <class I>
00789   ModEvent
00790   CardView::inter(Space* home, I& i) {
00791     return view.inter(home,i);
00792   }
00793   template <class I>
00794   ModEvent
00795   CardView::minus(Space* home, I& i) {
00796     return view.minus(home,i);
00797   }
00798 
00799 
00800 
00801   /*
00802    * Propagator modification events
00803    *
00804    */
00805   forceinline ModEvent
00806   CardView::pme(const Propagator* p) {
00807     return IntView::pme(p);
00808   }
00809   forceinline PropModEvent
00810   CardView::pme(ModEvent me) {
00811     return IntView::pme(me);
00812   }
00813 
00814 
00815   /*
00816    * Dependencies
00817    *
00818    */
00819   forceinline void
00820   CardView::subscribe(Space* home, Propagator* p, PropCond pc) {
00821     view.subscribe(home, p, pc);
00822   }
00823   forceinline void
00824   CardView::cancel(Propagator* p, PropCond pc) {
00825     view.cancel(p, pc);
00826   }
00827 
00828 
00829   /*
00830    * Cloning
00831    *
00832    */
00833   forceinline void
00834   CardView::update(Space* home, bool share, CardView& x) {
00835     c     = x.c; 
00836     count = x.count;
00837     view.update(home,share,x.view);
00838   }
00839 
00840 
00841 
00842   /*
00843    * View comparison
00844    *
00845    */
00846 //   forceinline bool
00847 //   CardView::operator ==(const CardView& x) const {
00848 //     return (view == x.view) && (c == x.c) && (count == x.count);
00849 //   }
00850 //   forceinline bool
00851 //   CardView::operator !=(const CardView& x) const {
00852 //     return (view != x.view) || (c != x.c) ;
00853 //   }
00854 //   forceinline bool
00855 //   CardView::operator < (const CardView& x) const {
00856 //     return (view < x.view) || ((view == x.view) && (c < x.c));
00857 //   }
00858 //   forceinline bool
00859 //   CardView::operator > (const CardView& x) const {
00860 //     return (view > x.view) || ((view == x.view) && (c > x.c));
00861 //   }
00862 
00863 
00864 
00865 
00867   template <class T>
00868   class CardArray : public ViewArray<T>{
00869   public:
00870     int  lookup(int v);
00871     CardArray(void);
00872     CardArray(Space* home, int n);
00873     CardArray(Space* home, const ViewArray<T>& v);
00874     template <class Var>
00875     CardArray(Space* home, const VarArgArray<Var>&);
00876   };
00877 
00878   template <class T>
00879   forceinline 
00880   CardArray<T>::CardArray(void) : ViewArray<T>() {};
00881 
00882   template <class T>
00883   forceinline 
00884   CardArray<T>::CardArray(Space* home, int n) : ViewArray<T>(home, n) {};
00885 
00886   template <class T>
00887   forceinline 
00888   CardArray<T>::CardArray(Space* home, const ViewArray<T>& v) : ViewArray<T>(home, v) {};
00889 
00890   template <class T> template <class Var>
00891   forceinline 
00892   CardArray<T>::CardArray(Space* home, const VarArgArray<Var>& v) : ViewArray<T>(home, v) {};
00893 
00900   template <class T>
00901   forceinline int 
00902   CardArray<T>::lookup(int v){
00903     int idx = -1;
00904 
00905     int l  = 0;
00906     int r  = this->size() - 1;
00907 
00908     if (r == 0) {
00909       if ((*this)[0].card() == v) {
00910         return 0;
00911       } else {
00912         return -1;
00913       }
00914     }
00915 
00916     while ( l < r ) {
00917 
00918       if ( (*this)[l].card() == v) {
00919         idx = l;
00920         break;
00921       }
00922       if ( (*this)[r].card() == v) {
00923         idx = r;
00924         break;
00925       }
00926       int p  = (l + r) / 2;
00927       if ( v == (*this)[p].card()) {
00928         idx = p;
00929         break;
00930       } else {
00931         if ( v < (*this)[p].card()) {
00932           r = p;
00933         } else {
00934           l = p;
00935         }
00936       }
00937       if (l == r - 1) {
00938         break;
00939       }
00940     }
00941     return idx;
00942   }
00943 
00944 
00945 
00946   // Index the problem variables for staged propagation
00947 
00952   class IdxView : public DerivedViewBase<IntView> {
00953   protected:
00955     int newidx;
00956     int oldidx;
00957     using DerivedViewBase<IntView>::view;
00958   public:
00962     IdxView(void);
00964     IdxView(const IntView& x, int index);
00966     void init(const IntView& x, int c);
00968     int index(void) const;
00970     void index(int i);
00972     int oldindex(void) const;
00974     void oldindex(int i);
00976 
00977 
00980     void operator=(const IntView& x);
00982     int min(void) const;
00984     int max(void) const;
00986     int med(void) const;
00988     int val(void) const;
00989 
00991     unsigned int size(void) const;
00993     unsigned int width(void) const;
00995     unsigned int regret_min(void) const;
00997     unsigned int regret_max(void) const;
00999 
01003     bool range(void) const;
01005     bool assigned(void) const;
01006 
01008     bool in(int n) const;
01010     bool in(double n) const;
01012 
01016     ModEvent lq(Space* home, int n); 
01018     ModEvent lq(Space* home, double n);
01020     ModEvent le(Space* home, int n); 
01022     ModEvent le(Space* home, double n);
01024     ModEvent gq(Space* home, int n); 
01026     ModEvent gq(Space* home, double n);
01028     ModEvent gr(Space* home, int n); 
01030     ModEvent gr(Space* home, double n);
01032     ModEvent nq(Space* home, int n); 
01034     ModEvent nq(Space* home, double n);
01036     ModEvent eq(Space* home, int n); 
01038     ModEvent eq(Space* home, double n);
01040 
01044     template <class I> ModEvent narrow(Space* home, I& i);
01046     template <class I> ModEvent inter(Space* home, I& i);
01048     template <class I> ModEvent minus(Space* home, I& i);
01050 
01054     static ModEvent     pme(const Propagator* p);
01056     static PropModEvent pme(ModEvent me);
01058 
01062     void subscribe(Space* home, Propagator* p, PropCond pc);
01064     void cancel(Propagator* p, PropCond pc);
01066 
01070     void update(Space* home, bool share, IdxView& x);
01072 
01076     bool operator ==(const IdxView& x) const;
01078     bool operator !=(const IdxView& x) const;
01080     bool operator < (const IdxView& x) const;
01082     bool operator > (const IdxView& x) const;
01084   };
01085 
01086   /*
01087    * Constructors and initialization
01088    *
01089    */
01090   forceinline
01091   IdxView::IdxView(void) {}
01092 
01093   forceinline
01094   IdxView::IdxView(const IntView& x, int i)
01095     : DerivedViewBase<IntView>(x), newidx(i), oldidx(i) {}
01096 
01097   forceinline void
01098   IdxView::init(const IntView& x, int i) {
01099     view = x; 
01100     newidx = i;
01101     oldidx = i;
01102   }
01103   forceinline int
01104   IdxView::index(void) const {
01105     return newidx;
01106   }
01107   forceinline void
01108   IdxView::index(int i) {
01109     newidx = i;
01110   }
01111 
01112   forceinline int
01113   IdxView::oldindex(void) const {
01114     return oldidx;
01115   }
01116   forceinline void
01117   IdxView::oldindex(int i) {
01118     oldidx = i;
01119   }
01120 
01121 
01122   /*
01123    * Value access
01124    *
01125    */
01126   forceinline void 
01127   IdxView::operator=(const IntView& x) { 
01128     view = x; 
01129     newidx = 0;
01130     oldidx = 0;
01131   }
01132 
01133   forceinline int
01134   IdxView::min(void) const { 
01135     return view.min(); 
01136   }
01137   forceinline int
01138   IdxView::max(void) const { 
01139     return view.max(); 
01140   }
01141   forceinline int
01142   IdxView::med(void) const { 
01143     return view.med(); 
01144   }
01145   forceinline int
01146   IdxView::val(void) const { 
01147     return view.val(); 
01148   }
01149 
01150   forceinline unsigned int
01151   IdxView::width(void) const { 
01152     return view.width(); 
01153   }
01154   forceinline unsigned int
01155   IdxView::size(void) const { 
01156     return view.size(); 
01157   }
01158   forceinline unsigned int
01159   IdxView::regret_min(void) const { 
01160     return view.regret_min(); 
01161   }
01162   forceinline unsigned int
01163   IdxView::regret_max(void) const { 
01164     return view.regret_max(); 
01165   }
01166 
01167   /*
01168    * Domain tests
01169    *
01170    */
01171   forceinline bool
01172   IdxView::range(void) const { 
01173     return view.range(); 
01174   }
01175   forceinline bool
01176   IdxView::assigned(void) const { 
01177     return view.assigned(); 
01178   }
01179 
01180   forceinline bool
01181   IdxView::in(int n) const { 
01182     return view.in(n); 
01183   }
01184   forceinline bool
01185   IdxView::in(double n) const { 
01186     return view.in(n); 
01187   }
01188 
01189 
01190   /*
01191    * Domain update by value
01192    *
01193    */
01194   forceinline ModEvent
01195   IdxView::lq(Space* home, int n) { 
01196     return view.lq(home,n); 
01197   }
01198   forceinline ModEvent
01199   IdxView::lq(Space* home, double n) { 
01200     return view.lq(home,n); 
01201   }
01202   forceinline ModEvent
01203   IdxView::le(Space* home, int n) { 
01204     return view.le(home,n); 
01205   }
01206   forceinline ModEvent
01207   IdxView::le(Space* home, double n) { 
01208     return view.le(home,n); 
01209   }
01210   forceinline ModEvent
01211   IdxView::gq(Space* home, int n) { 
01212     return view.gq(home,n); 
01213   }
01214   forceinline ModEvent
01215   IdxView::gq(Space* home, double n) { 
01216     return view.gq(home,n); 
01217   }
01218   forceinline ModEvent
01219   IdxView::gr(Space* home, int n) { 
01220     return view.gr(home,n); 
01221   }
01222   forceinline ModEvent
01223   IdxView::gr(Space* home, double n) { 
01224     return view.gr(home,n); 
01225   }
01226   forceinline ModEvent
01227   IdxView::nq(Space* home, int n) { 
01228     return view.nq(home,n); 
01229   }
01230   forceinline ModEvent
01231   IdxView::nq(Space* home, double n) { 
01232     return view.nq(home,n); 
01233   }
01234   forceinline ModEvent
01235   IdxView::eq(Space* home, int n) { 
01236     return view.eq(home,n); 
01237   }
01238   forceinline ModEvent
01239   IdxView::eq(Space* home, double n) { 
01240     return view.eq(home,n); 
01241   }
01242 
01243 
01244 
01245   /*
01246    * Domain update by range iterator
01247    *
01248    */
01249   template <class I>
01250   ModEvent
01251   IdxView::narrow(Space* home, I& i) {
01252     return view.narrow(home, i);
01253   }
01254 
01255   template <class I>
01256   ModEvent
01257   IdxView::inter(Space* home, I& i) {
01258     return view.inter(home,i);
01259   }
01260   template <class I>
01261   ModEvent
01262   IdxView::minus(Space* home, I& i) {
01263     return view.minus(home,i);
01264   }
01265 
01266 
01267 
01268   /*
01269    * Propagator modification events
01270    *
01271    */
01272   forceinline ModEvent
01273   IdxView::pme(const Propagator* p) {
01274     return IntView::pme(p);
01275   }
01276   forceinline PropModEvent
01277   IdxView::pme(ModEvent me) {
01278     return IntView::pme(me);
01279   }
01280 
01281 
01282   /*
01283    * Dependencies
01284    *
01285    */
01286   forceinline void
01287   IdxView::subscribe(Space* home, Propagator* p, PropCond pc) {
01288     view.subscribe(home,p,pc);
01289   }
01290   forceinline void
01291   IdxView::cancel(Propagator* p, PropCond pc) {
01292     view.cancel(p,pc);
01293   }
01294 
01295 
01296   /*
01297    * Cloning
01298    *
01299    */
01300   forceinline void
01301   IdxView::update(Space* home, bool share, IdxView& x) {
01302     newidx = x.newidx; 
01303     oldidx = x.oldidx;
01304     view.update(home,share,x.view);
01305   }
01306 
01307 
01308 
01309   /*
01310    * View comparison
01311    *
01312    */
01313 //   forceinline bool
01314 //   IdxView::operator ==(const IdxView& x) const {
01315 //     return (view == x.view) 
01316 //       && (newidx == x.newidx) 
01317 //       && (oldidx == x.oldidx);
01318 //   }
01319 //   forceinline bool
01320 //   IdxView::operator !=(const IdxView& x) const {
01321 //     return (view != x.view) || (newidx != x.newidx) || (oldidx != x.oldidx);
01322 //   }
01323 //   forceinline bool
01324 //   IdxView::operator < (const IdxView& x) const {
01325 //     return (view < x.view) || 
01326 //       ((view == x.view) && (newidx < x.newidx) && (oldidx < x.oldidx));
01327 //   }
01328 //   forceinline bool
01329 //   IdxView::operator > (const IdxView& x) const {
01330 //     return (view > x.view) || 
01331 //       ((view == x.view) && (newidx > x.newidx) && (oldidx > x.oldidx));
01332 //   }
01333 
01334 }
01335 
01339   template <>
01340   class ViewRanges<GCC::IdxView>
01341     : public Gecode::Int::ViewRanges<IntView> {
01342   public:
01346     ViewRanges(void);
01348     ViewRanges(const GCC::IdxView& x);
01350     void init(const GCC::IdxView& x);
01352   };
01353 
01354   forceinline
01355   ViewRanges<GCC::IdxView>::ViewRanges(void) : 
01356     Gecode::Int::ViewRanges<IntView>()  {}
01357 
01358   forceinline
01359   ViewRanges<GCC::IdxView>::ViewRanges (const GCC::IdxView& x) 
01360     : Gecode::Int::ViewRanges<IntView>(x.base())  {}
01361 
01362   forceinline void
01363   ViewRanges<GCC::IdxView>::init(const GCC::IdxView& x) {
01364     Gecode::Int::ViewRanges<IntView> xi(x.base());
01365   }
01366 
01367   /*
01368    * View comparison
01369    *
01370    */
01371   forceinline bool
01372   same(const GCC::IdxView& x, const GCC::IdxView& y) {
01373     return same(x.base(),y.base()) && (x.index() == y.index());
01374   }
01375   forceinline bool
01376   before(const GCC::IdxView& x, const GCC::IdxView& y) {
01377     return before(x.base(),y.base())
01378       || (same(x.base(),y.base()) && (x.index() < y.index()));
01379   }
01380 
01381 
01382 }}
01383 
01384 
01385 
01386 // STATISTICS: int-prop