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

lq-le.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  *     Gabor Szokoli <szokoli@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2003
00009  *     Gabor Szokoli, 2003
00010  *
00011  *  Last modified:
00012  *     $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00013  *     $Revision: 6017 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 namespace Gecode { namespace Int { namespace Rel {
00041 
00042   /*
00043    * Less or equal propagator
00044    *
00045    */
00046 
00047   template <class View>
00048   forceinline
00049   Lq<View>::Lq(Space* home, View x0, View x1)
00050     : BinaryPropagator<View,PC_INT_BND>(home,x0,x1) {}
00051 
00052   template <class View>
00053   ExecStatus
00054   Lq<View>::post(Space* home, View x0, View x1) {
00055     GECODE_ME_CHECK(x0.lq(home,x1.max()));
00056     GECODE_ME_CHECK(x1.gq(home,x0.min()));
00057     if (!same(x0,x1) && (x0.max() > x1.min()))
00058       (void) new (home) Lq<View>(home,x0,x1);
00059     return ES_OK;
00060   }
00061 
00062   template <class View>
00063   forceinline
00064   Lq<View>::Lq(Space* home, bool share, Lq<View>& p)
00065     : BinaryPropagator<View,PC_INT_BND>(home,share,p) {}
00066 
00067   template <class View>
00068   Actor*
00069   Lq<View>::copy(Space* home, bool share) {
00070     return new (home) Lq<View>(home,share,*this);
00071   }
00072 
00073   template <class View>
00074   inline Support::Symbol
00075   Lq<View>::ati(void) {
00076     return Reflection::mangle<View>("Gecode::Int::Rel::Lq");
00077   }
00078 
00079   template <class View>
00080   Reflection::ActorSpec
00081   Lq<View>::spec(const Space* home, Reflection::VarMap& m) const {
00082     return BinaryPropagator<View,PC_INT_BND>::spec(home, m, ati());
00083   }
00084 
00085   template <class View>
00086   void
00087   Lq<View>::post(Space* home, Reflection::VarMap& vars,
00088                  const Reflection::ActorSpec& spec) {
00089     spec.checkArity(2);
00090     View x0(home, vars, spec[0]);
00091     View x1(home, vars, spec[1]);
00092     (void) new (home) Lq<View>(home, x0, x1);
00093   }
00094 
00095   template <class View>
00096   ExecStatus
00097   Lq<View>::propagate(Space* home, ModEventDelta) {
00098     GECODE_ME_CHECK(x0.lq(home,x1.max()));
00099     GECODE_ME_CHECK(x1.gq(home,x0.min()));
00100     return (x0.max() <= x1.min()) ? ES_SUBSUMED(this,home) : ES_FIX;
00101   }
00102 
00103 
00104 
00105 
00106   /*
00107    * Less propagator
00108    *
00109    */
00110   template <class View>
00111   forceinline
00112   Le<View>::Le(Space* home, View x0, View x1)
00113     : BinaryPropagator<View,PC_INT_BND>(home,x0,x1) {}
00114 
00115   template <class View>
00116   ExecStatus
00117   Le<View>::post(Space* home, View x0, View x1) {
00118     if (same(x0,x1))
00119       return ES_FAILED;
00120     GECODE_ME_CHECK(x0.le(home,x1.max()));
00121     GECODE_ME_CHECK(x1.gr(home,x0.min()));
00122     if (x0.max() >= x1.min())
00123       (void) new (home) Le<View>(home,x0,x1);
00124     return ES_OK;
00125   }
00126 
00127   template <class View>
00128   forceinline
00129   Le<View>::Le(Space* home, bool share, Le<View>& p)
00130     : BinaryPropagator<View,PC_INT_BND>(home,share,p) {}
00131 
00132   template <class View>
00133   Actor*
00134   Le<View>::copy(Space* home, bool share) {
00135     return new (home) Le<View>(home,share,*this);
00136   }
00137 
00138   template <class View>
00139   inline Support::Symbol
00140   Le<View>::ati(void) {
00141     return Reflection::mangle<View>("Gecode::Int::Rel::Le");
00142   }
00143 
00144   template <class View>
00145   Reflection::ActorSpec
00146   Le<View>::spec(const Space* home, Reflection::VarMap& m) const {
00147     return BinaryPropagator<View,PC_INT_BND>
00148       ::spec(home, m, ati());
00149   }
00150 
00151   template <class View>
00152   void
00153   Le<View>::post(Space* home, Reflection::VarMap& vars,
00154                  const Reflection::ActorSpec& spec) {
00155     spec.checkArity(2);
00156     View x0(home, vars, spec[0]);
00157     View x1(home, vars, spec[1]);
00158     (void) new (home) Le<View>(home, x0, x1);
00159   }
00160 
00161   template <class View>
00162   ExecStatus
00163   Le<View>::propagate(Space* home, ModEventDelta) {
00164     GECODE_ME_CHECK(x0.le(home,x1.max()));
00165     GECODE_ME_CHECK(x1.gr(home,x0.min()));
00166     return (x0.max() < x1.min()) ? ES_SUBSUMED(this,home) : ES_FIX;
00167   }
00168 
00169 
00170 
00171   /*
00172    * Reified less or equal propagator
00173    *
00174    */
00175 
00176   template <class View, class CtrlView>
00177   forceinline
00178   ReLq<View,CtrlView>::ReLq(Space* home, View x0, View x1, CtrlView b)
00179     : ReBinaryPropagator<View,PC_INT_BND,CtrlView>(home,x0,x1,b) {}
00180 
00181   template <class View, class CtrlView>
00182   ExecStatus
00183   ReLq<View,CtrlView>::post(Space* home, View x0, View x1, CtrlView b) {
00184     if (b.one())
00185       return Lq<View>::post(home,x0,x1);
00186     if (b.zero())
00187       return Le<View>::post(home,x1,x0);
00188     if (!same(x0,x1)) {
00189       switch (rtest_lq(x0,x1)) {
00190       case RT_TRUE:
00191         GECODE_ME_CHECK(b.one_none(home)); break;
00192       case RT_FALSE:
00193         GECODE_ME_CHECK(b.zero_none(home)); break;
00194       case RT_MAYBE:
00195         (void) new (home) ReLq<View,CtrlView>(home,x0,x1,b); break;
00196       default: GECODE_NEVER;
00197       }
00198     } else {
00199       GECODE_ME_CHECK(b.one_none(home));
00200     }
00201     return ES_OK;
00202   }
00203 
00204   template <class View, class CtrlView>
00205   forceinline
00206   ReLq<View,CtrlView>::ReLq(Space* home, bool share, ReLq& p)
00207     : ReBinaryPropagator<View,PC_INT_BND,CtrlView>(home,share,p) {}
00208 
00209   template <class View, class CtrlView>
00210   Actor*
00211   ReLq<View,CtrlView>::copy(Space* home, bool share) {
00212     return new (home) ReLq<View,CtrlView>(home,share,*this);
00213   }
00214 
00215   template <class View, class CtrlView>
00216   inline Support::Symbol
00217   ReLq<View,CtrlView>::ati(void) {
00218     return Reflection::mangle<View,CtrlView>("Gecode::Int::Rel::ReLq");
00219   }
00220 
00221   template <class View, class CtrlView>
00222   Reflection::ActorSpec
00223   ReLq<View,CtrlView>::spec(const Space* home, Reflection::VarMap& m) const {
00224     return
00225       ReBinaryPropagator<View,PC_INT_BND,CtrlView>::spec(home, m, ati());
00226   }
00227 
00228   template <class View, class CtrlView>
00229   void
00230   ReLq<View,CtrlView>::post(Space* home, Reflection::VarMap& vars,
00231                             const Reflection::ActorSpec& spec) {
00232     spec.checkArity(3);
00233     View x0(home, vars, spec[0]);
00234     View x1(home, vars, spec[1]);
00235     CtrlView b(home, vars, spec[2]);
00236     (void) new (home) ReLq<View,CtrlView>(home, x0, x1, b);
00237   }
00238 
00239   template <class View, class CtrlView>
00240   ExecStatus
00241   ReLq<View,CtrlView>::propagate(Space* home, ModEventDelta) {
00242     if (b.one())
00243       GECODE_REWRITE(this,Lq<View>::post(home,x0,x1));
00244     if (b.zero())
00245       GECODE_REWRITE(this,Le<View>::post(home,x1,x0));
00246     switch (rtest_lq(x0,x1)) {
00247     case RT_TRUE:
00248       GECODE_ME_CHECK(b.one_none(home));  return ES_SUBSUMED(this,home);
00249     case RT_FALSE:
00250       GECODE_ME_CHECK(b.zero_none(home)); return ES_SUBSUMED(this,home);
00251     case RT_MAYBE:
00252       break;
00253     default: GECODE_NEVER;
00254     }
00255     return ES_FIX;
00256   }
00257 
00258   /*
00259    * Reified less or equal propagator involving one variable
00260    *
00261    */
00262 
00263   template <class View, class CtrlView>
00264   forceinline
00265   ReLqInt<View,CtrlView>::ReLqInt(Space* home, View x, int c0, CtrlView b)
00266     : ReUnaryPropagator<View,PC_INT_BND,CtrlView>(home,x,b), c(c0) {}
00267 
00268   template <class View, class CtrlView>
00269   ExecStatus
00270   ReLqInt<View,CtrlView>::post(Space* home, View x, int c, CtrlView b) {
00271     if (b.one()) {
00272       GECODE_ME_CHECK(x.lq(home,c));
00273     } else if (b.zero()) {
00274       GECODE_ME_CHECK(x.gr(home,c));
00275     } else {
00276       switch (rtest_lq(x,c)) {
00277       case RT_TRUE:
00278         GECODE_ME_CHECK(b.one_none(home)); break;
00279       case RT_FALSE:
00280         GECODE_ME_CHECK(b.zero_none(home)); break;
00281       case RT_MAYBE:
00282         (void) new (home) ReLqInt<View,CtrlView>(home,x,c,b); break;
00283       default: GECODE_NEVER;
00284       }
00285     }
00286     return ES_OK;
00287   }
00288 
00289 
00290   template <class View, class CtrlView>
00291   forceinline
00292   ReLqInt<View,CtrlView>::ReLqInt(Space* home, bool share, ReLqInt& p)
00293     : ReUnaryPropagator<View,PC_INT_BND,CtrlView>(home,share,p), c(p.c) {}
00294 
00295   template <class View, class CtrlView>
00296   Actor*
00297   ReLqInt<View,CtrlView>::copy(Space* home, bool share) {
00298     return new (home) ReLqInt<View,CtrlView>(home,share,*this);
00299   }
00300 
00301   template <class View, class CtrlView>
00302   inline Support::Symbol
00303   ReLqInt<View,CtrlView>::ati(void) {
00304     return Reflection::mangle<View,CtrlView>("Gecode::Int::Rel::ReLqInt");
00305   }
00306   
00307   template <class View, class CtrlView>
00308   Reflection::ActorSpec
00309   ReLqInt<View,CtrlView>::spec(const Space* home,
00310                                Reflection::VarMap& m) const {
00311     return ReUnaryPropagator<View,PC_INT_BND,CtrlView>
00312       ::spec(home, m, ati()) << c;
00313   }
00314 
00315   template <class View, class CtrlView>
00316   void
00317   ReLqInt<View,CtrlView>::post(Space* home, Reflection::VarMap& vars,
00318                                const Reflection::ActorSpec& spec) {
00319     spec.checkArity(3);
00320     View x0(home, vars, spec[0]);
00321     CtrlView b(home, vars, spec[1]);
00322     int c = spec[2]->toInt();
00323     (void) new (home) ReLqInt<View,CtrlView>(home, x0, c, b);
00324   }
00325 
00326   template <class View, class CtrlView>
00327   ExecStatus
00328   ReLqInt<View,CtrlView>::propagate(Space* home, ModEventDelta) {
00329     if (b.one()) {
00330       GECODE_ME_CHECK(x0.lq(home,c)); goto subsumed;
00331     }
00332     if (b.zero()) {
00333       GECODE_ME_CHECK(x0.gr(home,c)); goto subsumed;
00334     }
00335     switch (rtest_lq(x0,c)) {
00336     case RT_TRUE:
00337       GECODE_ME_CHECK(b.one_none(home)); goto subsumed;
00338     case RT_FALSE:
00339       GECODE_ME_CHECK(b.zero_none(home)); goto subsumed;
00340     case RT_MAYBE:
00341       break;
00342     default: GECODE_NEVER;
00343     }
00344     return ES_FIX;
00345   subsumed:
00346     return ES_SUBSUMED(this,home);
00347   }
00348 
00349 }}}
00350 
00351 // STATISTICS: int-prop
00352