ranges-compl.hpp
Go to the documentation of this file.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 namespace Gecode { namespace Iter { namespace Ranges {
00037
00048 template<int UMIN, int UMAX, class I>
00049 class Compl : public MinMax {
00050 protected:
00052 I i;
00054 void start(void);
00055 public:
00057
00058
00059 Compl(void);
00061 Compl(I& i);
00063 void init(I& i);
00065
00067
00068
00069 void operator ++(void);
00071 };
00072
00073
00084 template<class I>
00085 class ComplVal : public MinMax {
00086 protected:
00088 int UMIN, UMAX;
00090 I i;
00092 void start(void);
00093 public:
00095
00096
00097 ComplVal(void);
00099 ComplVal(int umin, int umax, I& i);
00101 void init(int umin, int umax, I& i);
00103
00105
00106
00107 void operator ++(void);
00109 };
00110
00111
00112 template<int UMIN, int UMAX, class I>
00113 forceinline void
00114 Compl<UMIN,UMAX,I>::start(void) {
00115 if (i()) {
00116 assert((i.min() >= UMIN) && (i.max() <= UMAX));
00117 if (i.min() > UMIN) {
00118 mi = UMIN;
00119 ma = i.min()-1;
00120 } else if (i.max() < UMAX) {
00121 mi = i.max()+1;
00122 ++i;
00123 ma = i() ? (i.min()-1) : UMAX;
00124 } else {
00125 finish();
00126 }
00127 } else {
00128 mi = UMIN;
00129 ma = UMAX;
00130 }
00131 }
00132
00133 template<int UMIN, int UMAX, class I>
00134 forceinline
00135 Compl<UMIN,UMAX,I>::Compl(void) {}
00136
00137 template<int UMIN, int UMAX, class I>
00138 forceinline
00139 Compl<UMIN,UMAX,I>::Compl(I& i0) : i(i0) {
00140 start();
00141 }
00142
00143 template<int UMIN, int UMAX, class I>
00144 forceinline void
00145 Compl<UMIN,UMAX,I>::init(I& i0) {
00146 i=i0; start();
00147 }
00148
00149 template<int UMIN, int UMAX, class I>
00150 forceinline void
00151 Compl<UMIN,UMAX,I>::operator ++(void) {
00152 assert(!i() || (i.max() <= UMAX));
00153 if (i() && (i.max() < UMAX)) {
00154 mi = i.max()+1;
00155 ++i;
00156 ma = i() ? (i.min()-1) : UMAX;
00157 } else {
00158 finish();
00159 }
00160 }
00161
00162 template<class I>
00163 forceinline void
00164 ComplVal<I>::start(void) {
00165 if (i()) {
00166 assert((i.min() >= UMIN) && (i.max() <= UMAX));
00167 if (i.min() > UMIN) {
00168 mi = UMIN;
00169 ma = i.min()-1;
00170 } else if (i.max() < UMAX) {
00171 mi = i.max()+1;
00172 ++i;
00173 ma = i() ? (i.min()-1) : UMAX;
00174 } else {
00175 finish();
00176 }
00177 } else {
00178 mi = UMIN;
00179 ma = UMAX;
00180 }
00181 }
00182
00183 template<class I>
00184 forceinline
00185 ComplVal<I>::ComplVal(void) {}
00186
00187 template<class I>
00188 forceinline
00189 ComplVal<I>::ComplVal(int umin, int umax, I& i0)
00190 : UMIN(umin), UMAX(umax), i(i0) {
00191 start();
00192 }
00193
00194 template<class I>
00195 forceinline void
00196 ComplVal<I>::init(int umin, int umax, I& i0) {
00197 UMIN=umin; UMAX=umax; i=i0; start();
00198 }
00199
00200 template<class I>
00201 forceinline void
00202 ComplVal<I>::operator ++(void) {
00203 assert(!i() || (i.max() <= UMAX));
00204 if (i() && (i.max() < UMAX)) {
00205 mi = i.max()+1;
00206 ++i;
00207 ma = i() ? (i.min()-1) : UMAX;
00208 } else {
00209 finish();
00210 }
00211 }
00212
00213 }}}
00214
00215
00216