Generated on Thu Jul 6 07:06:45 2006 for Gecode by doxygen 1.4.7

bool.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2002
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-05-23 17:20:37 +0200 (Tue, 23 May 2006) $ by $Author: schulte $
00010  *     $Revision: 3236 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 namespace Gecode { 
00023 
00024   namespace Int {
00025 
00026     /*
00027      * Constructors and initialization
00028      *
00029      */
00030     forceinline
00031     BoolView::BoolView(void) {}
00032     forceinline
00033     BoolView::BoolView(const BoolVar& b) : IntView(b) {}
00034     forceinline
00035     BoolView::BoolView(const IntVar& x) : IntView(x) {
00036       assert((variable()->min() >= 0) && (variable()->max() <= 1));
00037     }
00038     forceinline
00039     BoolView::BoolView(const IntView& x) : IntView(x) {
00040       assert((variable()->min() >= 0) && (variable()->max() <= 1));
00041     }
00042     
00043 
00044     /*
00045      * Boolean domain tests
00046      *
00047      */
00048     forceinline bool
00049     BoolView::zero(void) const {
00050       return var->max() == 0;
00051     }
00052     forceinline bool
00053     BoolView::one(void) const {
00054       return var->min() != 0;
00055     }
00056     forceinline bool
00057     BoolView::none(void) const {
00058       return ((var->min()+var->max()) == 1);
00059     }
00060     
00061     
00062     /*
00063      * Boolean assignment operations
00064      *
00065      */
00066     forceinline void
00067     BoolView::t_zero_none(Space* home) {
00068       var->t_zero_none(home);
00069     }
00070     forceinline void
00071     BoolView::t_one_none(Space* home) {
00072       var->t_one_none(home);
00073     }
00074     
00075     forceinline ModEvent
00076     BoolView::t_zero(Space* home) {
00077       if (one())  return ME_INT_FAILED;
00078       if (zero()) return ME_INT_NONE;
00079       t_zero_none(home);
00080       return ME_INT_VAL;
00081     }
00082     forceinline ModEvent
00083     BoolView::t_one(Space* home) {
00084       if (zero()) return ME_INT_FAILED;
00085       if (one())  return ME_INT_NONE;
00086       t_one_none(home);
00087       return ME_INT_VAL;
00088     }
00089 
00090 
00091 
00092     /*
00093      * Negated Boolean views
00094      *
00095      */
00096 
00097     /*
00098      * Constructors and initialization
00099      *
00100      */
00101     forceinline
00102     NegBoolView::NegBoolView(void) {}
00103     forceinline
00104     NegBoolView::NegBoolView(const BoolView& b)
00105       : DerivedViewBase<BoolView>(b) {}
00106     forceinline void
00107     NegBoolView::init(const BoolView& b) {
00108       view = b;
00109     }
00110 
00111 
00112     /*
00113      * Boolean domain tests
00114      *
00115      */
00116     forceinline bool
00117     NegBoolView::zero(void) const {
00118       return view.one();
00119     }
00120     forceinline bool
00121     NegBoolView::one(void) const {
00122       return view.zero();
00123     }
00124     forceinline bool
00125     NegBoolView::none(void) const {
00126       return view.none();
00127     }
00128     
00129     
00130     /*
00131      * Boolean assignment operations
00132      *
00133      */
00134     forceinline void
00135     NegBoolView::t_zero_none(Space* home) {
00136       view.t_one_none(home);
00137     }
00138     forceinline void
00139     NegBoolView::t_one_none(Space* home) {
00140       view.t_zero_none(home);
00141     }
00142     
00143     forceinline ModEvent
00144     NegBoolView::t_zero(Space* home) {
00145       return view.t_one(home);
00146     }
00147     forceinline ModEvent
00148     NegBoolView::t_one(Space* home) {
00149       return view.t_zero(home);
00150     }
00151 
00152 
00153     /*
00154      * Value access
00155      *
00156      */
00157     forceinline int
00158     NegBoolView::min(void) const { 
00159       return view.max(); 
00160     }
00161     forceinline int
00162     NegBoolView::max(void) const { 
00163       return view.min(); 
00164     }
00165     forceinline int
00166     NegBoolView::val(void) const { 
00167       return 1-view.val(); 
00168     }
00169 
00170 
00171     /*
00172      * Domain tests
00173      *
00174      */
00175     forceinline bool
00176     NegBoolView::assigned(void) const { 
00177       return view.assigned(); 
00178     }
00179 
00180     /*
00181      * Propagator modification events
00182      *
00183      */
00184     forceinline ModEvent
00185     NegBoolView::pme(const Propagator* p) {
00186       return BoolView::pme(p);
00187     }
00188     forceinline PropModEvent
00189     NegBoolView::pme(ModEvent me) {
00190       return BoolView::pme(me);
00191     }
00192 
00193 
00194     /*
00195      * Dependencies
00196      *
00197      */
00198     forceinline void
00199     NegBoolView::subscribe(Space* home, Propagator* p, PropCond pc) {
00200       view.subscribe(home,p,pc);
00201     }
00202     forceinline void
00203     NegBoolView::cancel(Space* home, Propagator* p, PropCond pc) {
00204       view.cancel(home,p,pc);
00205     }
00206 
00207 
00208     /*
00209      * Cloning
00210      *
00211      */
00212     forceinline void
00213     NegBoolView::update(Space* home, bool share, NegBoolView& b) {
00214       view.update(home,share,b.view);
00215     }
00216 
00217   }
00218 
00219 
00220   /*
00221    * View comparison
00222    *
00223    */
00224   forceinline bool
00225   same(const Int::NegBoolView& x, const Int::NegBoolView& y) {
00226     return same(x.base(),y.base());
00227   }
00228   forceinline bool
00229   before(const Int::NegBoolView& x, const Int::NegBoolView& y) {
00230     return before(x.base(),y.base());
00231   }
00232 
00233   namespace Int {
00234 
00235     /*
00236      * Test sharing between Boolean and negated Boolean views
00237      * 
00238      */
00239     forceinline BoolTest 
00240     bool_test(const BoolView& b0, const BoolView& b1) {
00241       return same(b0,b1) ? BT_SAME : BT_NONE;
00242     }
00243     forceinline BoolTest 
00244     bool_test(const BoolView& b0, const NegBoolView& b1) {
00245       return same(b0,b1.base()) ? BT_COMP : BT_NONE;
00246     }
00247     forceinline BoolTest 
00248     bool_test(const NegBoolView& b0, const BoolView& b1) {
00249       return same(b0.base(),b1) ? BT_COMP : BT_NONE;
00250     }
00252     forceinline BoolTest 
00253     bool_test(const NegBoolView& b0, const NegBoolView& b1) {
00254       return same(b0,b1) ? BT_SAME : BT_NONE;
00255     }
00256 
00257   }
00258 
00259 }
00260 
00261 // STATISTICS: int-var