Generated on Wed Nov 1 15:04:40 2006 for Gecode by doxygen 1.4.5

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-08-24 11:25:05 +0200 (Thu, 24 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3559 $
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      * Cloning
00093      *
00094      */
00095     forceinline void
00096     BoolView::update(Space* home, bool share, BoolView& x) {
00097       var = x.var->copy(home,share);
00098     }
00099 
00100     /*
00101      * Negated Boolean views
00102      *
00103      */
00104 
00105     /*
00106      * Constructors and initialization
00107      *
00108      */
00109     forceinline
00110     NegBoolView::NegBoolView(void) {}
00111     forceinline
00112     NegBoolView::NegBoolView(const BoolView& b)
00113       : DerivedViewBase<BoolView>(b) {}
00114     forceinline void
00115     NegBoolView::init(const BoolView& b) {
00116       view = b;
00117     }
00118 
00119 
00120     /*
00121      * Boolean domain tests
00122      *
00123      */
00124     forceinline bool
00125     NegBoolView::zero(void) const {
00126       return view.one();
00127     }
00128     forceinline bool
00129     NegBoolView::one(void) const {
00130       return view.zero();
00131     }
00132     forceinline bool
00133     NegBoolView::none(void) const {
00134       return view.none();
00135     }
00136 
00137 
00138     /*
00139      * Boolean assignment operations
00140      *
00141      */
00142     forceinline void
00143     NegBoolView::t_zero_none(Space* home) {
00144       view.t_one_none(home);
00145     }
00146     forceinline void
00147     NegBoolView::t_one_none(Space* home) {
00148       view.t_zero_none(home);
00149     }
00150 
00151     forceinline ModEvent
00152     NegBoolView::t_zero(Space* home) {
00153       return view.t_one(home);
00154     }
00155     forceinline ModEvent
00156     NegBoolView::t_one(Space* home) {
00157       return view.t_zero(home);
00158     }
00159 
00160 
00161     /*
00162      * Value access
00163      *
00164      */
00165     forceinline int
00166     NegBoolView::min(void) const {
00167       return view.max();
00168     }
00169     forceinline int
00170     NegBoolView::max(void) const {
00171       return view.min();
00172     }
00173     forceinline int
00174     NegBoolView::val(void) const {
00175       return 1-view.val();
00176     }
00177 
00178 
00179     /*
00180      * Domain tests
00181      *
00182      */
00183     forceinline bool
00184     NegBoolView::assigned(void) const {
00185       return view.assigned();
00186     }
00187 
00188     /*
00189      * Propagator modification events
00190      *
00191      */
00192     forceinline ModEvent
00193     NegBoolView::pme(const Propagator* p) {
00194       return BoolView::pme(p);
00195     }
00196     forceinline PropModEvent
00197     NegBoolView::pme(ModEvent me) {
00198       return BoolView::pme(me);
00199     }
00200 
00201 
00202     /*
00203      * Dependencies
00204      *
00205      */
00206     forceinline void
00207     NegBoolView::subscribe(Space* home, Propagator* p, PropCond pc,
00208                            bool process) {
00209       view.subscribe(home,p,pc,process);
00210     }
00211     forceinline void
00212     NegBoolView::cancel(Space* home, Propagator* p, PropCond pc) {
00213       view.cancel(home,p,pc);
00214     }
00215 
00216 
00217     /*
00218      * Cloning
00219      *
00220      */
00221     forceinline void
00222     NegBoolView::update(Space* home, bool share, NegBoolView& b) {
00223       view.update(home,share,b.view);
00224     }
00225 
00226   }
00227 
00228 
00229   /*
00230    * View comparison
00231    *
00232    */
00233   forceinline bool
00234   same(const Int::NegBoolView& x, const Int::NegBoolView& y) {
00235     return same(x.base(),y.base());
00236   }
00237   forceinline bool
00238   before(const Int::NegBoolView& x, const Int::NegBoolView& y) {
00239     return before(x.base(),y.base());
00240   }
00241 
00242   namespace Int {
00243 
00244     /*
00245      * Test sharing between Boolean and negated Boolean views
00246      *
00247      */
00248     forceinline BoolTest
00249     bool_test(const BoolView& b0, const BoolView& b1) {
00250       return same(b0,b1) ? BT_SAME : BT_NONE;
00251     }
00252     forceinline BoolTest
00253     bool_test(const BoolView& b0, const NegBoolView& b1) {
00254       return same(b0,b1.base()) ? BT_COMP : BT_NONE;
00255     }
00256     forceinline BoolTest
00257     bool_test(const NegBoolView& b0, const BoolView& b1) {
00258       return same(b0.base(),b1) ? BT_COMP : BT_NONE;
00259     }
00261     forceinline BoolTest
00262     bool_test(const NegBoolView& b0, const NegBoolView& b1) {
00263       return same(b0,b1) ? BT_SAME : BT_NONE;
00264     }
00265 
00266   }
00267 
00268 }
00269 
00270 // STATISTICS: int-var