/usr/include/gecode/set/rel-op/inter.hpp is in libgecode-dev 4.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
* Christian Schulte <schulte@gecode.org>
*
* Contributing authors:
* Gabor Szokoli <szokoli@gecode.org>
*
* Copyright:
* Guido Tack, 2004
* Christian Schulte, 2004
* Gabor Szokoli, 2004
*
* Last modified:
* $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
* $Revision: 13068 $
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
namespace Gecode { namespace Set { namespace RelOp {
/*
* "Ternary intersection" propagator
*
*/
template<class View0, class View1, class View2> ExecStatus
Intersection<View0,View1,View2>::post(Home home,
View0 x0,View1 x1,View2 x2) {
(void) new (home) Intersection<View0,View1,View2>(home,x0,x1,x2);
return ES_OK;
}
template<class View0, class View1, class View2>
Actor*
Intersection<View0,View1,View2>::copy(Space& home, bool share) {
return new (home) Intersection(home,share,*this);
}
template<class View0, class View1, class View2>
ExecStatus
Intersection<View0,View1,View2>::propagate(Space& home, const ModEventDelta& med) {
// This propagator implements the constraint
// x2 = x0 \cap x1
bool x0ass = x0.assigned();
bool x1ass = x1.assigned();
bool x2ass = x2.assigned();
ModEvent me0 = View0::me(med);
ModEvent me1 = View1::me(med);
ModEvent me2 = View2::me(med);
bool x0lbmod = false;
bool x1lbmod = false;
bool modified = false;
do {
modified = false;
do {
// 4) glb(x2) <= glb(x0) \cap glb(x1)
{
GlbRanges<View0> x0lb(x0);
GlbRanges<View1> x1lb(x1);
Iter::Ranges::Inter<GlbRanges<View0>, GlbRanges<View1> >
i2(x0lb,x1lb);
GECODE_ME_CHECK_MODIFIED(modified, x2.includeI(home,i2) );
}
if (modified || Rel::testSetEventLB(me2) )
{
modified = false;
// 5) x2 <= x0
GlbRanges<View2> x2lb1(x2);
GECODE_ME_CHECK_MODIFIED(modified, x0.includeI(home,x2lb1) );
x0lbmod |= modified;
// 6) x2 <= x1
bool modified2=false;
GlbRanges<View2> x2lb2(x2);
GECODE_ME_CHECK_MODIFIED(modified2, x1.includeI(home,x2lb2) );
x1lbmod |= modified2;
modified |= modified2;
}
} while (modified);
modified = false;
do {
bool modifiedOld = modified;
modified = false;
if (Rel::testSetEventUB(me2) || Rel::testSetEventLB(me0)
|| x0lbmod || modifiedOld)
{
// 1) lub(x2) \ glb(x0) => lub(x1)
GlbRanges<View0> x0lb(x0);
LubRanges<View2> x2ub(x2);
Iter::Ranges::Diff<GlbRanges<View0>,LubRanges<View2> >
diff(x0lb, x2ub);
GECODE_ME_CHECK_MODIFIED(modified, x1.excludeI(home,diff) );
}
if (Rel::testSetEventUB(me2) || Rel::testSetEventLB(me1)
|| x1lbmod || modifiedOld)
{
// 2) lub(x2) \ glb(x1) => lub(x0)
GlbRanges<View1> x1lb(x1);
LubRanges<View2> x2ub(x2);
Iter::Ranges::Diff<GlbRanges<View1>, LubRanges<View2> >
diff(x1lb, x2ub);
GECODE_ME_CHECK_MODIFIED(modified, x0.excludeI(home,diff) );
}
if (Rel::testSetEventUB(me0,me1) || modified)
{
// modified = false;
// 3) lub(x0) \cap lub(x1) <= lub(x2)
LubRanges<View0> x0ub(x0);
LubRanges<View1> x1ub(x1);
Iter::Ranges::Inter<LubRanges<View0>, LubRanges<View1> >
i1(x0ub,x1ub);
GECODE_ME_CHECK_MODIFIED(modified, x2.intersectI(home,i1) );
}
} while(modified);
modified = false;
{
// cardinality
ExecStatus ret = interCard(home,modified, x0, x1, x2);
GECODE_ES_CHECK(ret);
}
if (x2.cardMin() == Set::Limits::card) {
GECODE_ME_CHECK( x0.cardMin(home, Set::Limits::card) );
GECODE_ME_CHECK( x1.cardMin(home, Set::Limits::card) );
return home.ES_SUBSUMED(*this);
}
if (x0.cardMin() == Set::Limits::card)
GECODE_REWRITE(*this,(Rel::Eq<View1,View2>::post(home(*this),x1,x2)));
if (x1.cardMin() == Set::Limits::card)
GECODE_REWRITE(*this,(Rel::Eq<View0,View2>::post(home(*this),x0,x2)));
} while(modified);
if (shared(x0,x1,x2)) {
return (x0ass && x1ass && x2ass) ? home.ES_SUBSUMED(*this) : ES_NOFIX;
} else {
if (x0ass && x1ass && x2ass)
return home.ES_SUBSUMED(*this);
if (x0ass != x0.assigned() ||
x1ass != x1.assigned() ||
x2ass != x2.assigned()) {
return ES_NOFIX;
} else {
return ES_FIX;
}
}
}
template<class View0, class View1, class View2>
forceinline
Intersection<View0,View1,View2>::Intersection(Home home,
View0 y0,View1 y1,View2 y2)
: MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
View2,PC_SET_ANY>(home,y0,y1,y2) {}
template<class View0, class View1, class View2>
forceinline
Intersection<View0,View1,View2>::Intersection(Space& home, bool share,
Intersection<View0,View1,View2>& p)
: MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
View2,PC_SET_ANY>(home,share,p) {}
/*
* "Nary intersection" propagator
*
*/
template<class View0, class View1>
forceinline
IntersectionN<View0,View1>::IntersectionN(Home home, ViewArray<View0>& x,
View1 y)
: MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,x,y),
intOfDets(home) {
shared = x.shared(home) || viewarrayshared(home,x,y);
}
template<class View0, class View1>
forceinline
IntersectionN<View0,View1>::IntersectionN(Home home, ViewArray<View0>& x,
const IntSet& z, View1 y)
: MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,x,y),
intOfDets(home) {
shared = x.shared(home) || viewarrayshared(home,x,y);
IntSetRanges rz(z);
intOfDets.intersectI(home, rz);
}
template<class View0, class View1>
forceinline
IntersectionN<View0,View1>::IntersectionN(Space& home, bool share,
IntersectionN& p)
: MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,share,p),
shared(p.shared),
intOfDets() {
intOfDets.update(home, p.intOfDets);
}
template<class View0, class View1>
ExecStatus
IntersectionN<View0,View1>::post(Home home,
ViewArray<View0>& x, View1 y) {
switch (x.size()) {
case 0:
GECODE_ME_CHECK(y.cardMin(home, Limits::card));
return ES_OK;
case 1:
return Rel::Eq<View0,View1>::post(home, x[0], y);
case 2:
return Intersection<View0,View0,View1>::post(home, x[0], x[1], y);
default:
(void) new (home) IntersectionN<View0,View1>(home,x,y);
return ES_OK;
}
}
template<class View0, class View1>
ExecStatus
IntersectionN<View0,View1>::post(Home home, ViewArray<View0>& x,
const IntSet& z, View1 y) {
(void) new (home) IntersectionN<View0,View1>(home,x,z,y);
return ES_OK;
}
template<class View0, class View1>
Actor*
IntersectionN<View0,View1>::copy(Space& home, bool share) {
return new (home) IntersectionN<View0,View1>(home,share,*this);
}
template<class View0, class View1>
PropCost
IntersectionN<View0,View1>::cost(const Space&, const ModEventDelta&) const {
return PropCost::quadratic(PropCost::HI, x.size()+1);
}
template<class View0, class View1>
ExecStatus
IntersectionN<View0,View1>::propagate(Space& home, const ModEventDelta&) {
bool repeat = false;
do {
repeat = false;
int xsize = x.size();
if (xsize == 0)
goto size0;
for (int i = xsize; i--; ) {
GECODE_ME_CHECK( y.cardMax(home,x[i].cardMax()) );
GECODE_ME_CHECK( x[i].cardMin(home,y.cardMin()) );
if (x[i].cardMax()==0) {
GECODE_ME_CHECK( y.cardMax(home, 0));
intOfDets.dispose(home);
return home.ES_SUBSUMED(*this);
}
}
{
Region r(home);
GlbRanges<View0>* xLBs = r.alloc<GlbRanges<View0> >(xsize);
LubRanges<View0>* xUBs = r.alloc<LubRanges<View0> >(xsize);
for (int i = xsize; i--; ) {
GlbRanges<View0> lb(x[i]);
LubRanges<View0> ub(x[i]);
xLBs[i]=lb;
xUBs[i]=ub;
}
{
Iter::Ranges::NaryInter lbi(r,xLBs,xsize);
BndSetRanges dets(intOfDets);
lbi &= dets;
GECODE_ME_CHECK(y.includeI(home,lbi));
}
{
Iter::Ranges::NaryInter ubi(r,xUBs,xsize);
BndSetRanges dets(intOfDets);
ubi &= dets;
GECODE_ME_CHECK(y.intersectI(home,ubi));
}
}
for (int i = xsize; i--; ) {
GlbRanges<View1> ylb(y);
GECODE_ME_CHECK( x[i].includeI(home,ylb) );
}
// xi.exclude (Intersection(xj.lb) - y.ub)
{
Region r(home);
GLBndSet* rightSet =
static_cast<GLBndSet*>(r.ralloc(sizeof(GLBndSet)*xsize));
new (&rightSet[xsize-1]) GLBndSet(home);
rightSet[xsize-1].update(home,intOfDets);
for (int i=xsize-1;i--;) {
GlbRanges<View0> xilb(x[i+1]);
BndSetRanges prev(rightSet[i+1]);
Iter::Ranges::Inter<GlbRanges<View0>,
BndSetRanges> inter(xilb,prev);
new (&rightSet[i]) GLBndSet(home);
rightSet[i].includeI(home,inter);
}
LUBndSet leftAcc(home);
for (int i=0;i<xsize;i++) {
BndSetRanges left(leftAcc);
BndSetRanges right(rightSet[i]);
Iter::Ranges::Inter<BndSetRanges,
BndSetRanges> inter(left, right);
LubRanges<View1> yub(y);
Iter::Ranges::Diff<Iter::Ranges::Inter<BndSetRanges,
BndSetRanges>, LubRanges<View1> >
forbidden(inter, yub);
GECODE_ME_CHECK( x[i].excludeI(home,forbidden) );
GlbRanges<View0> xlb(x[i]);
leftAcc.intersectI(home,xlb);
}
for (int i=xsize; i--;)
rightSet[i].dispose(home);
leftAcc.dispose(home);
}
for(int i=0;i<x.size();i++){
//Do not reverse! Eats away the end of the array!
while (i<x.size() && x[i].assigned()) {
GlbRanges<View0> det(x[i]);
if (intOfDets.intersectI(home,det)) {repeat = true;}
x.move_lst(i);
if (intOfDets.size()==0) {
GECODE_ME_CHECK( y.cardMax(home,0) );
intOfDets.dispose(home);
return home.ES_SUBSUMED(*this);
}
}
}
size0:
if (x.size()==0) {
BndSetRanges all1(intOfDets);
GECODE_ME_CHECK( y.intersectI(home,all1) );
BndSetRanges all2(intOfDets);
GECODE_ME_CHECK( y.includeI(home,all2) );
intOfDets.dispose(home);
return home.ES_SUBSUMED(*this);
}
} while (repeat);
return shared ? ES_NOFIX : ES_FIX;
}
}}}
// STATISTICS: set-prop
|