/usr/include/gecode/int/channel/dom.hpp is in libgecode-dev 3.7.1-3.
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 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Contributing authors:
* Mikael Lagerkvist <lagerkvist@gecode.org>
*
* Copyright:
* Christian Schulte, 2006
* Mikael Lagerkvist, 2006
*
* Last modified:
* $Date: 2011-09-06 14:19:49 +0200 (Tue, 06 Sep 2011) $ by $Author: schulte $
* $Revision: 12393 $
*
* 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 Int { namespace Channel {
/**
* \brief Combine view with information for domain propagation
*
*/
template<class View, class Offset>
class DomInfo {
public:
/// The view
View view;
/// Last propagated size
unsigned int size;
/// Last propagated minimum
int min;
/// Last propagated maximum
int max;
/// Initialize
void init(View x, int n);
/// Update during cloning
void update(Space& home, bool share, DomInfo<View,Offset>& vcb);
/// Check whether propagation for assignment is to be done
bool doval(void) const;
/// Check whether propagation for domain is to be done
bool dodom(void) const;
/// Record that view got assigned
void assigned(void);
/// Record that one value got removed
void removed(int i);
/// Update the size and bounds information after pruning
void done(Offset& o);
};
template<class View, class Offset>
forceinline void
DomInfo<View,Offset>::init(View x, int n) {
view = x;
size = static_cast<unsigned int>(n);
min = 0;
max = n-1;
}
template<class View, class Offset>
forceinline void
DomInfo<View,Offset>::update(Space& home, bool share,
DomInfo<View,Offset>& di) {
view.update(home,share,di.view);
size = di.size;
min = di.min;
max = di.max;
}
template<class View, class Offset>
forceinline bool
DomInfo<View,Offset>::doval(void) const {
return (size != 1) && view.assigned();
}
template<class View, class Offset>
forceinline bool
DomInfo<View,Offset>::dodom(void) const {
return size != view.size();
}
template<class View, class Offset>
forceinline void
DomInfo<View,Offset>::assigned(void) {
size = 1;
}
template<class View, class Offset>
forceinline void
DomInfo<View,Offset>::removed(int i) {
size--;
if (i == min)
min++;
else if (i == max)
max--;
}
template<class View, class Offset>
forceinline void
DomInfo<View,Offset>::done(Offset& o) {
size = view.size();
min = o(view).min();
max = o(view).max();
}
// Propagate domain information from x to y
template<class View, class Offset>
ExecStatus
prop_dom(Space& home, int n, DomInfo<View,Offset>* x, Offset& ox,
DomInfo<View,Offset>* y, Offset& oy, ProcessStack& ya) {
for (int i = n; i--; )
// Only views with not yet propagated missing values
if (x[i].dodom()) {
// Iterate the values in the complement of x[i]
ViewRanges<typename Offset::ViewType>
xir(ox(x[i].view));
Iter::Ranges::ComplVal<ViewRanges<typename Offset::ViewType> >
xirc(x[i].min,x[i].max,xir);
Iter::Ranges::ToValues<Iter::Ranges::ComplVal<
ViewRanges<typename Offset::ViewType> > > jv(xirc);
while (jv()) {
// j is not in the domain of x[i], so prune i from y[j]
int j = jv.val();
ModEvent me = oy(y[j].view).nq(home,i);
if (me_failed(me))
return ES_FAILED;
if (me_modified(me)) {
if (me == ME_INT_VAL) {
// Record that y[j] has been assigned and must be propagated
ya.push(j);
} else {
// Obvious as x[i] is different from j
y[j].removed(i);
}
}
++jv;
}
// Update which values have been propagated and what are the new bounds
x[i].done(ox);
}
return ES_OK;
}
/*
* The actual propagator
*
*/
template<class View, class Offset, bool shared>
forceinline
Dom<View,Offset,shared>::Dom(Home home, int n, DomInfo<View,Offset>* xy,
Offset& ox, Offset& oy)
: Base<DomInfo<View,Offset>,Offset,PC_INT_DOM>(home,n,xy,ox,oy) {}
template<class View, class Offset, bool shared>
forceinline
Dom<View,Offset,shared>::Dom(Space& home, bool share,
Dom<View,Offset,shared>& p)
: Base<DomInfo<View,Offset>,Offset,PC_INT_DOM>(home,share,p) {}
template<class View, class Offset, bool shared>
Actor*
Dom<View,Offset,shared>::copy(Space& home, bool share) {
return new (home) Dom<View,Offset,shared>(home,share,*this);
}
template<class View, class Offset, bool shared>
PropCost
Dom<View,Offset,shared>::cost(const Space&,
const ModEventDelta& med) const {
if (View::me(med) == ME_INT_VAL)
return PropCost::quadratic(PropCost::LO, 2*n);
else
return PropCost::quadratic(PropCost::HI, 2*n);
}
template<class View, class Offset, bool shared>
ExecStatus
Dom<View,Offset,shared>::propagate(Space& home, const ModEventDelta& med) {
Region r(home);
ProcessStack xa(r,n);
ProcessStack ya(r,n);
DomInfo<View,Offset>* x = xy;
DomInfo<View,Offset>* y = xy+n;
if (View::me(med) == ME_INT_VAL) {
// Scan x and y for assigned but not yet propagated views
for (int i = n; i--; ) {
if (x[i].doval()) xa.push(i);
if (y[i].doval()) ya.push(i);
}
if (shared) {
do {
// Propagate assigned views for x
GECODE_ES_CHECK((prop_val<View,Offset,DomInfo<View,Offset> >
(home,n,x,ox,y,oy,n_na,xa,ya)));
// Propagate assigned views for y
GECODE_ES_CHECK((prop_val<View,Offset,DomInfo<View,Offset> >
(home,n,y,oy,x,ox,n_na,ya,xa)));
assert(ya.empty());
} while (!xa.empty() || !ya.empty());
return home.ES_NOFIX_PARTIAL(*this,View::med(ME_INT_DOM));
} else {
do {
// Propagate assigned views for x
GECODE_ES_CHECK((prop_val<View,Offset,DomInfo<View,Offset> >
(home,n,x,ox,y,oy,n_na,xa,ya)));
// Propagate assigned views for y
GECODE_ES_CHECK((prop_val<View,Offset,DomInfo<View,Offset> >
(home,n,y,oy,x,ox,n_na,ya,xa)));
assert(ya.empty());
} while (!xa.empty());
return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
}
}
// Process changed views for y
// This propagates from y to x and possibly records xs that
// got assigned
GECODE_ES_CHECK(prop_dom(home,n,y,oy,x,ox,xa));
// Process assigned views for x
GECODE_ES_CHECK((prop_val<View,Offset,DomInfo<View,Offset> >
(home,n,x,ox,y,oy,n_na,xa,ya)));
// Perform domain consistent propagation for distinct on the x views
if (dc.available()) {
GECODE_ES_CHECK(dc.sync(home));
} else {
ViewArray<View> xv(r,n);
for (int i=n; i--; )
xv[i] = x[i].view;
GECODE_ES_CHECK(dc.init(home,xv));
}
bool assigned;
GECODE_ES_CHECK(dc.propagate(home,assigned));
if (assigned) {
// This has assigned some more views in x which goes unnoticed
// (that is, not recorded in xa). This must be checked and propagated
// to the y views, however the distinctness on x is already
// propagated.
for (int i=n; i--; )
if (x[i].doval()) {
int j = ox(x[i].view).val();
// Assign the y variable to i (or test if already assigned!)
ModEvent me = oy(y[j].view).eq(home,i);
if (me_failed(me))
return ES_FAILED;
if (me_modified(me)) {
// Record that y[j] has been assigned and must be propagated
assert(me == ME_INT_VAL);
// Otherwise the modification event would not be ME_INT_VAL
ya.push(j);
}
x[i].assigned(); n_na--;
}
}
// Process changed views for x
// This propagates from x to y and possibly records ys that
// got assigned
GECODE_ES_CHECK(prop_dom(home,n,x,ox,y,oy,ya));
// Process assigned view again (some might have been found above)
while (!xa.empty() || !ya.empty()) {
// Process assigned views for x
GECODE_ES_CHECK((prop_val<View,Offset,DomInfo<View,Offset> >
(home,n,x,ox,y,oy,n_na,xa,ya)));
// Process assigned views for y
GECODE_ES_CHECK((prop_val<View,Offset,DomInfo<View,Offset> >
(home,n,y,oy,x,ox,n_na,ya,xa)));
};
if (shared) {
for (int i=2*n; i--; )
if (!xy[i].view.assigned())
return ES_NOFIX;
return home.ES_SUBSUMED(*this);
} else {
return (n_na == 0) ? home.ES_SUBSUMED(*this) : ES_FIX;
}
}
template<class View, class Offset, bool shared>
ExecStatus
Dom<View,Offset,shared>::post(Home home, int n, DomInfo<View,Offset>* xy,
Offset& ox, Offset& oy) {
assert(n > 0);
if (n == 1) {
GECODE_ME_CHECK(ox(xy[0].view).eq(home,0));
GECODE_ME_CHECK(oy(xy[1].view).eq(home,0));
return ES_OK;
}
for (int i=n; i--; ) {
GECODE_ME_CHECK(ox(xy[i ].view).gq(home,0));
GECODE_ME_CHECK(ox(xy[i ].view).le(home,n));
GECODE_ME_CHECK(oy(xy[i+n].view).gq(home,0));
GECODE_ME_CHECK(oy(xy[i+n].view).le(home,n));
}
(void) new (home) Dom<View,Offset,shared>(home,n,xy,ox,oy);
return ES_OK;
}
}}}
// STATISTICS: int-prop
|