00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 namespace Gecode {
00023
00024 namespace Int {
00025
00026
00027
00028
00029
00030 template <class Val, class UnsVal>
00031 forceinline int
00032 ScaleView<Val,UnsVal>::floor_div(double x) const {
00033 return static_cast<int>(floor(x / a));
00034 }
00035
00036 template <class Val, class UnsVal>
00037 forceinline int
00038 ScaleView<Val,UnsVal>::ceil_div(double x) const {
00039 return static_cast<int>(ceil(x / a));
00040 }
00041
00042 template <class Val, class UnsVal>
00043 forceinline int
00044 ScaleView<Val,UnsVal>::exact_div(double x, bool& exact) const {
00045 double xa = x / a;
00046 if (ceil(xa) == xa) {
00047 exact = true; return static_cast<int>(xa);
00048 } else {
00049 exact = false; return 0;
00050 }
00051 }
00052
00053 #if GECODE_INT_RND_TWDS_ZERO
00054
00055 template <class Val, class UnsVal>
00056 forceinline int
00057 ScaleView<Val,UnsVal>::floor_div(int x) const {
00058 return ((x >= 0) ? x : (x-a+1))/a;
00059 }
00060
00061 template <class Val, class UnsVal>
00062 forceinline int
00063 ScaleView<Val,UnsVal>::ceil_div(int x) const {
00064 return ((x >= 0) ? (x+a-1) : x)/a;
00065 }
00066
00067 template <class Val, class UnsVal>
00068 forceinline int
00069 ScaleView<Val,UnsVal>::exact_div(int x, bool& exact) const {
00070 int xa = x / a;
00071 if (a * xa == x) {
00072 exact = true; return xa;
00073 } else {
00074 exact = false; return 0;
00075 }
00076 }
00077
00078 #endif
00079
00080
00081
00082
00083
00084
00085 template <class Val, class UnsVal>
00086 forceinline
00087 ScaleView<Val,UnsVal>::ScaleView(void) {}
00088
00089 template <class Val, class UnsVal>
00090 forceinline
00091 ScaleView<Val,UnsVal>::ScaleView(int b, const IntView& x)
00092 : DerivedViewBase<IntView>(x), a(b) {}
00093
00094 template <class Val, class UnsVal>
00095 forceinline void
00096 ScaleView<Val,UnsVal>::init(int b, const IntView& x) {
00097 view=x; a=b;
00098 }
00099
00100 template <class Val, class UnsVal>
00101 forceinline int
00102 ScaleView<Val,UnsVal>::scale(void) const {
00103 return a;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112 template <class Val, class UnsVal>
00113 forceinline Val
00114 ScaleView<Val,UnsVal>::min(void) const {
00115 Val c = view.min(); c *= a; return c;
00116 }
00117
00118 template <class Val, class UnsVal>
00119 forceinline Val
00120 ScaleView<Val,UnsVal>::max(void) const {
00121 Val c = view.max(); c *= a; return c;
00122 }
00123
00124 template <class Val, class UnsVal>
00125 forceinline Val
00126 ScaleView<Val,UnsVal>::med(void) const {
00127 Val c = view.med(); c *= a; return c;
00128 }
00129
00130 template <class Val, class UnsVal>
00131 forceinline Val
00132 ScaleView<Val,UnsVal>::val(void) const {
00133 Val c = view.val(); c *= a; return c;
00134 }
00135
00136 template <class Val, class UnsVal>
00137 forceinline UnsVal
00138 ScaleView<Val,UnsVal>::size(void) const {
00139 return static_cast<UnsVal>(view.size());
00140 }
00141
00142 template <class Val, class UnsVal>
00143 forceinline UnsVal
00144 ScaleView<Val,UnsVal>::width(void) const {
00145 UnsVal c = view.width(); c *= a; return c;
00146 }
00147
00148 template <class Val, class UnsVal>
00149 forceinline UnsVal
00150 ScaleView<Val,UnsVal>::regret_min(void) const {
00151 UnsVal c = view.regret_min(); c *= a; return c;
00152 }
00153
00154 template <class Val, class UnsVal>
00155 forceinline UnsVal
00156 ScaleView<Val,UnsVal>::regret_max(void) const {
00157 UnsVal c = view.regret_max(); c *= a; return c;
00158 }
00159
00160
00161
00162
00163
00164
00165 template <class Val, class UnsVal>
00166 forceinline bool
00167 ScaleView<Val,UnsVal>::range(void) const {
00168 return view.range();
00169 }
00170
00171 template <class Val, class UnsVal>
00172 forceinline bool
00173 ScaleView<Val,UnsVal>::assigned(void) const {
00174 return view.assigned();
00175 }
00176
00177 template <class Val, class UnsVal>
00178 forceinline bool
00179 ScaleView<Val,UnsVal>::in(Val n) const {
00180 bool exact;
00181 int nda = exact_div(n, exact);
00182 return exact && view.in(nda);
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192 template <class Val, class UnsVal>
00193 forceinline ModEvent
00194 ScaleView<Val,UnsVal>::lq(Space* home, Val n) {
00195 return (n >= max()) ? ME_INT_NONE : view.lq(home,floor_div(n));
00196 }
00197
00198 template <class Val, class UnsVal>
00199 forceinline ModEvent
00200 ScaleView<Val,UnsVal>::le(Space* home, Val n) {
00201 return (n > max()) ? ME_INT_NONE : view.le(home,floor_div(n));
00202 }
00203
00204 template <class Val, class UnsVal>
00205 forceinline ModEvent
00206 ScaleView<Val,UnsVal>::gq(Space* home, Val n) {
00207 return (n <= min()) ? ME_INT_NONE : view.gq(home,ceil_div(n));
00208 }
00209 template <class Val, class UnsVal>
00210 forceinline ModEvent
00211 ScaleView<Val,UnsVal>::gr(Space* home, Val n) {
00212 return (n < min()) ? ME_INT_NONE : view.gr(home,ceil_div(n));
00213 }
00214
00215 template <class Val, class UnsVal>
00216 forceinline ModEvent
00217 ScaleView<Val,UnsVal>::nq(Space* home, Val n) {
00218 bool exact;
00219 int nda = exact_div(n,exact);
00220 return exact ? view.nq(home,nda) : ME_INT_NONE;
00221 }
00222
00223 template <class Val, class UnsVal>
00224 forceinline ModEvent
00225 ScaleView<Val,UnsVal>::eq(Space* home, Val n) {
00226 bool exact;
00227 int nda = exact_div(n,exact);
00228 return exact ? view.eq(home,nda) : ME_INT_FAILED;
00229 }
00230
00231
00232
00233
00234
00235
00236 template <class Val, class UnsVal>
00237 forceinline ModEvent
00238 ScaleView<Val,UnsVal>::pme(const Propagator* p) {
00239 return IntView::pme(p);
00240 }
00241
00242 template <class Val, class UnsVal>
00243 forceinline PropModEvent
00244 ScaleView<Val,UnsVal>::pme(ModEvent me) {
00245 return IntView::pme(me);
00246 }
00247
00248
00249
00250
00251
00252
00253
00254 template <class Val, class UnsVal>
00255 forceinline void
00256 ScaleView<Val,UnsVal>::subscribe(Space* home, Propagator* p, PropCond pc,
00257 bool process) {
00258 view.subscribe(home,p,pc,process);
00259 }
00260 template <class Val, class UnsVal>
00261 forceinline void
00262 ScaleView<Val,UnsVal>::cancel(Space* home, Propagator* p, PropCond pc) {
00263 view.cancel(home,p,pc);
00264 }
00265
00266
00267
00268
00269
00270
00271 template <class Val, class UnsVal>
00272 forceinline void
00273 ScaleView<Val,UnsVal>::update(Space* home, bool share,
00274 ScaleView<Val,UnsVal>& x) {
00275 a=x.a; view.update(home,share,x.view);
00276 }
00277
00278
00283 template <>
00284 class ViewRanges<IntScaleView>
00285 : public Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> > {
00286 public:
00288
00289
00290 ViewRanges(void);
00292 ViewRanges(const IntScaleView& x);
00294 void init(const IntScaleView& x);
00296 };
00297
00298 forceinline
00299 ViewRanges<IntScaleView>::ViewRanges(void) {}
00300 forceinline
00301 ViewRanges<IntScaleView>::ViewRanges(const IntScaleView& x) {
00302 ViewRanges<IntView> xi(x.base());
00303 Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init
00304 (xi,x.scale());
00305 }
00306 forceinline void
00307 ViewRanges<IntScaleView>::init(const IntScaleView& x) {
00308 ViewRanges<IntView> xi(x.base());
00309 Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init
00310 (xi,x.scale());
00311 }
00312
00313
00318 template <>
00319 class ViewRanges<DoubleScaleView>
00320 : public Iter::Ranges::ScaleUp<double,double,ViewRanges<IntView> > {
00321 public:
00323
00324
00325 ViewRanges(void);
00327 ViewRanges(const DoubleScaleView& x);
00329 void init(const DoubleScaleView& x);
00331 };
00332
00333 forceinline
00334 ViewRanges<DoubleScaleView>::ViewRanges(void) {}
00335 forceinline
00336 ViewRanges<DoubleScaleView>::ViewRanges(const DoubleScaleView& x) {
00337 ViewRanges<IntView> xi(x.base());
00338 Iter::Ranges::ScaleUp<double,double,ViewRanges<IntView> >::init
00339 (xi,x.scale());
00340 }
00341 forceinline void
00342 ViewRanges<DoubleScaleView>::init(const DoubleScaleView& x) {
00343 ViewRanges<IntView> xi(x.base());
00344 Iter::Ranges::ScaleUp<double,double,ViewRanges<IntView> >::init
00345 (xi,x.scale());
00346 }
00347
00348 }
00349
00350
00351
00352
00353
00354
00355
00356 template <class Val, class UnsVal>
00357 forceinline bool
00358 same(const Int::ScaleView<Val,UnsVal>& x,
00359 const Int::ScaleView<Val,UnsVal>& y) {
00360 return same(x.base(),y.base()) && (x.scale() == y.scale());
00361 }
00362 template <class Val, class UnsVal>
00363 forceinline bool
00364 before(const Int::ScaleView<Val,UnsVal>& x,
00365 const Int::ScaleView<Val,UnsVal>& y) {
00366 return before(x.base(),y.base())
00367 || (same(x.base(),y.base()) && (x.scale() < y.scale()));
00368 }
00369
00370 }
00371
00372
00373