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 /* 37 * Dimension with integer size 38 * 39 */ 40 forceinline 41 FixDim::FixDim(void) 42 : s(0) {} 43 forceinline 44 FixDim::FixDim(IntView c0, int s0) 45 : c(c0), s(s0) {} 46 47 forceinline int 48 FixDim::ssc(void) const { 49 return c.min(); 50 } 51 forceinline int 52 FixDim::lsc(void) const { 53 return c.max(); 54 } 55 forceinline int 56 FixDim::sec(void) const { 57 return c.min() + s; 58 } 59 forceinline int 60 FixDim::lec(void) const { 61 return c.max() + s; 62 } 63 64 forceinline ExecStatus 65 FixDim::ssc(Space& home, int n) { 66 GECODE_ME_CHECK(c.gq(home, n)); 67 return ES_OK; 68 } 69 forceinline ExecStatus 70 FixDim::lec(Space& home, int n) { 71 GECODE_ME_CHECK(c.lq(home, n - s)); 72 return ES_OK; 73 } 74 forceinline ExecStatus 75 FixDim::nooverlap(Space& home, int n, int m) { 76 if (n <= m) { 77 Iter::Ranges::Singleton r(n-s+1,m); 78 GECODE_ME_CHECK(c.minus_r(home,r,false)); 79 } 80 return ES_OK; 81 } 82 forceinline ExecStatus 83 FixDim::nooverlap(Space& home, FixDim& d) { 84 if (d.sec() > lsc()) { 85 // Propagate that d must be after this 86 GECODE_ES_CHECK(lec(home,d.lsc())); 87 GECODE_ES_CHECK(d.ssc(home,sec())); 88 } else { 89 nooverlap(home, d.lsc(), d.sec()-1); 90 } 91 return ES_OK; 92 } 93 94 forceinline void 95 FixDim::update(Space& home, FixDim& d) { 96 c.update(home,d.c); 97 s = d.s; 98 } 99 100 forceinline void 101 FixDim::subscribe(Space& home, Propagator& p) { 102 c.subscribe(home,p,PC_INT_DOM); 103 } 104 forceinline void 105 FixDim::cancel(Space& home, Propagator& p) { 106 c.cancel(home,p,PC_INT_DOM); 107 } 108 forceinline void 109 FixDim::reschedule(Space& home, Propagator& p) { 110 c.reschedule(home,p,PC_INT_DOM); 111 } 112 113 114 /* 115 * Dimension with integer view size 116 * 117 */ 118 forceinline 119 FlexDim::FlexDim(void) {} 120 forceinline 121 FlexDim::FlexDim(IntView c00, IntView s0, IntView c10) 122 : c0(c00), s(s0), c1(c10) {} 123 124 forceinline int 125 FlexDim::ssc(void) const { 126 return c0.min(); 127 } 128 forceinline int 129 FlexDim::lsc(void) const { 130 return c0.max(); 131 } 132 forceinline int 133 FlexDim::sec(void) const { 134 return c1.min(); 135 } 136 forceinline int 137 FlexDim::lec(void) const { 138 return c1.max(); 139 } 140 141 forceinline ExecStatus 142 FlexDim::ssc(Space& home, int n) { 143 GECODE_ME_CHECK(c0.gq(home, n)); 144 return ES_OK; 145 } 146 forceinline ExecStatus 147 FlexDim::lec(Space& home, int n) { 148 GECODE_ME_CHECK(c1.lq(home, n)); 149 return ES_OK; 150 } 151 forceinline ExecStatus 152 FlexDim::nooverlap(Space& home, int n, int m) { 153 if (n <= m) { 154 Iter::Ranges::Singleton r0(n-s.min()+1,m); 155 GECODE_ME_CHECK(c0.minus_r(home,r0,false)); 156 Iter::Ranges::Singleton r1(n+1,s.min()+m); 157 GECODE_ME_CHECK(c1.minus_r(home,r1,false)); 158 } 159 return ES_OK; 160 } 161 forceinline ExecStatus 162 FlexDim::nooverlap(Space& home, FlexDim& d) { 163 if (d.sec() > lsc()) { 164 // Propagate that d must be after this 165 GECODE_ES_CHECK(lec(home,d.lsc())); 166 GECODE_ES_CHECK(d.ssc(home,sec())); 167 } else { 168 nooverlap(home, d.lsc(), d.sec()-1); 169 } 170 return ES_OK; 171 } 172 173 174 forceinline void 175 FlexDim::update(Space& home, FlexDim& d) { 176 c0.update(home,d.c0); 177 s.update(home,d.s); 178 c1.update(home,d.c1); 179 } 180 181 forceinline void 182 FlexDim::subscribe(Space& home, Propagator& p) { 183 c0.subscribe(home,p,PC_INT_DOM); 184 s.subscribe(home,p,PC_INT_BND); 185 c1.subscribe(home,p,PC_INT_DOM); 186 } 187 forceinline void 188 FlexDim::cancel(Space& home, Propagator& p) { 189 c0.cancel(home,p,PC_INT_DOM); 190 s.cancel(home,p,PC_INT_BND); 191 c1.cancel(home,p,PC_INT_DOM); 192 } 193 forceinline void 194 FlexDim::reschedule(Space& home, Propagator& p) { 195 c0.reschedule(home,p,PC_INT_DOM); 196 s.reschedule(home,p,PC_INT_BND); 197 c1.reschedule(home,p,PC_INT_DOM); 198 } 199 200}}} 201 202// STATISTICS: int-prop 203