/usr/include/gecode/float/rel/eq.hpp is in libgecode-dev 4.4.0-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 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Copyright:
* Christian Schulte, 2004
* Vincent Barichard, 2012
*
* Last modified:
* $Date: 2013-01-24 19:28:06 +0100 (Thu, 24 Jan 2013) $ by $Author: schulte $
* $Revision: 13235 $
*
* 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 Float { namespace Rel {
/*
* Binary bounds consistent equality
*
*/
template<class View0, class View1>
forceinline
Eq<View0,View1>::Eq(Home home, View0 x0, View1 x1)
: MixBinaryPropagator<View0,PC_FLOAT_BND,View1,PC_FLOAT_BND>(home,x0,x1) {}
template<class View0, class View1>
ExecStatus
Eq<View0,View1>::post(Home home, View0 x0, View1 x1){
if (x0.assigned()) {
GECODE_ME_CHECK(x1.eq(home,x0.val()));
} else if (x1.assigned()) {
GECODE_ME_CHECK(x0.eq(home,x1.val()));
} else if (!same(x0,x1)) {
GECODE_ME_CHECK(x0.lq(home,x1.max()));
GECODE_ME_CHECK(x1.lq(home,x0.max()));
GECODE_ME_CHECK(x0.gq(home,x1.min()));
GECODE_ME_CHECK(x1.gq(home,x0.min()));
(void) new (home) Eq<View0,View1>(home,x0,x1);
}
return ES_OK;
}
template<class View0, class View1>
forceinline
Eq<View0,View1>::Eq(Space& home, bool share, Eq<View0,View1>& p)
: MixBinaryPropagator<View0,PC_FLOAT_BND,View1,PC_FLOAT_BND>(home,share,p) {}
template<class View0, class View1>
forceinline
Eq<View0,View1>::Eq(Space& home, bool share, Propagator& p,
View0 x0, View1 x1)
: MixBinaryPropagator<View0,PC_FLOAT_BND,View1,PC_FLOAT_BND>(home,share,p,
x0,x1) {}
template<class View0, class View1>
Actor*
Eq<View0,View1>::copy(Space& home, bool share) {
return new (home) Eq<View0,View1>(home,share,*this);
}
template<class View0, class View1>
ExecStatus
Eq<View0,View1>::propagate(Space& home, const ModEventDelta&) {
if (x0.assigned()) {
GECODE_ME_CHECK(x1.eq(home,x0.val()));
} else if (x1.assigned()) {
GECODE_ME_CHECK(x0.eq(home,x1.val()));
} else {
do {
GECODE_ME_CHECK(x0.gq(home,x1.min()));
GECODE_ME_CHECK(x1.gq(home,x0.min()));
} while (x0.min() != x1.min());
do {
GECODE_ME_CHECK(x0.lq(home,x1.max()));
GECODE_ME_CHECK(x1.lq(home,x0.max()));
} while (x0.max() != x1.max());
if (!x0.assigned())
return ES_FIX;
}
assert(x0.assigned() && x1.assigned());
return home.ES_SUBSUMED(*this);
}
/*
* Nary bound consistent equality
*
*/
template<class View>
forceinline
NaryEq<View>::NaryEq(Home home, ViewArray<View>& x)
: NaryPropagator<View,PC_FLOAT_BND>(home,x) {}
template<class View>
ExecStatus
NaryEq<View>::post(Home home, ViewArray<View>& x) {
x.unique(home);
if (x.size() == 2) {
return Eq<View,View>::post(home,x[0],x[1]);
} else if (x.size() > 2) {
FloatNum l = x[0].min();
FloatNum u = x[0].max();
for (int i=x.size(); i-- > 1; ) {
l = std::max(l,x[i].min());
u = std::min(u,x[i].max());
}
for (int i=x.size(); i--; ) {
GECODE_ME_CHECK(x[i].gq(home,l));
GECODE_ME_CHECK(x[i].lq(home,u));
}
(void) new (home) NaryEq<View>(home,x);
}
return ES_OK;
}
template<class View>
forceinline
NaryEq<View>::NaryEq(Space& home, bool share, NaryEq<View>& p)
: NaryPropagator<View,PC_FLOAT_BND>(home,share,p) {}
template<class View>
Actor*
NaryEq<View>::copy(Space& home, bool share) {
return new (home) NaryEq<View>(home,share,*this);
}
template<class View>
PropCost
NaryEq<View>::cost(const Space&, const ModEventDelta& med) const {
if (View::me(med) == ME_FLOAT_VAL)
return PropCost::unary(PropCost::LO);
else
return PropCost::linear(PropCost::LO, x.size());
}
template<class View>
ExecStatus
NaryEq<View>::propagate(Space& home, const ModEventDelta& med) {
assert(x.size() > 2);
if (View::me(med) == ME_FLOAT_VAL) {
// One of the variables is assigned
for (int i = 0; ; i++)
if (x[i].assigned()) {
FloatVal n = x[i].val();
x.move_lst(i);
for (int j = x.size(); j--; )
GECODE_ME_CHECK(x[j].eq(home,n));
return home.ES_SUBSUMED(*this);
}
GECODE_NEVER;
}
FloatNum mn = x[0].min();
restart_min:
for (int i = x.size(); i--; ) {
GECODE_ME_CHECK(x[i].gq(home,mn));
if (mn < x[i].min()) {
mn = x[i].min();
goto restart_min;
}
}
FloatNum mx = x[0].max();
restart_max:
for (int i = x.size(); i--; ) {
GECODE_ME_CHECK(x[i].lq(home,mx));
if (mx > x[i].max()) {
mx = x[i].max();
goto restart_max;
}
}
return x[0].assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
}
/*
* Reified bounds consistent equality
*
*/
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReEq<View,CtrlView,rm>::ReEq(Home home, View x0, View x1, CtrlView b)
: Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x0,x1,b) {}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReEq<View,CtrlView,rm>::post(Home home, View x0, View x1, CtrlView b){
if (b.one()) {
if (rm == RM_PMI)
return ES_OK;
return Eq<View,View>::post(home,x0,x1);
}
if (b.zero()) {
if (rm == RM_IMP)
return ES_OK;
return Nq<View,View>::post(home,x0,x1);
}
if (!same(x0,x1)) {
(void) new (home) ReEq(home,x0,x1,b);
} else if (rm != RM_IMP) {
GECODE_ME_CHECK(b.one(home));
}
return ES_OK;
}
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReEq<View,CtrlView,rm>::ReEq(Space& home, bool share, ReEq& p)
: Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,share,p) {}
template<class View, class CtrlView, ReifyMode rm>
Actor*
ReEq<View,CtrlView,rm>::copy(Space& home, bool share) {
return new (home) ReEq<View,CtrlView,rm>(home,share,*this);
}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReEq<View,CtrlView,rm>::propagate(Space& home, const ModEventDelta&) {
if (b.one()) {
if (rm == RM_PMI)
return home.ES_SUBSUMED(*this);
GECODE_REWRITE(*this,(Eq<View,View>::post(home(*this),x0,x1)));
}
if (b.zero()) {
if (rm == RM_IMP)
return home.ES_SUBSUMED(*this);
GECODE_REWRITE(*this,(Nq<View,View>::post(home(*this),x0,x1)));
}
switch (rtest_eq(x0,x1)) {
case RT_TRUE:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one_none(home));
break;
case RT_FALSE:
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero_none(home));
break;
case RT_MAYBE:
return ES_FIX;
default: GECODE_NEVER;
}
return home.ES_SUBSUMED(*this);
}
/*
* Reified bounds consistent equality (one variable)
*
*/
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReEqFloat<View,CtrlView,rm>::ReEqFloat
(Home home, View x, FloatVal c0, CtrlView b)
: Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x,b), c(c0) {}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReEqFloat<View,CtrlView,rm>::post(Home home, View x, FloatVal c, CtrlView b) {
if (b.one()) {
if (rm != RM_PMI)
GECODE_ME_CHECK(x.eq(home,c));
} else if (x.assigned()) {
if (overlap(x.val(),c)) {
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one(home));
} else {
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
}
} else {
(void) new (home) ReEqFloat(home,x,c,b);
}
return ES_OK;
}
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReEqFloat<View,CtrlView,rm>::ReEqFloat(Space& home, bool share, ReEqFloat& p)
: Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,share,p), c(p.c) {}
template<class View, class CtrlView, ReifyMode rm>
Actor*
ReEqFloat<View,CtrlView,rm>::copy(Space& home, bool share) {
return new (home) ReEqFloat<View,CtrlView,rm>(home,share,*this);
}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReEqFloat<View,CtrlView,rm>::propagate(Space& home, const ModEventDelta&) {
if (b.one()) {
if (rm != RM_PMI)
GECODE_ME_CHECK(x0.eq(home,c));
} else {
switch (rtest_eq(x0,c)) {
case RT_TRUE:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one(home));
break;
case RT_FALSE:
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
break;
case RT_MAYBE:
return ES_FIX;
default: GECODE_NEVER;
}
}
return home.ES_SUBSUMED(*this);
}
}}}
// STATISTICS: float-prop
|