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

bool.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, 2002
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00011  *     $Revision: 6017 $
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 {
00039 
00040   namespace Int {
00041 
00042     /*
00043      * Constructors and initialization
00044      *
00045      */
00046     forceinline
00047     BoolView::BoolView(void) {}
00048     forceinline
00049     BoolView::BoolView(const BoolVar& x)
00050       : VarViewBase<BoolVarImp>(x.var()) {}
00051     forceinline
00052     BoolView::BoolView(BoolVarImp* x)
00053       : VarViewBase<BoolVarImp>(x) {}
00054     forceinline
00055     BoolView::BoolView(Space* /*home*/, const Reflection::VarMap& vars,
00056                        Reflection::Arg* arg) 
00057       : VarViewBase<BoolVarImp>(BoolVar(vars.var(arg->toVar())).var()) {}
00058 
00059     /*
00060      * Value access
00061      *
00062      */
00063     forceinline BoolStatus
00064     BoolView::status(void) const {
00065       return varimp->status();
00066     }
00067     forceinline int
00068     BoolView::min(void) const {
00069       return varimp->min();
00070     }
00071     forceinline int
00072     BoolView::max(void) const {
00073       return varimp->max();
00074     }
00075     forceinline int
00076     BoolView::med(void) const {
00077       return varimp->med();
00078     }
00079     forceinline int
00080     BoolView::val(void) const {
00081       return varimp->val();
00082     }
00083     
00084     forceinline unsigned int
00085     BoolView::size(void) const {
00086       return varimp->size();
00087     }
00088     forceinline unsigned int
00089     BoolView::width(void) const {
00090       return varimp->width();
00091     }
00092     forceinline unsigned int
00093     BoolView::regret_min(void) const {
00094       return varimp->regret_min();
00095     }
00096     forceinline unsigned int
00097     BoolView::regret_max(void) const {
00098       return varimp->regret_max();
00099     }
00100     
00101     
00102     /*
00103      * Domain tests
00104      *
00105      */
00106     forceinline bool
00107     BoolView::range(void) const {
00108       return varimp->range();
00109     }
00110     forceinline bool
00111     BoolView::assigned(void) const {
00112       return varimp->assigned();
00113     }
00114     
00115     forceinline bool
00116     BoolView::in(int n) const {
00117       return varimp->in(n);
00118     }
00119     forceinline bool
00120     BoolView::in(double n) const {
00121       return varimp->in(n);
00122     }
00123     
00124 
00125     /*
00126      * Domain update by value
00127      *
00128      */
00129     forceinline ModEvent
00130     BoolView::lq(Space* home, int n) {
00131       return varimp->lq(home,n);
00132     }
00133     forceinline ModEvent
00134     BoolView::lq(Space* home, double n) {
00135       return varimp->lq(home,n);
00136     }
00137     
00138     forceinline ModEvent
00139     BoolView::le(Space* home, int n) {
00140       return varimp->lq(home,n-1);
00141     }
00142     forceinline ModEvent
00143     BoolView::le(Space* home, double n) {
00144       return lq(home,n-1.0);
00145     }
00146     
00147     forceinline ModEvent
00148     BoolView::gq(Space* home, int n) {
00149     return varimp->gq(home,n);
00150     }
00151     forceinline ModEvent
00152     BoolView::gq(Space* home, double n) {
00153       return varimp->gq(home,n);
00154     }
00155     
00156     forceinline ModEvent
00157     BoolView::gr(Space* home, int n) {
00158       return varimp->gq(home,n+1);
00159     }
00160     forceinline ModEvent
00161     BoolView::gr(Space* home, double n) {
00162       return gq(home,n+1.0);
00163     }
00164     
00165     forceinline ModEvent
00166     BoolView::nq(Space* home, int n) {
00167       return varimp->nq(home,n);
00168     }
00169     forceinline ModEvent
00170     BoolView::nq(Space* home, double n) {
00171       return varimp->nq(home,n);
00172     }
00173     
00174     forceinline ModEvent
00175     BoolView::eq(Space* home, int n) {
00176       return varimp->eq(home,n);
00177     }
00178     forceinline ModEvent
00179     BoolView::eq(Space* home, double n) {
00180       return varimp->eq(home,n);
00181     }
00182     
00183     
00184     /*
00185      * Iterator-based domain update
00186      *
00187      */
00188     template <class I>
00189     forceinline ModEvent
00190     BoolView::narrow_r(Space* home, I& i, bool depend) {
00191       return varimp->narrow_r(home,i,depend);
00192     }
00193     template <class I>
00194     forceinline ModEvent
00195     BoolView::inter_r(Space* home, I& i, bool depend) {
00196       return varimp->inter_r(home,i,depend);
00197     }
00198     template <class I>
00199     forceinline ModEvent
00200     BoolView::minus_r(Space* home, I& i, bool depend) {
00201       return varimp->minus_r(home,i,depend);
00202     }
00203     template <class I>
00204     forceinline ModEvent
00205     BoolView::narrow_v(Space* home, I& i, bool depend) {
00206       return varimp->narrow_v(home,i,depend);
00207     }
00208     template <class I>
00209     forceinline ModEvent
00210     BoolView::inter_v(Space* home, I& i, bool depend) {
00211       return varimp->inter_v(home,i,depend);
00212     }
00213     template <class I>
00214     forceinline ModEvent
00215     BoolView::minus_v(Space* home, I& i, bool depend) {
00216       return varimp->minus_v(home,i,depend);
00217     }
00218 
00219 
00220     /*
00221      * Boolean domain tests
00222      *
00223      */
00224     forceinline bool
00225     BoolView::zero(void) const {
00226       return varimp->zero();
00227     }
00228     forceinline bool
00229     BoolView::one(void) const {
00230       return varimp->one();
00231     }
00232     forceinline bool
00233     BoolView::none(void) const {
00234       return varimp->none();
00235     }
00236 
00237 
00238     /*
00239      * Boolean assignment operations
00240      *
00241      */
00242     forceinline ModEvent
00243     BoolView::zero_none(Space* home) {
00244       return varimp->zero_none(home);
00245     }
00246     forceinline ModEvent
00247     BoolView::one_none(Space* home) {
00248       return varimp->one_none(home);
00249     }
00250 
00251     forceinline ModEvent
00252     BoolView::zero(Space* home) {
00253       return varimp->zero(home);
00254     }
00255     forceinline ModEvent
00256     BoolView::one(Space* home) {
00257       return varimp->one(home);
00258     }
00259 
00260 
00261     /*
00262      * Delta information for advisors
00263      *
00264      */
00265     forceinline ModEvent
00266     BoolView::modevent(const Delta* d) {
00267       return BoolVarImp::modevent(d);
00268     }
00269     forceinline int
00270     BoolView::min(const Delta* d) const {
00271       return varimp->min(d);
00272     }
00273     forceinline int
00274     BoolView::max(const Delta* d) const {
00275       return varimp->max(d);
00276     }
00277     forceinline bool
00278     BoolView::any(const Delta* d) const {
00279       return varimp->any(d);
00280     }
00281 
00282 
00283 
00284     forceinline ModEventDelta
00285     BoolView::med(ModEvent me) {
00286       return VarViewBase<BoolVarImp>::med(me);
00287     }
00288 
00289 
00290     /*
00291      * Cloning
00292      *
00293      */
00294     forceinline void
00295     BoolView::update(Space* home, bool share, BoolView& x) {
00296       varimp = x.varimp->copy(home,share);
00297     }
00298 
00299     /*
00300      * Serialization
00301      *
00302      */
00303     forceinline Reflection::Arg*
00304     BoolView::spec(const Space* home, Reflection::VarMap& m) const {
00305       return varimp->spec(home, m);
00306     }
00307     inline Support::Symbol
00308     BoolView::type(void) {
00309       return Support::Symbol("Gecode::Int::BoolView");
00310     }
00311 
00312     /*
00313      * Negated Boolean views
00314      *
00315      */
00316 
00317     /*
00318      * Constructors and initialization
00319      *
00320      */
00321     forceinline
00322     NegBoolView::NegBoolView(void) {}
00323     forceinline
00324     NegBoolView::NegBoolView(const BoolView& b)
00325       : DerivedViewBase<BoolView>(b) {}
00326     forceinline void
00327     NegBoolView::init(const BoolView& b) {
00328       view = b;
00329     }
00330     forceinline
00331     NegBoolView::NegBoolView(Space* home, const Reflection::VarMap& vars,
00332                              Reflection::Arg* arg)
00333     : DerivedViewBase<BoolView>(BoolView(home, vars, arg)) {}
00334 
00335 
00336     /*
00337      * Boolean domain tests
00338      *
00339      */
00340     forceinline BoolStatus
00341     NegBoolView::status(void) const {
00342       return view.status();
00343     }
00344     forceinline bool
00345     NegBoolView::zero(void) const {
00346       return view.one();
00347     }
00348     forceinline bool
00349     NegBoolView::one(void) const {
00350       return view.zero();
00351     }
00352     forceinline bool
00353     NegBoolView::none(void) const {
00354       return view.none();
00355     }
00356 
00357 
00358     /*
00359      * Boolean assignment operations
00360      *
00361      */
00362     forceinline ModEvent
00363     NegBoolView::zero_none(Space* home) {
00364       return view.one_none(home);
00365     }
00366     forceinline ModEvent
00367     NegBoolView::one_none(Space* home) {
00368       return view.zero_none(home);
00369     }
00370 
00371     forceinline ModEvent
00372     NegBoolView::zero(Space* home) {
00373       return view.one(home);
00374     }
00375     forceinline ModEvent
00376     NegBoolView::one(Space* home) {
00377       return view.zero(home);
00378     }
00379 
00380 
00381     /*
00382      * Value access
00383      *
00384      */
00385     forceinline int
00386     NegBoolView::min(void) const {
00387       return view.max();
00388     }
00389     forceinline int
00390     NegBoolView::max(void) const {
00391       return view.min();
00392     }
00393     forceinline int
00394     NegBoolView::val(void) const {
00395       return 1-view.val();
00396     }
00397 
00398 
00399     /*
00400      * Domain tests
00401      *
00402      */
00403     forceinline bool
00404     NegBoolView::assigned(void) const {
00405       return view.assigned();
00406     }
00407 
00408     /*
00409      * Propagator modification events
00410      *
00411      */
00412     forceinline void
00413     NegBoolView::schedule(Space* home, Propagator* p, ModEvent me) {
00414       return BoolView::schedule(home,p,me);
00415     }
00416     forceinline ModEvent
00417     NegBoolView::me(ModEventDelta med) {
00418       return BoolView::me(med);
00419     }
00420     forceinline ModEventDelta
00421     NegBoolView::med(ModEvent me) {
00422       return BoolView::med(me);
00423     }
00424 
00425 
00426     /*
00427      * Dependencies
00428      *
00429      */
00430     forceinline void
00431     NegBoolView::subscribe(Space* home, Propagator* p, PropCond pc,
00432                            bool process) {
00433       view.subscribe(home,p,pc,process);
00434     }
00435     forceinline void
00436     NegBoolView::cancel(Space* home, Propagator* p, PropCond pc) {
00437       view.cancel(home,p,pc);
00438     }
00439     forceinline void
00440     NegBoolView::subscribe(Space* home, Advisor* a) {
00441       view.subscribe(home,a);
00442     }
00443     forceinline void
00444     NegBoolView::cancel(Space* home, Advisor* a) {
00445       view.cancel(home,a);
00446     }
00447 
00448 
00449     /*
00450      * Delta information for advisors
00451      *
00452      */
00453     forceinline ModEvent
00454     NegBoolView::modevent(const Delta* d) {
00455       return BoolView::modevent(d);
00456     }
00457     forceinline int
00458     NegBoolView::min(const Delta* d) const {
00459       return view.max(d);
00460     }
00461     forceinline int
00462     NegBoolView::max(const Delta* d) const {
00463       return view.min(d);
00464     }
00465     forceinline bool
00466     NegBoolView::any(const Delta* d) const {
00467       return view.any(d);
00468     }
00469 
00470 
00471 
00472     /*
00473      * Cloning
00474      *
00475      */
00476     forceinline void
00477     NegBoolView::update(Space* home, bool share, NegBoolView& b) {
00478       view.update(home,share,b.view);
00479     }
00480 
00481     /*
00482      * Serialization
00483      *
00484      */
00485     forceinline Reflection::Arg*
00486     NegBoolView::spec(const Space* home, Reflection::VarMap& m) const {
00487       return view.spec(home, m);
00488     }
00489     inline Support::Symbol
00490     NegBoolView::type(void) {
00491       return Support::Symbol("Gecode::Int::NegBoolView");
00492     }
00493 
00498     template <>
00499     class ViewRanges<BoolView> : public Iter::Ranges::Singleton {
00500     public:
00502 
00503 
00504       ViewRanges(void);
00506       ViewRanges(const BoolView& x);
00508       void init(const BoolView& x);
00510     };
00511 
00512     forceinline
00513     ViewRanges<BoolView>::ViewRanges(void) {}
00514 
00515     forceinline
00516     ViewRanges<BoolView>::ViewRanges(const BoolView& x)
00517       : Iter::Ranges::Singleton(x.min(),x.max()) {}
00518 
00519     forceinline void
00520     ViewRanges<BoolView>::init(const BoolView& x) {
00521       Iter::Ranges::Singleton::init(x.min(),x.max());
00522     }
00523 
00528     template <>
00529     class ViewRanges<NegBoolView> : public Iter::Ranges::Singleton {
00530     public:
00532 
00533 
00534       ViewRanges(void);
00536       ViewRanges(const NegBoolView& x);
00538       void init(const NegBoolView& x);
00540     };
00541 
00542     forceinline
00543     ViewRanges<NegBoolView>::ViewRanges(void) {}
00544 
00545     forceinline
00546     ViewRanges<NegBoolView>::ViewRanges(const NegBoolView& x)
00547       : Iter::Ranges::Singleton(x.min(),x.max()) {}
00548 
00549     forceinline void
00550     ViewRanges<NegBoolView>::init(const NegBoolView& x) {
00551       Iter::Ranges::Singleton::init(x.min(),x.max());
00552     }
00553 
00554   }
00555 
00556 
00557   /*
00558    * View comparison
00559    *
00560    */
00561   forceinline bool
00562   same(const Int::NegBoolView& x, const Int::NegBoolView& y) {
00563     return same(x.base(),y.base());
00564   }
00565   forceinline bool
00566   before(const Int::NegBoolView& x, const Int::NegBoolView& y) {
00567     return before(x.base(),y.base());
00568   }
00569 
00570   namespace Int {
00571 
00572     /*
00573      * Test sharing between Boolean and negated Boolean views
00574      *
00575      */
00576     forceinline BoolTest
00577     bool_test(const BoolView& b0, const BoolView& b1) {
00578       return same(b0,b1) ? BT_SAME : BT_NONE;
00579     }
00580     forceinline BoolTest
00581     bool_test(const BoolView& b0, const NegBoolView& b1) {
00582       return same(b0,b1.base()) ? BT_COMP : BT_NONE;
00583     }
00584     forceinline BoolTest
00585     bool_test(const NegBoolView& b0, const BoolView& b1) {
00586       return same(b0.base(),b1) ? BT_COMP : BT_NONE;
00587     }
00589     forceinline BoolTest
00590     bool_test(const NegBoolView& b0, const NegBoolView& b1) {
00591       return same(b0,b1) ? BT_SAME : BT_NONE;
00592     }
00593 
00594   }
00595 
00596 }
00597 
00598 // STATISTICS: int-var