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
00044 template<class View>
00045 class ConstView {
00046 public:
00048 typedef typename View::VarImpType VarImpType;
00050 typedef typename View::VarType VarType;
00052
00053
00054 unsigned int degree(void) const;
00056 double afc(void) const;
00058 static bool varderived(void);
00060 VarImpType* varimp(void) const;
00062
00064
00065
00066 bool assigned(void) const;
00068
00070
00071
00072 static void schedule(Space& home, Propagator& p, ModEvent me);
00074 static ModEvent me(const ModEventDelta& med);
00076 static ModEventDelta med(ModEvent me);
00078
00080
00081
00088 void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
00090 void cancel(Space& home, Propagator& p, PropCond pc);
00092 void reschedule(Space& home, Propagator& p, PropCond pc);
00098 void subscribe(Space& home, Advisor& a, bool fail=false);
00100 void cancel(Space& home, Advisor& a, bool fail=false);
00102
00104
00105
00106 static ModEvent modevent(const Delta& d);
00108
00110
00111
00112 void update(Space& home, bool share, ConstView& y);
00114 };
00115
00116
00117
00122 template<class Var>
00123 class VarImpView {
00124 public:
00126 typedef Var VarType;
00128 typedef typename Var::VarImpType VarImpType;
00129 protected:
00131 VarImpType* x;
00133 VarImpView(void);
00135 VarImpView(VarImpType* y);
00137 void varimp(VarImpType* y);
00138 public:
00140
00141
00142 static bool varderived(void);
00144 VarImpType* varimp(void) const;
00146 unsigned int degree(void) const;
00148 double afc(void) const;
00150
00152
00153
00154 bool assigned(void) const;
00156
00158
00159
00160 static void schedule(Space& home, Propagator& p, ModEvent me);
00162 static ModEvent me(const ModEventDelta& med);
00164 static ModEventDelta med(ModEvent me);
00166
00168
00169
00176 void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
00178 void cancel(Space& home, Propagator& p, PropCond pc);
00180 void reschedule(Space& home, Propagator& p, PropCond pc);
00186 void subscribe(Space& home, Advisor& a, bool fail=false);
00188 void cancel(Space& home, Advisor& a, bool fail=false);
00190
00192
00193
00194 static ModEvent modevent(const Delta& d);
00196
00198
00199
00200 void update(Space& home, bool share, VarImpView<Var>& y);
00202 };
00203
00208
00209 template<class VarA, class VarB>
00210 bool same(const VarImpView<VarA>& x, const VarImpView<VarB>& y);
00212 template<class ViewA, class ViewB>
00213 bool before(const ViewA& x, const ViewB& y);
00215
00216
00221 template<class View>
00222 class DerivedView {
00223 public:
00225 typedef typename View::VarImpType VarImpType;
00227 typedef typename View::VarType VarType;
00228 protected:
00230 View x;
00232 DerivedView(void);
00233 public:
00235 DerivedView(const View& y);
00237
00238
00239 static bool varderived(void);
00241 VarImpType* varimp(void) const;
00243 View base(void) const;
00245 unsigned int degree(void) const;
00247 double afc(void) const;
00249
00251
00252
00253 bool assigned(void) const;
00255
00257
00258
00259 static void schedule(Space& home, Propagator& p, ModEvent me);
00261 static ModEvent me(const ModEventDelta& med);
00263 static ModEventDelta med(ModEvent);
00265
00267
00268
00275 void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
00277 void cancel(Space& home, Propagator& p, PropCond pc);
00279 void reschedule(Space& home, Propagator& p, PropCond pc);
00285 void subscribe(Space& home, Advisor& a, bool fail=false);
00287 void cancel(Space& home, Advisor& a, bool fail=false);
00289
00291
00292
00293 static ModEvent modevent(const Delta& d);
00295
00297
00298
00299 void update(Space& home, bool share, DerivedView<View>& y);
00301 };
00302
00303
00308 template<class ViewA, class ViewB>
00309 bool shared(const ConstView<ViewA>&, const ConstView<ViewB>&);
00314 template<class Var, class View>
00315 bool shared(const VarImpView<Var>&, const ConstView<View>&);
00320 template<class ViewA, class ViewB>
00321 bool shared(const DerivedView<ViewA>&, const ConstView<ViewB>&);
00326 template<class View, class Var>
00327 bool shared(const ConstView<View>&, const VarImpView<Var>&);
00332 template<class ViewA, class ViewB>
00333 bool shared(const ConstView<ViewA>&, const DerivedView<ViewB>&);
00338 template<class VarA, class VarB>
00339 bool shared(const VarImpView<VarA>&, const VarImpView<VarB>&);
00344 template<class Var, class View>
00345 bool shared(const VarImpView<Var>&, const DerivedView<View>&);
00350 template<class View, class Var>
00351 bool shared(const DerivedView<View>&, const VarImpView<Var>&);
00356 template<class ViewA, class ViewB>
00357 bool shared(const DerivedView<ViewA>&, const DerivedView<ViewB>&);
00358
00359
00360
00361
00362
00363
00364 template<class View>
00365 forceinline unsigned int
00366 ConstView<View>::degree(void) const {
00367 return 0;
00368 }
00369 template<class View>
00370 forceinline double
00371 ConstView<View>::afc(void) const {
00372 return 0.0;
00373 }
00374 template<class View>
00375 forceinline bool
00376 ConstView<View>::varderived(void) {
00377 return false;
00378 }
00379 template<class View>
00380 forceinline typename View::VarImpType*
00381 ConstView<View>::varimp(void) const {
00382 return NULL;
00383 }
00384 template<class View>
00385 forceinline bool
00386 ConstView<View>::assigned(void) const {
00387 return true;
00388 }
00389 template<class View>
00390 forceinline void
00391 ConstView<View>::subscribe(Space& home, Propagator& p, PropCond,
00392 bool schedule) {
00393 if (schedule)
00394 View::schedule(home,p,ME_GEN_ASSIGNED);
00395 }
00396 template<class View>
00397 forceinline void
00398 ConstView<View>::cancel(Space&, Propagator&, PropCond) {
00399 }
00400 template<class View>
00401 forceinline void
00402 ConstView<View>::reschedule(Space& home, Propagator& p, PropCond) {
00403 View::schedule(home,p,ME_GEN_ASSIGNED);
00404 }
00405 template<class View>
00406 forceinline void
00407 ConstView<View>::subscribe(Space&, Advisor&, bool) {
00408 }
00409 template<class View>
00410 forceinline void
00411 ConstView<View>::cancel(Space&, Advisor&, bool) {
00412 }
00413 template<class View>
00414 forceinline void
00415 ConstView<View>::schedule(Space& home, Propagator& p, ModEvent me) {
00416 View::schedule(home,p,me);
00417 }
00418 template<class View>
00419 forceinline ModEvent
00420 ConstView<View>::me(const ModEventDelta& med) {
00421 return View::me(med);
00422 }
00423 template<class View>
00424 forceinline ModEventDelta
00425 ConstView<View>::med(ModEvent me) {
00426 return View::med(me);
00427 }
00428 template<class View>
00429 forceinline ModEvent
00430 ConstView<View>::modevent(const Delta& d) {
00431 (void) d;
00432 return ME_GEN_NONE;
00433 }
00434 template<class View>
00435 forceinline void
00436 ConstView<View>::update(Space&, bool, ConstView<View>&) {
00437 }
00438
00439
00440
00441
00442
00443 template<class Var>
00444 forceinline
00445 VarImpView<Var>::VarImpView(void)
00446 : x(NULL) {}
00447 template<class Var>
00448 forceinline
00449 VarImpView<Var>::VarImpView(VarImpType* y)
00450 : x(y) {}
00451 template<class Var>
00452 forceinline void
00453 VarImpView<Var>::varimp(VarImpType* y) {
00454 x=y;
00455 }
00456 template<class Var>
00457 forceinline bool
00458 VarImpView<Var>::varderived(void) {
00459 return true;
00460 }
00461 template<class Var>
00462 forceinline typename Var::VarImpType*
00463 VarImpView<Var>::varimp(void) const {
00464 return x;
00465 }
00466 template<class Var>
00467 forceinline unsigned int
00468 VarImpView<Var>::degree(void) const {
00469 return x->degree();
00470 }
00471 template<class Var>
00472 forceinline double
00473 VarImpView<Var>::afc(void) const {
00474 return x->afc();
00475 }
00476 template<class Var>
00477 forceinline bool
00478 VarImpView<Var>::assigned(void) const {
00479 return x->assigned();
00480 }
00481 template<class Var>
00482 forceinline void
00483 VarImpView<Var>::subscribe(Space& home, Propagator& p, PropCond pc,
00484 bool schedule) {
00485 x->subscribe(home,p,pc,schedule);
00486 }
00487 template<class Var>
00488 forceinline void
00489 VarImpView<Var>::cancel(Space& home, Propagator& p, PropCond pc) {
00490 x->cancel(home,p,pc);
00491 }
00492 template<class Var>
00493 forceinline void
00494 VarImpView<Var>::reschedule(Space& home, Propagator& p, PropCond pc) {
00495 x->reschedule(home,p,pc);
00496 }
00497 template<class Var>
00498 forceinline void
00499 VarImpView<Var>::subscribe(Space& home, Advisor& a, bool fail) {
00500 x->subscribe(home,a,fail);
00501 }
00502 template<class Var>
00503 forceinline void
00504 VarImpView<Var>::cancel(Space& home, Advisor& a, bool fail) {
00505 x->cancel(home,a,fail);
00506 }
00507 template<class Var>
00508 forceinline void
00509 VarImpView<Var>::schedule(Space& home, Propagator& p, ModEvent me) {
00510 VarImpType::schedule(home,p,me);
00511 }
00512 template<class Var>
00513 forceinline ModEvent
00514 VarImpView<Var>::me(const ModEventDelta& med) {
00515 return VarImpType::me(med);
00516 }
00517 template<class Var>
00518 forceinline ModEventDelta
00519 VarImpView<Var>::med(ModEvent me) {
00520 return VarImpType::med(me);
00521 }
00522 template<class Var>
00523 forceinline ModEvent
00524 VarImpView<Var>::modevent(const Delta& d) {
00525 return VarImpType::modevent(d);
00526 }
00527 template<class Var>
00528 forceinline void
00529 VarImpView<Var>::update(Space& home, bool share, VarImpView<Var>& y) {
00530 x = y.x->copy(home,share);
00531 }
00532
00533
00534
00535
00536
00537
00538 template<class View>
00539 forceinline
00540 DerivedView<View>::DerivedView(void) {}
00541
00542 template<class View>
00543 forceinline
00544 DerivedView<View>::DerivedView(const View& y)
00545 : x(y) {}
00546
00547 template<class View>
00548 forceinline bool
00549 DerivedView<View>::varderived(void) {
00550 return View::varderived();
00551 }
00552
00553 template<class View>
00554 forceinline typename View::VarImpType*
00555 DerivedView<View>::varimp(void) const {
00556 return x.varimp();
00557 }
00558
00559 template<class View>
00560 forceinline View
00561 DerivedView<View>::base(void) const {
00562 return x;
00563 }
00564
00565 template<class View>
00566 forceinline unsigned int
00567 DerivedView<View>::degree(void) const {
00568 return x.degree();
00569 }
00570 template<class View>
00571 forceinline double
00572 DerivedView<View>::afc(void) const {
00573 return x.afc();
00574 }
00575 template<class View>
00576 forceinline bool
00577 DerivedView<View>::assigned(void) const {
00578 return x.assigned();
00579 }
00580
00581 template<class View>
00582 forceinline void
00583 DerivedView<View>::schedule(Space& home, Propagator& p, ModEvent me) {
00584 return View::schedule(home,p,me);
00585 }
00586 template<class View>
00587 forceinline ModEvent
00588 DerivedView<View>::me(const ModEventDelta& med) {
00589 return View::me(med);
00590 }
00591 template<class View>
00592 forceinline ModEventDelta
00593 DerivedView<View>::med(ModEvent me) {
00594 return View::med(me);
00595 }
00596
00597 template<class View>
00598 forceinline void
00599 DerivedView<View>::subscribe(Space& home, Propagator& p, PropCond pc,
00600 bool schedule) {
00601 x.subscribe(home,p,pc,schedule);
00602 }
00603 template<class View>
00604 forceinline void
00605 DerivedView<View>::cancel(Space& home, Propagator& p, PropCond pc) {
00606 x.cancel(home,p,pc);
00607 }
00608 template<class View>
00609 forceinline void
00610 DerivedView<View>::reschedule(Space& home, Propagator& p, PropCond pc) {
00611 x.reschedule(home,p,pc);
00612 }
00613 template<class View>
00614 forceinline void
00615 DerivedView<View>::subscribe(Space& home, Advisor& a, bool fail) {
00616 x.subscribe(home,a,fail);
00617 }
00618 template<class View>
00619 forceinline void
00620 DerivedView<View>::cancel(Space& home, Advisor& a, bool fail) {
00621 x.cancel(home,a,fail);
00622 }
00623 template<class View>
00624 forceinline ModEvent
00625 DerivedView<View>::modevent(const Delta& d) {
00626 return View::modevent(d);
00627 }
00628 template<class View>
00629 forceinline void
00630 DerivedView<View>::update(Space& home, bool share, DerivedView<View>& y) {
00631 x.update(home,share,y.x);
00632 }
00633
00634
00635
00636
00637
00638
00639
00641 template<class ViewA, class ViewB>
00642 forceinline bool
00643 same(const ConstView<ViewA>&, const ConstView<ViewB>&) {
00644 return false;
00645 }
00647 template<class Var, class View>
00648 forceinline bool
00649 same(const VarImpView<Var>&, const ConstView<View>&) {
00650 return false;
00651 }
00653 template<class ViewA, class ViewB>
00654 forceinline bool
00655 same(const ConstView<ViewA>&, const DerivedView<ViewB>&) {
00656 return false;
00657 }
00659 template<class Var, class View>
00660 forceinline bool
00661 same(const VarImpView<Var>&, const DerivedView<View>&) {
00662 return false;
00663 }
00665 template<class View, class Var>
00666 forceinline bool
00667 same(const DerivedView<View>&, const VarImpView<Var>&) {
00668 return false;
00669 }
00671 template<class Var>
00672 forceinline bool
00673 same(const VarImpView<Var>& x, const VarImpView<Var>& y) {
00674 return x.varimp() == y.varimp();
00675 }
00677 template<class ViewA, class ViewB>
00678 forceinline bool
00679 same(const DerivedView<ViewA>& x, const DerivedView<ViewB>& y) {
00680 return same(x.base(),y.base());
00681 }
00682
00683
00684
00685
00686
00687
00688 template<class ViewA, class ViewB>
00689 forceinline bool
00690 before(const ViewA& x, const ViewB& y) {
00691 return x.varimp() < y.varimp();
00692 }
00693
00694
00695
00696
00697
00698
00699
00700 template<class ViewA, class ViewB>
00701 forceinline bool
00702 shared(const ConstView<ViewA>&, const ConstView<ViewB>&) {
00703 return false;
00704 }
00705 template<class Var, class View>
00706 forceinline bool
00707 shared(const VarImpView<Var>&, const ConstView<View>&) {
00708 return false;
00709 }
00710 template<class ViewA, class ViewB>
00711 forceinline bool
00712 shared(const DerivedView<ViewA>&, const ConstView<ViewB>&) {
00713 return false;
00714 }
00715 template<class View, class Var>
00716 forceinline bool
00717 shared(const ConstView<View>&, const VarImpView<Var>&) {
00718 return false;
00719 }
00720 template<class ViewA, class ViewB>
00721 forceinline bool
00722 shared(const ConstView<ViewA>&, const DerivedView<ViewB>&) {
00723 return false;
00724 }
00725 template<class VarA, class VarB>
00726 forceinline bool
00727 shared(const VarImpView<VarA>& x, const VarImpView<VarB>& y) {
00728 return (static_cast<VarImpBase*>(x.varimp()) ==
00729 static_cast<VarImpBase*>(y.varimp()));
00730 }
00731 template<class Var, class View>
00732 forceinline bool
00733 shared(const VarImpView<Var>& x, const DerivedView<View>& y) {
00734 return (View::varderived() &&
00735 static_cast<VarImpBase*>(x.varimp()) ==
00736 static_cast<VarImpBase*>(y.varimp()));
00737 }
00738 template<class View, class Var>
00739 forceinline bool
00740 shared(const DerivedView<View>& x, const VarImpView<Var>& y) {
00741 return (View::varderived() &&
00742 static_cast<VarImpBase*>(x.varimp()) ==
00743 static_cast<VarImpBase*>(y.varimp()));
00744 }
00745 template<class ViewA, class ViewB>
00746 forceinline bool
00747 shared(const DerivedView<ViewA>& x, const DerivedView<ViewB>& y) {
00748 return (ViewA::varderived() && ViewB::varderived() &&
00749 static_cast<VarImpBase*>(x.varimp()) ==
00750 static_cast<VarImpBase*>(y.varimp()));
00751 }
00752
00753 }
00754
00755