Generated on Sun Feb 17 15:24:21 2019 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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Int { namespace NoOverlap {
00035 
00036   /*
00037    * Mandatory boxes
00038    *
00039    */
00040   template<class Dim, int n>
00041   forceinline const Dim&
00042   ManBox<Dim,n>::operator [](int i) const {
00043     assert((i >= 0) && (i < n));
00044     return d[i];
00045   }
00046   template<class Dim, int n>
00047   forceinline Dim&
00048   ManBox<Dim,n>::operator [](int i) {
00049     assert((i >= 0) && (i < n));
00050     return d[i];
00051   }
00052   template<class Dim, int n>
00053   forceinline int
00054   ManBox<Dim,n>::dim(void) {
00055     return n;
00056   }
00057 
00058   template<class Dim, int n>
00059   forceinline bool
00060   ManBox<Dim,n>::mandatory(void) const {
00061     return true;
00062   }
00063   template<class Dim, int n>
00064   forceinline bool
00065   ManBox<Dim,n>::excluded(void) const {
00066     return false;
00067   }
00068   template<class Dim, int n>
00069   forceinline bool
00070   ManBox<Dim,n>::optional(void) const {
00071     return false;
00072   }
00073 
00074   template<class Dim, int n>
00075   forceinline ExecStatus
00076   ManBox<Dim,n>::exclude(Space&) {
00077     return ES_FAILED;
00078   }
00079 
00080   template<class Dim, int n>
00081   forceinline bool
00082   ManBox<Dim,n>::nooverlap(const ManBox<Dim,n>& box) const {
00083     for (int i=0; i<n; i++)
00084       if ((d[i].lec() <= box.d[i].ssc()) || (box.d[i].lec() <= d[i].ssc()))
00085         return true;
00086     return false;
00087   }
00088 
00089   template<class Dim, int n>
00090   forceinline bool
00091   ManBox<Dim,n>::overlap(const ManBox<Dim,n>& box) const {
00092     for (int i=0; i<n; i++)
00093       if ((d[i].sec() <= box.d[i].lsc()) || (box.d[i].sec() <= d[i].lsc()))
00094         return false;
00095     return true;
00096   }
00097 
00098   template<class Dim, int n>
00099   forceinline ExecStatus
00100   ManBox<Dim,n>::nooverlap(Space& home, ManBox<Dim,n>& box) {
00101     for (int i=0; i<n; i++)
00102       if ((d[i].sec() <= box.d[i].lsc()) ||
00103           (box.d[i].sec() <= d[i].lsc())) {
00104         // Does not overlap for dimension i
00105         for (int j=i+1; j<n; j++)
00106           if ((d[j].sec() <= box.d[j].lsc()) ||
00107               (box.d[j].sec() <= d[j].lsc()))
00108             return ES_OK;
00109         // Does not overlap for only dimension i, hence propagate
00110         d[i].nooverlap(home, box.d[i]);
00111         box.d[i].nooverlap(home, d[i]);
00112         return ES_OK;
00113       }
00114     // Overlaps in all dimensions
00115     return ES_FAILED;
00116   }
00117 
00118   template<class Dim, int n>
00119   forceinline void
00120   ManBox<Dim,n>::update(Space& home, ManBox<Dim,n>& b) {
00121     for (int i=0; i<n; i++)
00122       d[i].update(home,b.d[i]);
00123   }
00124 
00125   template<class Dim, int n>
00126   forceinline void
00127   ManBox<Dim,n>::subscribe(Space& home, Propagator& p) {
00128     for (int i=0; i<n; i++)
00129       d[i].subscribe(home,p);
00130   }
00131   template<class Dim, int n>
00132   forceinline void
00133   ManBox<Dim,n>::cancel(Space& home, Propagator& p) {
00134     for (int i=0; i<n; i++)
00135       d[i].cancel(home,p);
00136   }
00137   template<class Dim, int n>
00138   forceinline void
00139   ManBox<Dim,n>::reschedule(Space& home, Propagator& p) {
00140     for (int i=0; i<n; i++)
00141       d[i].reschedule(home,p);
00142   }
00143 
00144 
00145   /*
00146    * Optional boxes
00147    *
00148    */
00149   template<class Dim, int n>
00150   forceinline void
00151   OptBox<Dim,n>::optional(BoolView o0) {
00152     o = o0;
00153   }
00154   template<class Dim, int n>
00155   forceinline bool
00156   OptBox<Dim,n>::mandatory(void) const {
00157     return o.one();
00158   }
00159   template<class Dim, int n>
00160   forceinline bool
00161   OptBox<Dim,n>::excluded(void) const {
00162     return o.zero();
00163   }
00164   template<class Dim, int n>
00165   forceinline bool
00166   OptBox<Dim,n>::optional(void) const {
00167     return o.none();
00168   }
00169 
00170   template<class Dim, int n>
00171   forceinline ExecStatus
00172   OptBox<Dim,n>::exclude(Space& home) {
00173     GECODE_ME_CHECK(o.zero(home));
00174     return ES_OK;
00175   }
00176 
00177   template<class Dim, int n>
00178   forceinline void
00179   OptBox<Dim,n>::update(Space& home, OptBox<Dim,n>& b) {
00180     ManBox<Dim,n>::update(home, b);
00181     o.update(home, b.o);
00182   }
00183 
00184   template<class Dim, int n>
00185   forceinline void
00186   OptBox<Dim,n>::subscribe(Space& home, Propagator& p) {
00187     ManBox<Dim,n>::subscribe(home,p);
00188     o.subscribe(home, p, PC_BOOL_VAL);
00189   }
00190   template<class Dim, int n>
00191   forceinline void
00192   OptBox<Dim,n>::cancel(Space& home, Propagator& p) {
00193     ManBox<Dim,n>::cancel(home,p);
00194     o.cancel(home, p, PC_BOOL_VAL);
00195   }
00196   template<class Dim, int n>
00197   forceinline void
00198   OptBox<Dim,n>::reschedule(Space& home, Propagator& p) {
00199     ManBox<Dim,n>::reschedule(home,p);
00200     o.reschedule(home, p, PC_BOOL_VAL);
00201   }
00202 
00203 }}}
00204 
00205 // STATISTICS: int-prop
00206