Generated on Thu Mar 22 10:39:39 2012 for Gecode by doxygen 1.6.3

box.hpp

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, 2011
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-07-13 18:16:57 +0200 (Wed, 13 Jul 2011) $ by $Author: schulte $
00011  *     $Revision: 12192 $
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 NoOverlap {
00039 
00040   /*
00041    * Mandatory boxes
00042    *
00043    */
00044   template<class Dim, int n>
00045   forceinline const Dim&
00046   ManBox<Dim,n>::operator [](int i) const {
00047     assert((i >= 0) && (i < n));
00048     return d[i];
00049   }
00050   template<class Dim, int n>
00051   forceinline Dim&
00052   ManBox<Dim,n>::operator [](int i) {
00053     assert((i >= 0) && (i < n));
00054     return d[i];
00055   }
00056   template<class Dim, int n>
00057   forceinline int
00058   ManBox<Dim,n>::dim(void) {
00059     return n;
00060   }
00061 
00062   template<class Dim, int n>
00063   forceinline bool
00064   ManBox<Dim,n>::mandatory(void) const {
00065     return true;
00066   }
00067   template<class Dim, int n>
00068   forceinline bool
00069   ManBox<Dim,n>::excluded(void) const {
00070     return false;
00071   }
00072   template<class Dim, int n>
00073   forceinline bool
00074   ManBox<Dim,n>::optional(void) const {
00075     return false;
00076   }
00077 
00078   template<class Dim, int n>
00079   forceinline ExecStatus
00080   ManBox<Dim,n>::exclude(Space&) {
00081     return ES_FAILED;
00082   }
00083 
00084   template<class Dim, int n>
00085   forceinline bool
00086   ManBox<Dim,n>::nooverlap(const ManBox<Dim,n>& box) const {
00087     for (int i=0; i<n; i++)
00088       if ((d[i].lec() <= box.d[i].ssc()) || (box.d[i].lec() <= d[i].ssc()))
00089         return true;
00090     return false;
00091   }
00092 
00093   template<class Dim, int n>
00094   forceinline bool
00095   ManBox<Dim,n>::overlap(const ManBox<Dim,n>& box) const {
00096     for (int i=0; i<n; i++)
00097       if ((d[i].sec() <= box.d[i].lsc()) || (box.d[i].sec() <= d[i].lsc()))
00098         return false;
00099     return true;
00100   }
00101 
00102   template<class Dim, int n>
00103   forceinline ExecStatus
00104   ManBox<Dim,n>::nooverlap(Space& home, ManBox<Dim,n>& box) {
00105     for (int i=0; i<n; i++)
00106       if ((d[i].sec() <= box.d[i].lsc()) || 
00107           (box.d[i].sec() <= d[i].lsc())) {
00108         // Does not overlap for dimension i
00109         for (int j=i+1; j<n; j++)
00110           if ((d[j].sec() <= box.d[j].lsc()) || 
00111               (box.d[j].sec() <= d[j].lsc()))
00112             return ES_OK;
00113         // Does not overlap for only dimension i, hence propagate
00114         d[i].nooverlap(home, box.d[i]);
00115         box.d[i].nooverlap(home, d[i]);
00116         return ES_OK;
00117       }
00118     // Overlaps in all dimensions
00119     return ES_FAILED;
00120   }
00121 
00122   template<class Dim, int n>
00123   forceinline void
00124   ManBox<Dim,n>::update(Space& home, bool share, ManBox<Dim,n>& b) {
00125     for (int i=0; i<n; i++)
00126       d[i].update(home,share,b.d[i]);
00127   }
00128 
00129   template<class Dim, int n>
00130   forceinline void
00131   ManBox<Dim,n>::subscribe(Space& home, Propagator& p) {
00132     for (int i=0; i<n; i++)
00133       d[i].subscribe(home,p);
00134   }
00135   template<class Dim, int n>
00136   forceinline void
00137   ManBox<Dim,n>::cancel(Space& home, Propagator& p) {
00138     for (int i=0; i<n; i++)
00139       d[i].cancel(home,p);
00140   }
00141 
00142 
00143   /*
00144    * Optional boxes
00145    *
00146    */
00147   template<class Dim, int n>
00148   forceinline void
00149   OptBox<Dim,n>::optional(BoolView o0) {
00150     o = o0;
00151   }
00152   template<class Dim, int n>
00153   forceinline bool
00154   OptBox<Dim,n>::mandatory(void) const {
00155     return o.one();
00156   }
00157   template<class Dim, int n>
00158   forceinline bool
00159   OptBox<Dim,n>::excluded(void) const {
00160     return o.zero();
00161   }
00162   template<class Dim, int n>
00163   forceinline bool
00164   OptBox<Dim,n>::optional(void) const {
00165     return o.none();
00166   }
00167 
00168   template<class Dim, int n>
00169   forceinline ExecStatus
00170   OptBox<Dim,n>::exclude(Space& home) {
00171     GECODE_ME_CHECK(o.zero(home));
00172     return ES_OK;
00173   }
00174 
00175   template<class Dim, int n>
00176   forceinline void
00177   OptBox<Dim,n>::update(Space& home, bool share, OptBox<Dim,n>& b) {
00178     ManBox<Dim,n>::update(home, share, b);
00179     o.update(home, share, b.o);
00180   }
00181 
00182   template<class Dim, int n>
00183   forceinline void
00184   OptBox<Dim,n>::subscribe(Space& home, Propagator& p) {
00185     ManBox<Dim,n>::subscribe(home,p);
00186     o.subscribe(home, p, PC_BOOL_VAL);
00187   }
00188   template<class Dim, int n>
00189   forceinline void
00190   OptBox<Dim,n>::cancel(Space& home, Propagator& p) {
00191     ManBox<Dim,n>::cancel(home,p);
00192     o.cancel(home, p, PC_BOOL_VAL);
00193   }
00194 
00195 }}}
00196 
00197 // STATISTICS: int-prop
00198