this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2011 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34namespace Gecode { namespace Int { namespace NoOverlap { 35 36 template<class Box> 37 forceinline 38 Base<Box>::Base(Home home, Box* b0, int n0) 39 : Propagator(home), b(b0), n(n0) { 40 for (int i=0; i<n; i++) 41 b[i].subscribe(home,*this); 42 } 43 44 template<class Box> 45 forceinline int 46 Base<Box>::partition(Box* b, int i, int n) { 47 int j = n-1; 48 while (true) { 49 while (!b[j].mandatory() && (--j >= 0)) {} 50 while (b[i].mandatory() && (++i < n)) {} 51 if (j <= i) break; 52 std::swap(b[i],b[j]); 53 } 54 return i; 55 } 56 57 template<class Box> 58 forceinline size_t 59 Base<Box>::dispose(Space& home) { 60 for (int i=0; i<n; i++) 61 b[i].cancel(home,*this); 62 (void) Propagator::dispose(home); 63 return sizeof(*this); 64 } 65 66 67 template<class Box> 68 forceinline 69 Base<Box>::Base(Space& home, Base<Box>& p, int m) 70 : Propagator(home,p), b(home.alloc<Box>(m)), n(p.n) { 71 for (int i=0; i<m; i++) 72 b[i].update(home,p.b[i]); 73 } 74 75 template<class Box> 76 PropCost 77 Base<Box>::cost(const Space&, const ModEventDelta&) const { 78 return PropCost::quadratic(PropCost::HI,Box::dim()*n); 79 } 80 81 template<class Box> 82 void 83 Base<Box>::reschedule(Space& home) { 84 for (int i=0; i<n; i++) 85 b[i].reschedule(home,*this); 86 } 87 88}}} 89 90// STATISTICS: int-prop 91