Generated on Mon Aug 25 11:35:35 2008 for Gecode by doxygen 1.5.6

eq.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2004
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-07-11 10:49:55 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00011  *     $Revision: 7348 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Int { namespace Rel {
00039 
00040   /*
00041    * Binary bounds consistent equality
00042    *
00043    */
00044 
00045   template <class View0, class View1>
00046   forceinline
00047   EqBnd<View0,View1>::EqBnd(Space* home, View0 x0, View1 x1)
00048     : MixBinaryPropagator<View0,PC_INT_BND,View1,PC_INT_BND>(home,x0,x1) {}
00049 
00050   template <class View0, class View1>
00051   ExecStatus
00052   EqBnd<View0,View1>::post(Space* home, View0 x0, View1 x1){
00053     if (x0.assigned()) {
00054       GECODE_ME_CHECK(x1.eq(home,x0.val()));
00055     } else if (x1.assigned()) {
00056       GECODE_ME_CHECK(x0.eq(home,x1.val()));
00057     } else if (!same(x0,x1)) {
00058       GECODE_ME_CHECK(x0.lq(home,x1.max()));
00059       GECODE_ME_CHECK(x1.lq(home,x0.max()));
00060       GECODE_ME_CHECK(x0.gq(home,x1.min()));
00061       GECODE_ME_CHECK(x1.gq(home,x0.min()));
00062       (void) new (home) EqBnd<View0,View1>(home,x0,x1);
00063     }
00064     return ES_OK;
00065   }
00066 
00067   template <class View0, class View1>
00068   forceinline
00069   EqBnd<View0,View1>::EqBnd(Space* home, bool share, EqBnd<View0,View1>& p)
00070     : MixBinaryPropagator<View0,PC_INT_BND,View1,PC_INT_BND>(home,share,p) {}
00071 
00072   template <class View0, class View1>
00073   forceinline
00074   EqBnd<View0,View1>::EqBnd(Space* home, bool share, Propagator& p,
00075                             View0 x0, View1 x1)
00076     : MixBinaryPropagator<View0,PC_INT_BND,View1,PC_INT_BND>(home,share,p,
00077                                                              x0,x1) {}
00078 
00079   template <class View0, class View1>
00080   Actor*
00081   EqBnd<View0,View1>::copy(Space* home, bool share) {
00082     return new (home) EqBnd<View0,View1>(home,share,*this);
00083   }
00084 
00085   template <class View0, class View1>
00086   inline Support::Symbol
00087   EqBnd<View0,View1>::ati(void) {
00088     return Reflection::mangle<View0,View1>("Gecode::Int::Rel::EqBnd");
00089   }
00090 
00091   template <class View0, class View1>
00092   Reflection::ActorSpec
00093   EqBnd<View0,View1>::spec(const Space* home, Reflection::VarMap& m) const {
00094     return MixBinaryPropagator<View0,PC_INT_BND,View1,PC_INT_BND>
00095       ::spec(home, m, ati());
00096   }
00097 
00098   template <class View0, class View1>
00099   void
00100   EqBnd<View0,View1>::post(Space* home, Reflection::VarMap& vars,
00101                            const Reflection::ActorSpec& spec) {
00102     spec.checkArity(2);
00103     View0 x0(home, vars, spec[0]);
00104     View1 x1(home, vars, spec[1]);
00105     (void) new (home) EqBnd<View0,View1>(home, x0, x1);
00106   } 
00107 
00108   template <class View0, class View1>
00109   ExecStatus
00110   EqBnd<View0,View1>::propagate(Space* home, ModEventDelta) {
00111     if (x0.assigned()) {
00112       GECODE_ME_CHECK(x1.eq(home,x0.val()));
00113     } else if (x1.assigned()) {
00114       GECODE_ME_CHECK(x0.eq(home,x1.val()));
00115     } else {
00116       do {
00117         GECODE_ME_CHECK(x0.gq(home,x1.min()));
00118         GECODE_ME_CHECK(x1.gq(home,x0.min()));
00119       } while (x0.min() != x1.min());
00120       do {
00121         GECODE_ME_CHECK(x0.lq(home,x1.max()));
00122         GECODE_ME_CHECK(x1.lq(home,x0.max()));
00123       } while (x0.max() != x1.max());
00124       if (!x0.assigned())
00125         return ES_FIX;
00126     }
00127     assert(x0.assigned() && x1.assigned());
00128     return ES_SUBSUMED(this,sizeof(*this));
00129   }
00130 
00131   /*
00132    * Binary domain consistent equality
00133    *
00134    */
00135 
00136   template <class View0, class View1>
00137   forceinline
00138   EqDom<View0,View1>::EqDom(Space* home, View0 x0, View1 x1)
00139     : MixBinaryPropagator<View0,PC_INT_DOM,View1,PC_INT_DOM>(home,x0,x1) {}
00140 
00141   template <class View0, class View1>
00142   ExecStatus
00143   EqDom<View0,View1>::post(Space* home, View0 x0, View1 x1){
00144     if (x0.assigned()) {
00145       GECODE_ME_CHECK(x1.eq(home,x0.val()));
00146     } else if (x1.assigned()) {
00147       GECODE_ME_CHECK(x0.eq(home,x1.val()));
00148     } else if (!same(x0,x1)) {
00149       GECODE_ME_CHECK(x0.lq(home,x1.max()));
00150       GECODE_ME_CHECK(x1.lq(home,x0.max()));
00151       GECODE_ME_CHECK(x0.gq(home,x1.min()));
00152       GECODE_ME_CHECK(x1.gq(home,x0.min()));
00153       (void) new (home) EqDom<View0,View1>(home,x0,x1);
00154     }
00155     return ES_OK;
00156   }
00157 
00158 
00159   template <class View0, class View1>
00160   forceinline
00161   EqDom<View0,View1>::EqDom(Space* home, bool share, EqDom<View0,View1>& p)
00162     : MixBinaryPropagator<View0,PC_INT_DOM,View1,PC_INT_DOM>(home,share,p) {}
00163 
00164   template <class View0, class View1>
00165   forceinline
00166   EqDom<View0,View1>::EqDom(Space* home, bool share, Propagator& p,
00167                             View0 x0, View1 x1)
00168     : MixBinaryPropagator<View0,PC_INT_DOM,View1,PC_INT_DOM>(home,share,p,
00169                                                              x0,x1) {}
00170 
00171   template <class View0, class View1>
00172   Actor*
00173   EqDom<View0,View1>::copy(Space* home, bool share) {
00174     return new (home) EqDom<View0,View1>(home,share,*this);
00175   }
00176 
00177   template <class View0, class View1>
00178   inline Support::Symbol
00179   EqDom<View0,View1>::ati(void) {
00180     return Reflection::mangle<View0,View1>("Gecode::Int::Rel::EqDom");
00181   }
00182 
00183   template <class View0, class View1>
00184   Reflection::ActorSpec
00185   EqDom<View0,View1>::spec(const Space* home, Reflection::VarMap& m) const {
00186     return MixBinaryPropagator<View0,PC_INT_DOM,View1,PC_INT_DOM>
00187       ::spec(home, m, ati());
00188   }
00189 
00190   template <class View0, class View1>
00191   void
00192   EqDom<View0,View1>::post(Space* home, Reflection::VarMap& vars,
00193                            const Reflection::ActorSpec& spec) {
00194     spec.checkArity(2);
00195     View0 x0(home, vars, spec[0]);
00196     View1 x1(home, vars, spec[1]);
00197     (void) new (home) EqDom<View0,View1>(home, x0, x1);
00198   } 
00199 
00200   template <class View0, class View1>
00201   PropCost
00202   EqDom<View0,View1>::cost(ModEventDelta med) const {
00203     if ((View0::me(med) == ME_INT_VAL) || (View1::me(med) == ME_INT_VAL))
00204       return PC_UNARY_LO;
00205     if ((View0::me(med) == ME_INT_DOM) || (View1::me(med) == ME_INT_DOM))
00206       return PC_BINARY_HI;
00207     return PC_BINARY_LO;
00208   }
00209 
00210   template <class View0, class View1>
00211   ExecStatus
00212   EqDom<View0,View1>::propagate(Space* home, ModEventDelta med) {
00213     if (x0.assigned()) {
00214       GECODE_ME_CHECK(x1.eq(home,x0.val()));
00215       return ES_SUBSUMED(this,sizeof(*this));
00216     }
00217     if (x1.assigned()) {
00218       GECODE_ME_CHECK(x0.eq(home,x1.val()));
00219       return ES_SUBSUMED(this,sizeof(*this));
00220     }
00221     if ((View0::me(med) != ME_INT_DOM) && (View1::me(med) != ME_INT_DOM)) {
00222       do {
00223         GECODE_ME_CHECK(x0.gq(home,x1.min()));
00224         GECODE_ME_CHECK(x1.gq(home,x0.min()));
00225       } while (x0.min() != x1.min());
00226       do {
00227         GECODE_ME_CHECK(x0.lq(home,x1.max()));
00228         GECODE_ME_CHECK(x1.lq(home,x0.max()));
00229       } while (x0.max() != x1.max());
00230       if (x0.assigned())
00231         return ES_SUBSUMED(this,sizeof(*this));
00232       if (x0.range() && x1.range())
00233         return ES_FIX;
00234       return ES_FIX_PARTIAL(this,View0::med(ME_INT_DOM));
00235     }
00236     ViewRanges<View0> r0(x0);
00237     GECODE_ME_CHECK(x1.inter_r(home,r0,false));
00238     ViewRanges<View1> r1(x1);
00239     GECODE_ME_CHECK(x0.narrow_r(home,r1,false));
00240     if (x0.assigned())
00241       return ES_SUBSUMED(this,sizeof(*this));
00242     return ES_FIX;
00243   }
00244 
00245 
00246 
00247   /*
00248    * Nary domain consistent equality
00249    *
00250    */
00251 
00252   template <class View>
00253   forceinline
00254   NaryEqDom<View>::NaryEqDom(Space* home, ViewArray<View>& x)
00255     : NaryPropagator<View,PC_INT_DOM>(home,x) {}
00256 
00257   template <class View>
00258   ExecStatus
00259   NaryEqDom<View>::post(Space* home, ViewArray<View>& x) {
00260     x.unique();
00261     if (x.size() == 2) {
00262       return EqDom<View,View>::post(home,x[0],x[1]);
00263     } else if (x.size() > 2) {
00264       int l = x[0].min();
00265       int u = x[0].max();
00266       for (int i=x.size(); i-- > 1; ) {
00267         l = std::max(l,x[i].min());
00268         u = std::min(u,x[i].max());
00269       }
00270       for (int i=x.size(); i--; ) {
00271         GECODE_ME_CHECK(x[i].gq(home,l));
00272         GECODE_ME_CHECK(x[i].lq(home,u));
00273       }
00274       (void) new (home) NaryEqDom<View>(home,x);
00275     }
00276     return ES_OK;
00277   }
00278 
00279   template <class View>
00280   forceinline
00281   NaryEqDom<View>::NaryEqDom(Space* home, bool share, NaryEqDom<View>& p)
00282     : NaryPropagator<View,PC_INT_DOM>(home,share,p) {}
00283 
00284   template <class View>
00285   Actor*
00286   NaryEqDom<View>::copy(Space* home, bool share) {
00287     return new (home) NaryEqDom<View>(home,share,*this);
00288   }
00289 
00290   template <class View>
00291   inline Support::Symbol
00292   NaryEqDom<View>::ati(void) {
00293     return Reflection::mangle<View>("Gecode::Int::Rel::NaryEqDom");
00294   }
00295 
00296   template <class View>
00297   Reflection::ActorSpec
00298   NaryEqDom<View>::spec(const Space* home, Reflection::VarMap& m) const {
00299     return NaryPropagator<View,PC_INT_DOM>
00300       ::spec(home, m, ati());
00301   }
00302 
00303   template <class View>
00304   void
00305   NaryEqDom<View>::post(Space* home, Reflection::VarMap& vars,
00306                         const Reflection::ActorSpec& spec) {
00307     spec.checkArity(1);
00308     ViewArray<View> x(home, vars, spec[0]);
00309     (void) new (home) NaryEqDom<View>(home, x);
00310   }
00311 
00312   template <class View>
00313   PropCost
00314   NaryEqDom<View>::cost(ModEventDelta med) const {
00315     if (View::me(med) == ME_INT_VAL)
00316       return PC_UNARY_LO;
00317     if (View::me(med) == ME_INT_DOM)
00318       return cost_hi(x.size(),PC_LINEAR_HI);
00319     return cost_lo(x.size(),PC_LINEAR_LO);
00320   }
00321 
00322   template <class View>
00323   ExecStatus
00324   NaryEqDom<View>::propagate(Space* home, ModEventDelta med) {
00325     assert(x.size() > 2);
00326 
00327     ModEvent me = View::me(med);
00328     if (me == ME_INT_VAL) {
00329       // One of the variables is assigned
00330       for (int i = 0; ; i++)
00331         if (x[i].assigned()) {
00332           int n = x[i].val();
00333           x.move_lst(i);
00334           for (int j = x.size(); j--; )
00335             GECODE_ME_CHECK(x[j].eq(home,n));
00336           return ES_SUBSUMED(this,sizeof(*this));
00337         }
00338       GECODE_NEVER;
00339       return ES_SUBSUMED(this,sizeof(*this));
00340     }
00341 
00342     if (me == ME_INT_BND) {
00343       {
00344         // One of the mins has changed
00345         int mn = x[0].min();
00346       restart_min:
00347         for (int i = x.size(); i--; ) {
00348           GECODE_ME_CHECK(x[i].gq(home,mn));
00349           if (mn < x[i].min()) {
00350             mn = x[i].min();
00351             goto restart_min;
00352           }
00353         }
00354       }
00355       {
00356         // One of the maxs has changed
00357         int mx = x[0].max();
00358       restart_max:
00359         for (int i = x.size(); i--; ) {
00360           GECODE_ME_CHECK(x[i].lq(home,mx));
00361           if (mx > x[i].max()) {
00362             mx = x[i].max();
00363             goto restart_max;
00364           }
00365         }
00366       }
00367       if (x[0].assigned())
00368         return ES_SUBSUMED(this,sizeof(*this));
00369       return ES_FIX_PARTIAL(this,View::med(ME_INT_DOM));
00370     }
00371 
00372     int n = x.size();
00373 
00374     GECODE_AUTOARRAY(ViewRanges<View>, i_x, n);
00375     for (int i = n; i--; ) {
00376       ViewRanges<View> i_xi(x[i]);
00377       i_x[i] = i_xi;
00378     }
00379     Iter::Ranges::NaryInter<ViewRanges<View> > r(i_x,n);
00380     Iter::Ranges::Cache<Iter::Ranges::NaryInter<ViewRanges<View> > > rc(r);
00381 
00382     if (!rc())
00383       return ES_FAILED;
00384     ++rc;
00385     if (!rc()) {
00386       rc.reset();
00387       for (int i = n; i--; ) {
00388         GECODE_ME_CHECK(x[i].gq(home,rc.min()));
00389         GECODE_ME_CHECK(x[i].lq(home,rc.max()));
00390       }
00391     } else {
00392       for (int i = n; i--; ) {
00393         rc.reset();
00394         GECODE_ME_CHECK(x[i].narrow_r(home,rc,false));
00395       }
00396     }
00397     return ES_FIX;
00398   }
00399 
00400 
00401 
00402   /*
00403    * Nary bound consistent equality
00404    *
00405    */
00406 
00407   template <class View>
00408   forceinline
00409   NaryEqBnd<View>::NaryEqBnd(Space* home, ViewArray<View>& x)
00410     : NaryPropagator<View,PC_INT_BND>(home,x) {}
00411 
00412   template <class View>
00413   ExecStatus
00414   NaryEqBnd<View>::post(Space* home, ViewArray<View>& x) {
00415     if (x.size() == 2) {
00416       return EqBnd<View,View>::post(home,x[0],x[1]);
00417     } else if (x.size() > 2) {
00418       int l = x[0].min();
00419       int u = x[0].max();
00420       for (int i=x.size(); i-- > 1; ) {
00421         l = std::max(l,x[i].min());
00422         u = std::min(u,x[i].max());
00423       }
00424       for (int i=x.size(); i--; ) {
00425         GECODE_ME_CHECK(x[i].gq(home,l));
00426         GECODE_ME_CHECK(x[i].lq(home,u));
00427       }
00428       (void) new (home) NaryEqBnd<View>(home,x);
00429     }
00430     return ES_OK;
00431   }
00432 
00433   template <class View>
00434   forceinline
00435   NaryEqBnd<View>::NaryEqBnd(Space* home, bool share, NaryEqBnd<View>& p)
00436     : NaryPropagator<View,PC_INT_BND>(home,share,p) {}
00437 
00438   template <class View>
00439   Actor*
00440   NaryEqBnd<View>::copy(Space* home, bool share) {
00441     return new (home) NaryEqBnd<View>(home,share,*this);
00442   }
00443 
00444   template <class View>
00445   PropCost
00446   NaryEqBnd<View>::cost(ModEventDelta med) const {
00447     if (View::me(med) == ME_INT_VAL)
00448       return PC_UNARY_LO;
00449     return cost_lo(x.size(),PC_LINEAR_LO);
00450   }
00451 
00452   template <class View>
00453   inline Support::Symbol
00454   NaryEqBnd<View>::ati(void) {
00455     return Reflection::mangle<View>("Gecode::Int::Rel::NaryEqBnd");
00456   }
00457 
00458   template <class View>
00459   Reflection::ActorSpec
00460   NaryEqBnd<View>::spec(const Space* home, Reflection::VarMap& m) const {
00461     return NaryPropagator<View,PC_INT_BND>
00462       ::spec(home, m, ati());
00463   }
00464 
00465   template <class View>
00466   void
00467   NaryEqBnd<View>::post(Space* home, Reflection::VarMap& vars,
00468                         const Reflection::ActorSpec& spec) {
00469     spec.checkArity(1);
00470     ViewArray<View> x(home, vars, spec[0]);
00471     (void) new (home) NaryEqBnd<View>(home, x);
00472   }
00473 
00474   template <class View>
00475   ExecStatus
00476   NaryEqBnd<View>::propagate(Space* home, ModEventDelta med) {
00477     assert(x.size() > 2);
00478     if (View::me(med) == ME_INT_VAL) {
00479       // One of the variables is assigned
00480       for (int i = 0; ; i++)
00481         if (x[i].assigned()) {
00482           int n = x[i].val();
00483           x.move_lst(i);
00484           for (int j = x.size(); j--; )
00485             GECODE_ME_CHECK(x[j].eq(home,n));
00486           return ES_SUBSUMED(this,sizeof(*this));
00487         }
00488       GECODE_NEVER;
00489       return ES_SUBSUMED(this,sizeof(*this));
00490     }
00491 
00492     int mn = x[0].min();
00493   restart_min:
00494     for (int i = x.size(); i--; ) {
00495       GECODE_ME_CHECK(x[i].gq(home,mn));
00496       if (mn < x[i].min()) {
00497         mn = x[i].min();
00498         goto restart_min;
00499       }
00500     }
00501     int mx = x[0].max();
00502   restart_max:
00503     for (int i = x.size(); i--; ) {
00504       GECODE_ME_CHECK(x[i].lq(home,mx));
00505       if (mx > x[i].max()) {
00506         mx = x[i].max();
00507         goto restart_max;
00508       }
00509     }
00510     return x[0].assigned() ? ES_SUBSUMED(this,sizeof(*this)) : ES_FIX;
00511   }
00512 
00513 
00514 
00515   /*
00516    * Reified domain consistent equality
00517    *
00518    */
00519 
00520   template <class View, class CtrlView>
00521   forceinline
00522   ReEqDom<View,CtrlView>::ReEqDom(Space* home, View x0, View x1, CtrlView b)
00523     : ReBinaryPropagator<View,PC_INT_DOM,CtrlView>(home,x0,x1,b) {}
00524 
00525   template <class View, class CtrlView>
00526   ExecStatus
00527   ReEqDom<View,CtrlView>::post(Space* home, View x0, View x1, CtrlView b) {
00528     if (b.one())
00529       return EqDom<View,View>::post(home,x0,x1);
00530     if (b.zero())
00531       return Nq<View>::post(home,x0,x1);
00532     if (!same(x0,x1)) {
00533       (void) new (home) ReEqDom(home,x0,x1,b);
00534     } else {
00535       GECODE_ME_CHECK(b.one(home));
00536     }
00537     return ES_OK;
00538   }
00539 
00540 
00541   template <class View, class CtrlView>
00542   forceinline
00543   ReEqDom<View,CtrlView>::ReEqDom(Space* home, bool share, ReEqDom& p)
00544     : ReBinaryPropagator<View,PC_INT_DOM,CtrlView>(home,share,p) {}
00545 
00546   template <class View, class CtrlView>
00547   Actor*
00548   ReEqDom<View,CtrlView>::copy(Space* home, bool share) {
00549     return new (home) ReEqDom<View,CtrlView>(home,share,*this);
00550   }
00551 
00552   template <class View, class CtrlView>
00553   inline Support::Symbol
00554   ReEqDom<View,CtrlView>::ati(void) {
00555     return Reflection::mangle<View,CtrlView>("Gecode::Int::Rel::ReEqDom");
00556   }
00557 
00558   template <class View, class CtrlView>
00559   Reflection::ActorSpec
00560   ReEqDom<View,CtrlView>::spec(const Space* home,
00561                                Reflection::VarMap& m) const {
00562     return ReBinaryPropagator<View,PC_INT_DOM,CtrlView>
00563       ::spec(home, m, ati());
00564   }
00565 
00566   template <class View, class CtrlView>
00567   void
00568   ReEqDom<View,CtrlView>::post(Space* home, Reflection::VarMap& vars,
00569                                const Reflection::ActorSpec& spec) {
00570     spec.checkArity(3);
00571     View x0(home, vars, spec[0]);
00572     View x1(home, vars, spec[1]);
00573     CtrlView b(home, vars, spec[2]);
00574     (void) new (home) ReEqDom<View,CtrlView>(home, x0, x1, b);
00575   }
00576 
00577   template <class View, class CtrlView>
00578   ExecStatus
00579   ReEqDom<View,CtrlView>::propagate(Space* home, ModEventDelta) {
00580     if (b.one())
00581       GECODE_REWRITE(this,(EqDom<View,View>::post(home,x0,x1)));
00582     if (b.zero())
00583       GECODE_REWRITE(this,Nq<View>::post(home,x0,x1));
00584     switch (rtest_eq_dom(x0,x1)) {
00585     case RT_TRUE:
00586       GECODE_ME_CHECK(b.one_none(home)); return ES_SUBSUMED(this,home);
00587     case RT_FALSE:
00588       GECODE_ME_CHECK(b.zero_none(home)); return ES_SUBSUMED(this,home);
00589     case RT_MAYBE:
00590       break;
00591     default: GECODE_NEVER;
00592     }
00593     return ES_FIX;
00594   }
00595 
00596 
00597 
00598   /*
00599    * Reified bounds consistent equality
00600    *
00601    */
00602 
00603   template <class View, class CtrlView>
00604   forceinline
00605   ReEqBnd<View,CtrlView>::ReEqBnd(Space* home, View x0, View x1, CtrlView b)
00606     : ReBinaryPropagator<View,PC_INT_BND,CtrlView>(home,x0,x1,b) {}
00607 
00608   template <class View, class CtrlView>
00609   ExecStatus
00610   ReEqBnd<View,CtrlView>::post(Space* home, View x0, View x1, CtrlView b){
00611     if (b.one())
00612       return EqBnd<View,View>::post(home,x0,x1);
00613     if (b.zero())
00614       return Nq<View>::post(home,x0,x1);
00615     if (!same(x0,x1)) {
00616       (void) new (home) ReEqBnd(home,x0,x1,b);
00617     } else {
00618       GECODE_ME_CHECK(b.one(home));
00619     }
00620     return ES_OK;
00621   }
00622 
00623 
00624   template <class View, class CtrlView>
00625   forceinline
00626   ReEqBnd<View,CtrlView>::ReEqBnd(Space* home, bool share, ReEqBnd& p)
00627     : ReBinaryPropagator<View,PC_INT_BND,CtrlView>(home,share,p) {}
00628 
00629   template <class View, class CtrlView>
00630   Actor*
00631   ReEqBnd<View,CtrlView>::copy(Space* home, bool share) {
00632     return new (home) ReEqBnd<View,CtrlView>(home,share,*this);
00633   }
00634 
00635   template <class View, class CtrlView>
00636   inline Support::Symbol
00637   ReEqBnd<View,CtrlView>::ati(void) {
00638     return Reflection::mangle<View,CtrlView>("Gecode::Int::Rel::ReEqBnd");
00639   }
00640 
00641   template <class View, class CtrlView>
00642   Reflection::ActorSpec
00643   ReEqBnd<View,CtrlView>::spec(const Space* home,
00644                                Reflection::VarMap& m) const {
00645     return ReBinaryPropagator<View,PC_INT_BND,CtrlView>
00646       ::spec(home, m, ati());
00647   }
00648 
00649   template <class View, class CtrlView>
00650   void
00651   ReEqBnd<View,CtrlView>::post(Space* home, Reflection::VarMap& vars,
00652                                const Reflection::ActorSpec& spec) {
00653     spec.checkArity(3);
00654     View x0(home, vars, spec[0]);
00655     View x1(home, vars, spec[1]);
00656     CtrlView b(home, vars, spec[2]);
00657     (void) new (home) ReEqBnd<View,CtrlView>(home, x0, x1, b);
00658   }
00659 
00660   template <class View, class CtrlView>
00661   ExecStatus
00662   ReEqBnd<View,CtrlView>::propagate(Space* home, ModEventDelta) {
00663     if (b.one())
00664       GECODE_REWRITE(this,(EqBnd<View,View>::post(home,x0,x1)));
00665     if (b.zero())
00666       GECODE_REWRITE(this,Nq<View>::post(home,x0,x1));
00667     switch (rtest_eq_bnd(x0,x1)) {
00668     case RT_TRUE:
00669       GECODE_ME_CHECK(b.one_none(home));  return ES_SUBSUMED(this,home);
00670     case RT_FALSE:
00671       GECODE_ME_CHECK(b.zero_none(home)); return ES_SUBSUMED(this,home);
00672     case RT_MAYBE:
00673       break;
00674     default: GECODE_NEVER;
00675     }
00676     return ES_FIX;
00677   }
00678 
00679 
00680 
00681 
00682   /*
00683    * Reified domain consistent equality (one variable)
00684    *
00685    */
00686 
00687   template <class View, class CtrlView>
00688   forceinline
00689   ReEqDomInt<View,CtrlView>::ReEqDomInt
00690   (Space* home, View x, int c0, CtrlView b)
00691     : ReUnaryPropagator<View,PC_INT_DOM,CtrlView>(home,x,b), c(c0) {}
00692 
00693   template <class View, class CtrlView>
00694   ExecStatus
00695   ReEqDomInt<View,CtrlView>::post(Space* home, View x, int c, CtrlView b) {
00696     if (b.one()) {
00697       GECODE_ME_CHECK(x.eq(home,c));
00698     } else if (b.zero()) {
00699       GECODE_ME_CHECK(x.nq(home,c));
00700     } else if (x.assigned()) {
00701       assert(b.none());
00702       if (x.val() == c) {
00703         GECODE_ME_CHECK(b.one_none(home));
00704       } else {
00705         GECODE_ME_CHECK(b.zero_none(home));
00706       }
00707     } else {
00708       (void) new (home) ReEqDomInt(home,x,c,b);        
00709     }
00710     return ES_OK;
00711   }
00712 
00713 
00714   template <class View, class CtrlView>
00715   forceinline
00716   ReEqDomInt<View,CtrlView>::ReEqDomInt(Space* home, bool share, ReEqDomInt& p)
00717     : ReUnaryPropagator<View,PC_INT_DOM,CtrlView>(home,share,p), c(p.c) {}
00718 
00719   template <class View, class CtrlView>
00720   Actor*
00721   ReEqDomInt<View,CtrlView>::copy(Space* home, bool share) {
00722     return new (home) ReEqDomInt<View,CtrlView>(home,share,*this);
00723   }
00724 
00725   template <class View, class CtrlView>
00726   inline Support::Symbol
00727   ReEqDomInt<View,CtrlView>::ati(void) {
00728     return Reflection::mangle<View,CtrlView>("Gecode::Int::Rel::ReEqDomInt");
00729   }
00730 
00731   template <class View, class CtrlView>
00732   Reflection::ActorSpec
00733   ReEqDomInt<View,CtrlView>::spec(const Space* home,
00734                                   Reflection::VarMap& m) const {
00735     return ReUnaryPropagator<View,PC_INT_DOM,CtrlView>
00736       ::spec(home, m, ati()) << c;
00737   }
00738 
00739   template <class View, class CtrlView>
00740   void
00741   ReEqDomInt<View,CtrlView>::post(Space* home, Reflection::VarMap& vars,
00742                                   const Reflection::ActorSpec& spec) {
00743     spec.checkArity(3);
00744     View x0(home, vars, spec[0]);
00745     CtrlView b(home, vars, spec[1]);
00746     int c = spec[2]->toInt();
00747     (void) new (home) ReEqDomInt<View,CtrlView>(home, x0, c, b);
00748   }
00749 
00750   template <class View, class CtrlView>
00751   ExecStatus
00752   ReEqDomInt<View,CtrlView>::propagate(Space* home, ModEventDelta) {
00753     if (b.one()) {
00754       GECODE_ME_CHECK(x0.eq(home,c)); 
00755       assert(x0.assigned());
00756       goto subsumed;
00757     }
00758     if (b.zero()) {
00759       GECODE_ME_CHECK(x0.nq(home,c)); 
00760       x0.cancel(home,this,PC_INT_DOM);
00761       goto subsumed;
00762     }
00763     switch (rtest_eq_dom(x0,c)) {
00764     case RT_TRUE:
00765       GECODE_ME_CHECK(b.one_none(home)); 
00766       assert(x0.assigned());
00767       goto subsumed;
00768     case RT_FALSE:
00769       GECODE_ME_CHECK(b.zero_none(home)); 
00770       x0.cancel(home,this,PC_INT_DOM);
00771       goto subsumed;
00772     case RT_MAYBE:
00773       break;
00774     default: GECODE_NEVER;
00775     }
00776     return ES_FIX;
00777   subsumed:
00778     return ES_SUBSUMED(this,sizeof(*this));    
00779   }
00780 
00781 
00782 
00783 
00784   /*
00785    * Reified bounds consistent equality (one variable)
00786    *
00787    */
00788 
00789   template <class View, class CtrlView>
00790   forceinline
00791   ReEqBndInt<View,CtrlView>::ReEqBndInt
00792   (Space* home, View x, int c0, CtrlView b)
00793     : ReUnaryPropagator<View,PC_INT_BND,CtrlView>(home,x,b), c(c0) {}
00794 
00795   template <class View, class CtrlView>
00796   ExecStatus
00797   ReEqBndInt<View,CtrlView>::post(Space* home, View x, int c, CtrlView b) {
00798     if (b.one()) {
00799       GECODE_ME_CHECK(x.eq(home,c));
00800     } else if (b.zero()) {
00801       GECODE_ME_CHECK(x.nq(home,c));
00802     } else if (x.assigned()) {
00803       assert(b.none());
00804       if (x.val() == c) {
00805         GECODE_ME_CHECK(b.one_none(home));
00806       } else {
00807         GECODE_ME_CHECK(b.zero_none(home));
00808       }
00809     } else {
00810       (void) new (home) ReEqBndInt(home,x,c,b);        
00811     }
00812     return ES_OK;
00813   }
00814 
00815 
00816   template <class View, class CtrlView>
00817   forceinline
00818   ReEqBndInt<View,CtrlView>::ReEqBndInt(Space* home, bool share, ReEqBndInt& p)
00819     : ReUnaryPropagator<View,PC_INT_BND,CtrlView>(home,share,p), c(p.c) {}
00820 
00821   template <class View, class CtrlView>
00822   Actor*
00823   ReEqBndInt<View,CtrlView>::copy(Space* home, bool share) {
00824     return new (home) ReEqBndInt<View,CtrlView>(home,share,*this);
00825   }
00826 
00827   template <class View, class CtrlView>
00828   inline Support::Symbol
00829   ReEqBndInt<View,CtrlView>::ati(void) {
00830     return Reflection::mangle<View,CtrlView>("Gecode::Int::Rel::ReEqBndInt");
00831   }
00832 
00833   template <class View, class CtrlView>
00834   Reflection::ActorSpec
00835   ReEqBndInt<View,CtrlView>::spec(const Space* home,
00836                                   Reflection::VarMap& m) const {
00837     return ReUnaryPropagator<View,PC_INT_BND,CtrlView>
00838       ::spec(home, m, ati()) << c;
00839   }
00840 
00841   template <class View, class CtrlView>
00842   void
00843   ReEqBndInt<View,CtrlView>::post(Space* home, Reflection::VarMap& vars,
00844                                   const Reflection::ActorSpec& spec) {
00845     spec.checkArity(3);
00846     View x0(home, vars, spec[0]);
00847     CtrlView b(home, vars, spec[1]);
00848     int c = spec[2]->toInt();
00849     (void) new (home) ReEqBndInt<View,CtrlView>(home, x0, c, b);
00850   }
00851 
00852   template <class View, class CtrlView>
00853   ExecStatus
00854   ReEqBndInt<View,CtrlView>::propagate(Space* home, ModEventDelta) {
00855     if (b.one()) {
00856       GECODE_ME_CHECK(x0.eq(home,c)); 
00857       assert(x0.assigned());
00858       goto subsumed;
00859     }
00860     if (b.zero()) {
00861       GECODE_ME_CHECK(x0.nq(home,c)); 
00862       x0.cancel(home,this,PC_INT_BND);
00863       goto subsumed;
00864     }
00865     switch (rtest_eq_bnd(x0,c)) {
00866     case RT_TRUE:
00867       GECODE_ME_CHECK(b.one_none(home)); 
00868       assert(x0.assigned());
00869       goto subsumed;
00870     case RT_FALSE:
00871       GECODE_ME_CHECK(b.zero_none(home)); 
00872       x0.cancel(home,this,PC_INT_BND);
00873       goto subsumed;
00874     case RT_MAYBE:
00875       break;
00876     default: GECODE_NEVER;
00877     }
00878     return ES_FIX;
00879   subsumed:
00880     return ES_SUBSUMED(this,sizeof(*this));
00881   }
00882 
00883 }}}
00884 
00885 // STATISTICS: int-prop