/usr/include/gecode/kernel/brancher-view-val.hpp is in libgecode-dev 5.1.0-2build1.
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 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2012
*
* Last modified:
* $Date: 2017-04-01 20:27:10 +0200 (Sat, 01 Apr 2017) $ by $Author: schulte $
* $Revision: 15623 $
*
* 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 {
/**
* \defgroup TaskBranchViewVal Generic brancher based on view and value selection
*
* Implements view-based brancher for an array of views and value.
* \ingroup TaskActor
*/
//@{
/// %Choice storing position and value
template<class Val>
class GECODE_VTABLE_EXPORT PosValChoice : public PosChoice {
private:
/// Value to assign to
const Val _val;
public:
/// Initialize choice for brancher \a b, number of alternatives \a a, position \a p, and value \a n
PosValChoice(const Brancher& b, unsigned int a, const Pos& p, const Val& n);
/// Return value to branch with
const Val& val(void) const;
/// Report size occupied
virtual size_t size(void) const;
/// Archive into \a e
virtual void archive(Archive& e) const;
};
/// View-value no-good literal
template<class View, class Val, PropCond pc>
class ViewValNGL : public NGL {
protected:
/// The stored view
View x;
/// The stored value
Val n;
public:
/// Initialize for propagator \a p with view \a x and value \a n
ViewValNGL(Space& home, View x, Val n);
/// Constructor for cloning \a ngl
ViewValNGL(Space& home, bool share, ViewValNGL& ngl);
/// Create subscription for no-good literal
virtual void subscribe(Space& home, Propagator& p);
/// Cancel subscription for no-good literal
virtual void cancel(Space& home, Propagator& p);
/// Schedule propagator \a p
virtual void reschedule(Space& home, Propagator& p);
/// Dispose
virtual size_t dispose(Space& home);
};
/**
* \brief Generic brancher by view and value selection
*
* Implements view-based branching for an array of views (of type
* \a View) and value (of type \a Val).
*
*/
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
class ViewValBrancher : public ViewBrancher<View,Filter,n> {
protected:
using ViewBrancher<View,Filter,n>::vs;
using ViewBrancher<View,Filter,n>::x;
using ViewBrancher<View,Filter,n>::f;
/// The corresponding variable
typedef typename View::VarType Var;
/// Value selection and commit object
ValSelCommitBase<View,Val>* vsc;
/// Print function
Print p;
/// Constructor for cloning \a b
ViewValBrancher(Space& home, bool share, ViewValBrancher& b);
/// Constructor for creation
ViewValBrancher(Home home,
ViewArray<View>& x,
ViewSel<View>* vs[n],
ValSelCommitBase<View,Val>* vsc,
BranchFilter<Var> bf,
VarValPrint<Var,Val> vvp);
public:
/// Return choice
virtual const Choice* choice(Space& home);
/// Return choice
virtual const Choice* choice(const Space& home, Archive& e);
/// Perform commit for choice \a c and alternative \a b
virtual ExecStatus commit(Space& home, const Choice& c, unsigned int b);
/// Create no-good literal for choice \a c and alternative \a b
virtual NGL* ngl(Space& home, const Choice& c, unsigned int b) const;
/**
* \brief Print branch for choice \a c and alternative \a b
*
* Prints an explanation of the alternative \a b of choice \a c
* on the stream \a o.
*
*/
virtual void print(const Space& home, const Choice& c, unsigned int b,
std::ostream& o) const;
/// Perform cloning
virtual Actor* copy(Space& home, bool share);
/// Delete brancher and return its size
virtual size_t dispose(Space& home);
/// Brancher post function
static void post(Home home,
ViewArray<View>& x,
ViewSel<View>* vs[n],
ValSelCommitBase<View,Val>* vsc,
BranchFilter<Var> bf,
VarValPrint<Var,Val> vvp);
};
/// Post view value brancher
template<class View, int n, class Val, unsigned int a>
void
postviewvalbrancher(Home home,
ViewArray<View>& x,
ViewSel<View>* vs[n],
ValSelCommitBase<View,Val>* vsc,
BranchFilter<typename View::VarType> bf,
VarValPrint<typename View::VarType,Val> vvp);
//@}
/*
* %Choice with position and value
*
*/
template<class Val>
forceinline
PosValChoice<Val>::PosValChoice(const Brancher& b, unsigned int a,
const Pos& p, const Val& n)
: PosChoice(b,a,p), _val(n) {}
template<class Val>
forceinline const Val&
PosValChoice<Val>::val(void) const {
return _val;
}
template<class Val>
forceinline size_t
PosValChoice<Val>::size(void) const {
return sizeof(PosValChoice<Val>);
}
template<class Val>
forceinline void
PosValChoice<Val>::archive(Archive& e) const {
PosChoice::archive(e);
e << _val;
}
/*
* View-value no-good literal
*
*/
template<class View, class Val, PropCond pc>
forceinline
ViewValNGL<View,Val,pc>::ViewValNGL(Space& home, View x0, Val n0)
: NGL(home), x(x0), n(n0) {}
template<class View, class Val, PropCond pc>
forceinline
ViewValNGL<View,Val,pc>::ViewValNGL(Space& home, bool share, ViewValNGL& ngl)
: NGL(home,share,ngl), n(ngl.n) {
x.update(home,share,ngl.x);
}
template<class View, class Val, PropCond pc>
void
ViewValNGL<View,Val,pc>::subscribe(Space& home, Propagator& p) {
x.subscribe(home,p,pc);
}
template<class View, class Val, PropCond pc>
void
ViewValNGL<View,Val,pc>::cancel(Space& home, Propagator& p) {
x.cancel(home,p,pc);
}
template<class View, class Val, PropCond pc>
void
ViewValNGL<View,Val,pc>::reschedule(Space& home, Propagator& p) {
x.reschedule(home,p,pc);
}
template<class View, class Val, PropCond pc>
size_t
ViewValNGL<View,Val,pc>::dispose(Space& home) {
(void) NGL::dispose(home);
return sizeof(*this);
}
/*
* Generic brancher based on variable/value selection
*
*/
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
forceinline
ViewValBrancher<View,n,Val,a,Filter,Print>::
ViewValBrancher(Home home,
ViewArray<View>& x,
ViewSel<View>* vs[n],
ValSelCommitBase<View,Val>* vsc0,
BranchFilter<Var> bf,
VarValPrint<Var,Val> vvp)
: ViewBrancher<View,Filter,n>(home,x,vs,bf), vsc(vsc0), p(vvp) {
if (vsc->notice() || f.notice() || p.notice())
home.notice(*this,AP_DISPOSE,true);
}
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
forceinline void
ViewValBrancher<View,n,Val,a,Filter,Print>::
post(Home home, ViewArray<View>& x,
ViewSel<View>* vs[n], ValSelCommitBase<View,Val>* vsc,
BranchFilter<Var> bf,
VarValPrint<Var,Val> vvp) {
(void) new (home) ViewValBrancher<View,n,Val,a,Filter,Print>
(home,x,vs,vsc,bf,vvp);
}
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
forceinline
ViewValBrancher<View,n,Val,a,Filter,Print>::
ViewValBrancher(Space& home, bool shared,
ViewValBrancher<View,n,Val,a,Filter,Print>& b)
: ViewBrancher<View,Filter,n>(home,shared,b),
vsc(b.vsc->copy(home,shared)), p(home,shared,b.p) {}
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
Actor*
ViewValBrancher<View,n,Val,a,Filter,Print>::copy(Space& home, bool shared) {
return new (home) ViewValBrancher<View,n,Val,a,Filter,Print>
(home,shared,*this);
}
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
const Choice*
ViewValBrancher<View,n,Val,a,Filter,Print>::choice(Space& home) {
Pos p = ViewBrancher<View,Filter,n>::pos(home);
View v = ViewBrancher<View,Filter,n>::view(p);
return new PosValChoice<Val>(*this,a,p,vsc->val(home,v,p.pos));
}
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
const Choice*
ViewValBrancher<View,n,Val,a,Filter,Print>::choice(const Space& home,
Archive& e) {
(void) home;
int p; e >> p;
Val v; e >> v;
return new PosValChoice<Val>(*this,a,p,v);
}
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
ExecStatus
ViewValBrancher<View,n,Val,a,Filter,Print>
::commit(Space& home, const Choice& c, unsigned int b) {
const PosValChoice<Val>& pvc
= static_cast<const PosValChoice<Val>&>(c);
return me_failed(vsc->commit(home,b,
ViewBrancher<View,Filter,n>::view(pvc.pos()),
pvc.pos().pos,
pvc.val()))
? ES_FAILED : ES_OK;
}
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
NGL*
ViewValBrancher<View,n,Val,a,Filter,Print>
::ngl(Space& home, const Choice& c, unsigned int b) const {
const PosValChoice<Val>& pvc
= static_cast<const PosValChoice<Val>&>(c);
return vsc->ngl(home,b,
ViewBrancher<View,Filter,n>::view(pvc.pos()),pvc.val());
}
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
void
ViewValBrancher<View,n,Val,a,Filter,Print>
::print(const Space& home, const Choice& c, unsigned int b,
std::ostream& o) const {
const PosValChoice<Val>& pvc
= static_cast<const PosValChoice<Val>&>(c);
View xi = ViewBrancher<View,Filter,n>::view(pvc.pos());
if (p)
p(home,*this,b,xi,pvc.pos().pos,pvc.val(),o);
else
vsc->print(home,b,xi,pvc.pos().pos,pvc.val(),o);
}
template<class View, int n, class Val, unsigned int a,
class Filter, class Print>
forceinline size_t
ViewValBrancher<View,n,Val,a,Filter,Print>::dispose(Space& home) {
if (vsc->notice() || f.notice() || p.notice())
home.ignore(*this,AP_DISPOSE,true);
vsc->dispose(home);
(void) ViewBrancher<View,Filter,n>::dispose(home);
return sizeof(ViewValBrancher<View,n,Val,a,Filter,Print>);
}
template<class View, int n, class Val, unsigned int a>
forceinline void
postviewvalbrancher(Home home,
ViewArray<View>& x,
ViewSel<View>* vs[n],
ValSelCommitBase<View,Val>* vsc,
BranchFilter<typename View::VarType> bf,
VarValPrint<typename View::VarType,Val> vvp) {
if (bf) {
if (vvp) {
ViewValBrancher<View,n,Val,a,
BrancherFilter<View>,BrancherPrint<View,Val> >
::post(home,x,vs,vsc,bf,vvp);
} else {
ViewValBrancher<View,n,Val,a,
BrancherFilter<View>,BrancherNoPrint<View,Val> >
::post(home,x,vs,vsc,bf,vvp);
}
} else {
if (vvp)
ViewValBrancher<View,n,Val,a,
BrancherNoFilter<View>,BrancherPrint<View,Val> >
::post(home,x,vs,vsc,bf,vvp);
else
ViewValBrancher<View,n,Val,a,
BrancherNoFilter<View>,BrancherNoPrint<View,Val> >
::post(home,x,vs,vsc,bf,vvp);
}
}
}
// STATISTICS: kernel-branch
|