Generated on Sun Feb 17 15:24:14 2019 for Gecode by doxygen 1.6.3

base.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   template<class Box>
00037   forceinline
00038   Base<Box>::Base(Home home, Box* b0, int n0)
00039     : Propagator(home), b(b0), n(n0) {
00040     for (int i=0; i<n; i++)
00041       b[i].subscribe(home,*this);
00042   }
00043 
00044   template<class Box>
00045   forceinline int
00046   Base<Box>::partition(Box* b, int i, int n) {
00047     int j = n-1;
00048     while (true) {
00049       while (!b[j].mandatory() && (--j >= 0)) {}
00050       while (b[i].mandatory() && (++i < n)) {}
00051       if (j <= i) break;
00052       std::swap(b[i],b[j]);
00053     }
00054     return i;
00055   }
00056 
00057   template<class Box>
00058   forceinline size_t
00059   Base<Box>::dispose(Space& home) {
00060     for (int i=0; i<n; i++)
00061       b[i].cancel(home,*this);
00062     (void) Propagator::dispose(home);
00063     return sizeof(*this);
00064   }
00065 
00066 
00067   template<class Box>
00068   forceinline
00069   Base<Box>::Base(Space& home, Base<Box>& p, int m)
00070     : Propagator(home,p), b(home.alloc<Box>(m)), n(p.n) {
00071     for (int i=0; i<m; i++)
00072       b[i].update(home,p.b[i]);
00073   }
00074 
00075   template<class Box>
00076   PropCost
00077   Base<Box>::cost(const Space&, const ModEventDelta&) const {
00078     return PropCost::quadratic(PropCost::HI,Box::dim()*n);
00079   }
00080 
00081   template<class Box>
00082   void
00083   Base<Box>::reschedule(Space& home) {
00084     for (int i=0; i<n; i++)
00085       b[i].reschedule(home,*this);
00086   }
00087 
00088 }}}
00089 
00090 // STATISTICS: int-prop
00091