Generated on Tue Apr 18 10:21:58 2017 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: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
00011  *     $Revision: 15137 $
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   template<class Dim, int n>
00142   forceinline void
00143   ManBox<Dim,n>::reschedule(Space& home, Propagator& p) {
00144     for (int i=0; i<n; i++)
00145       d[i].reschedule(home,p);
00146   }
00147 
00148 
00149   /*
00150    * Optional boxes
00151    *
00152    */
00153   template<class Dim, int n>
00154   forceinline void
00155   OptBox<Dim,n>::optional(BoolView o0) {
00156     o = o0;
00157   }
00158   template<class Dim, int n>
00159   forceinline bool
00160   OptBox<Dim,n>::mandatory(void) const {
00161     return o.one();
00162   }
00163   template<class Dim, int n>
00164   forceinline bool
00165   OptBox<Dim,n>::excluded(void) const {
00166     return o.zero();
00167   }
00168   template<class Dim, int n>
00169   forceinline bool
00170   OptBox<Dim,n>::optional(void) const {
00171     return o.none();
00172   }
00173 
00174   template<class Dim, int n>
00175   forceinline ExecStatus
00176   OptBox<Dim,n>::exclude(Space& home) {
00177     GECODE_ME_CHECK(o.zero(home));
00178     return ES_OK;
00179   }
00180 
00181   template<class Dim, int n>
00182   forceinline void
00183   OptBox<Dim,n>::update(Space& home, bool share, OptBox<Dim,n>& b) {
00184     ManBox<Dim,n>::update(home, share, b);
00185     o.update(home, share, b.o);
00186   }
00187 
00188   template<class Dim, int n>
00189   forceinline void
00190   OptBox<Dim,n>::subscribe(Space& home, Propagator& p) {
00191     ManBox<Dim,n>::subscribe(home,p);
00192     o.subscribe(home, p, PC_BOOL_VAL);
00193   }
00194   template<class Dim, int n>
00195   forceinline void
00196   OptBox<Dim,n>::cancel(Space& home, Propagator& p) {
00197     ManBox<Dim,n>::cancel(home,p);
00198     o.cancel(home, p, PC_BOOL_VAL);
00199   }
00200   template<class Dim, int n>
00201   forceinline void
00202   OptBox<Dim,n>::reschedule(Space& home, Propagator& p) {
00203     ManBox<Dim,n>::reschedule(home,p);
00204     o.reschedule(home, p, PC_BOOL_VAL);
00205   }
00206 
00207 }}}
00208 
00209 // STATISTICS: int-prop
00210