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
00038 namespace Gecode {
00039
00040 namespace Int {
00041
00042
00043
00044
00045
00046 template <class Val, class UnsVal>
00047 forceinline int
00048 ScaleView<Val,UnsVal>::floor_div(double x) const {
00049 return static_cast<int>(floor(x / a));
00050 }
00051
00052 template <class Val, class UnsVal>
00053 forceinline int
00054 ScaleView<Val,UnsVal>::ceil_div(double x) const {
00055 return static_cast<int>(ceil(x / a));
00056 }
00057
00058 template <class Val, class UnsVal>
00059 forceinline int
00060 ScaleView<Val,UnsVal>::exact_div(double x, bool& exact) const {
00061 double xa = x / a;
00062 if (ceil(xa) == xa) {
00063 exact = true; return static_cast<int>(xa);
00064 } else {
00065 exact = false; return 0;
00066 }
00067 }
00068
00069 #if GECODE_INT_RND_TWDS_ZERO
00070
00071 template <class Val, class UnsVal>
00072 forceinline int
00073 ScaleView<Val,UnsVal>::floor_div(int x) const {
00074 return ((x >= 0) ? x : (x-a+1))/a;
00075 }
00076
00077 template <class Val, class UnsVal>
00078 forceinline int
00079 ScaleView<Val,UnsVal>::ceil_div(int x) const {
00080 return ((x >= 0) ? (x+a-1) : x)/a;
00081 }
00082
00083 template <class Val, class UnsVal>
00084 forceinline int
00085 ScaleView<Val,UnsVal>::exact_div(int x, bool& exact) const {
00086 int xa = x / a;
00087 if (a * xa == x) {
00088 exact = true; return xa;
00089 } else {
00090 exact = false; return 0;
00091 }
00092 }
00093
00094 #endif
00095
00096
00097
00098
00099
00100
00101 template <class Val, class UnsVal>
00102 forceinline
00103 ScaleView<Val,UnsVal>::ScaleView(void) {}
00104
00105 template <class Val, class UnsVal>
00106 forceinline
00107 ScaleView<Val,UnsVal>::ScaleView(int b, const IntView& x)
00108 : DerivedViewBase<IntView>(x), a(b) {}
00109
00110 template <class Val, class UnsVal>
00111 forceinline
00112 ScaleView<Val,UnsVal>::ScaleView(Space* home,
00113 const Reflection::VarMap& vars,
00114 Reflection::Arg* arg)
00115 : DerivedViewBase<IntView>(IntView(home, vars, arg->second())),
00116 a(arg->first()->toInt()) {}
00117
00118 template <class Val, class UnsVal>
00119 forceinline void
00120 ScaleView<Val,UnsVal>::init(int b, const IntView& x) {
00121 view=x; a=b;
00122 }
00123
00124 template <class Val, class UnsVal>
00125 forceinline int
00126 ScaleView<Val,UnsVal>::scale(void) const {
00127 return a;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 template <class Val, class UnsVal>
00137 forceinline Val
00138 ScaleView<Val,UnsVal>::min(void) const {
00139 Val c = view.min(); c *= a; return c;
00140 }
00141
00142 template <class Val, class UnsVal>
00143 forceinline Val
00144 ScaleView<Val,UnsVal>::max(void) const {
00145 Val c = view.max(); c *= a; return c;
00146 }
00147
00148 template <class Val, class UnsVal>
00149 forceinline Val
00150 ScaleView<Val,UnsVal>::med(void) const {
00151 Val c = view.med(); c *= a; return c;
00152 }
00153
00154 template <class Val, class UnsVal>
00155 forceinline Val
00156 ScaleView<Val,UnsVal>::val(void) const {
00157 Val c = view.val(); c *= a; return c;
00158 }
00159
00160 template <class Val, class UnsVal>
00161 forceinline UnsVal
00162 ScaleView<Val,UnsVal>::size(void) const {
00163 return static_cast<UnsVal>(view.size());
00164 }
00165
00166 template <class Val, class UnsVal>
00167 forceinline UnsVal
00168 ScaleView<Val,UnsVal>::width(void) const {
00169 UnsVal c = view.width(); c *= a; return c;
00170 }
00171
00172 template <class Val, class UnsVal>
00173 forceinline UnsVal
00174 ScaleView<Val,UnsVal>::regret_min(void) const {
00175 UnsVal c = view.regret_min(); c *= a; return c;
00176 }
00177
00178 template <class Val, class UnsVal>
00179 forceinline UnsVal
00180 ScaleView<Val,UnsVal>::regret_max(void) const {
00181 UnsVal c = view.regret_max(); c *= a; return c;
00182 }
00183
00184
00185
00186
00187
00188
00189 template <class Val, class UnsVal>
00190 forceinline bool
00191 ScaleView<Val,UnsVal>::range(void) const {
00192 return view.range();
00193 }
00194
00195 template <class Val, class UnsVal>
00196 forceinline bool
00197 ScaleView<Val,UnsVal>::assigned(void) const {
00198 return view.assigned();
00199 }
00200
00201 template <class Val, class UnsVal>
00202 forceinline bool
00203 ScaleView<Val,UnsVal>::in(Val n) const {
00204 bool exact;
00205 int nda = exact_div(n, exact);
00206 return exact && view.in(nda);
00207 }
00208
00209
00210
00211
00212
00213
00214
00215
00216 template <class Val, class UnsVal>
00217 forceinline ModEvent
00218 ScaleView<Val,UnsVal>::lq(Space* home, Val n) {
00219 return (n >= max()) ? ME_INT_NONE : view.lq(home,floor_div(n));
00220 }
00221
00222 template <class Val, class UnsVal>
00223 forceinline ModEvent
00224 ScaleView<Val,UnsVal>::le(Space* home, Val n) {
00225 return (n > max()) ? ME_INT_NONE : view.le(home,floor_div(n));
00226 }
00227
00228 template <class Val, class UnsVal>
00229 forceinline ModEvent
00230 ScaleView<Val,UnsVal>::gq(Space* home, Val n) {
00231 return (n <= min()) ? ME_INT_NONE : view.gq(home,ceil_div(n));
00232 }
00233 template <class Val, class UnsVal>
00234 forceinline ModEvent
00235 ScaleView<Val,UnsVal>::gr(Space* home, Val n) {
00236 return (n < min()) ? ME_INT_NONE : view.gr(home,ceil_div(n));
00237 }
00238
00239 template <class Val, class UnsVal>
00240 forceinline ModEvent
00241 ScaleView<Val,UnsVal>::nq(Space* home, Val n) {
00242 bool exact;
00243 int nda = exact_div(n,exact);
00244 return exact ? view.nq(home,nda) : ME_INT_NONE;
00245 }
00246
00247 template <class Val, class UnsVal>
00248 forceinline ModEvent
00249 ScaleView<Val,UnsVal>::eq(Space* home, Val n) {
00250 bool exact;
00251 int nda = exact_div(n,exact);
00252 return exact ? view.eq(home,nda) : ME_INT_FAILED;
00253 }
00254
00255
00256
00257
00258
00259
00260 template <class Val, class UnsVal>
00261 forceinline void
00262 ScaleView<Val,UnsVal>::schedule(Space* home, Propagator* p, ModEvent me) {
00263 return IntView::schedule(home,p,me);
00264 }
00265 template <class Val, class UnsVal>
00266 forceinline ModEvent
00267 ScaleView<Val,UnsVal>::me(ModEventDelta med) {
00268 return IntView::me(med);
00269 }
00270
00271 template <class Val, class UnsVal>
00272 forceinline ModEventDelta
00273 ScaleView<Val,UnsVal>::med(ModEvent me) {
00274 return IntView::med(me);
00275 }
00276
00277
00278
00279
00280
00281
00282
00283 template <class Val, class UnsVal>
00284 forceinline void
00285 ScaleView<Val,UnsVal>::subscribe(Space* home, Propagator* p, PropCond pc,
00286 bool process) {
00287 view.subscribe(home,p,pc,process);
00288 }
00289 template <class Val, class UnsVal>
00290 forceinline void
00291 ScaleView<Val,UnsVal>::cancel(Space* home, Propagator* p, PropCond pc) {
00292 view.cancel(home,p,pc);
00293 }
00294 template <class Val, class UnsVal>
00295 forceinline void
00296 ScaleView<Val,UnsVal>::subscribe(Space* home, Advisor* a) {
00297 view.subscribe(home,a);
00298 }
00299 template <class Val, class UnsVal>
00300 forceinline void
00301 ScaleView<Val,UnsVal>::cancel(Space* home, Advisor* a) {
00302 view.cancel(home,a);
00303 }
00304
00305
00306
00307
00308
00309
00310 template <class Val, class UnsVal>
00311 forceinline ModEvent
00312 ScaleView<Val,UnsVal>::modevent(const Delta* d) {
00313 return IntView::modevent(d);
00314 }
00315 template <class Val, class UnsVal>
00316 forceinline Val
00317 ScaleView<Val,UnsVal>::min(const Delta* d) const {
00318 Val c = view.min(d); c *= a; return c;
00319 }
00320 template <class Val, class UnsVal>
00321 forceinline Val
00322 ScaleView<Val,UnsVal>::max(const Delta* d) const {
00323 Val c = view.max(d); c *= a; return c;
00324 }
00325 template <class Val, class UnsVal>
00326 forceinline bool
00327 ScaleView<Val,UnsVal>::any(const Delta* d) const {
00328 return view.any(d);
00329 }
00330
00331
00332
00333
00334
00335
00336
00337 template <class Val, class UnsVal>
00338 forceinline void
00339 ScaleView<Val,UnsVal>::update(Space* home, bool share,
00340 ScaleView<Val,UnsVal>& x) {
00341 a=x.a; view.update(home,share,x.view);
00342 }
00343
00344
00345
00346
00347
00348 template <class Val, class UnsVal>
00349 forceinline Reflection::Arg*
00350 ScaleView<Val,UnsVal>::spec(const Space* home,
00351 Reflection::VarMap& m) const {
00352 return Reflection::Arg::newPair(Reflection::Arg::newInt(a),
00353 view.spec(home, m));
00354 }
00355 template <class Val, class UnsVal>
00356 inline Support::Symbol
00357 ScaleView<Val,UnsVal>::type(void) {
00358 return Support::Symbol("Gecode::Int::ScaleView");
00359 }
00360
00361
00366 template <>
00367 class ViewRanges<IntScaleView>
00368 : public Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> > {
00369 public:
00371
00372
00373 ViewRanges(void);
00375 ViewRanges(const IntScaleView& x);
00377 void init(const IntScaleView& x);
00379 };
00380
00381 forceinline
00382 ViewRanges<IntScaleView>::ViewRanges(void) {}
00383 forceinline
00384 ViewRanges<IntScaleView>::ViewRanges(const IntScaleView& x) {
00385 ViewRanges<IntView> xi(x.base());
00386 Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init
00387 (xi,x.scale());
00388 }
00389 forceinline void
00390 ViewRanges<IntScaleView>::init(const IntScaleView& x) {
00391 ViewRanges<IntView> xi(x.base());
00392 Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init
00393 (xi,x.scale());
00394 }
00395
00396
00401 template <>
00402 class ViewRanges<DoubleScaleView>
00403 : public Iter::Ranges::ScaleUp<double,double,ViewRanges<IntView> > {
00404 public:
00406
00407
00408 ViewRanges(void);
00410 ViewRanges(const DoubleScaleView& x);
00412 void init(const DoubleScaleView& x);
00414 };
00415
00416 forceinline
00417 ViewRanges<DoubleScaleView>::ViewRanges(void) {}
00418 forceinline
00419 ViewRanges<DoubleScaleView>::ViewRanges(const DoubleScaleView& x) {
00420 ViewRanges<IntView> xi(x.base());
00421 Iter::Ranges::ScaleUp<double,double,ViewRanges<IntView> >::init
00422 (xi,x.scale());
00423 }
00424 forceinline void
00425 ViewRanges<DoubleScaleView>::init(const DoubleScaleView& x) {
00426 ViewRanges<IntView> xi(x.base());
00427 Iter::Ranges::ScaleUp<double,double,ViewRanges<IntView> >::init
00428 (xi,x.scale());
00429 }
00430
00431 }
00432
00433
00434
00435
00436
00437
00438
00439 template <class Val, class UnsVal>
00440 forceinline bool
00441 same(const Int::ScaleView<Val,UnsVal>& x,
00442 const Int::ScaleView<Val,UnsVal>& y) {
00443 return same(x.base(),y.base()) && (x.scale() == y.scale());
00444 }
00445 template <class Val, class UnsVal>
00446 forceinline bool
00447 before(const Int::ScaleView<Val,UnsVal>& x,
00448 const Int::ScaleView<Val,UnsVal>& y) {
00449 return before(x.base(),y.base())
00450 || (same(x.base(),y.base()) && (x.scale() < y.scale()));
00451 }
00452
00453 }
00454
00455
00456