/usr/include/gecode/kernel/view.hpp is in libgecode-dev 3.7.3-1.
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 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2005
*
* Last modified:
* $Date: 2010-10-11 21:10:44 +1100 (Mon, 11 Oct 2010) $ by $Author: tack $
* $Revision: 11514 $
*
* 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 {
/**
* \brief Base-class for constant views
* \ingroup TaskVarView
*/
template<class View>
class ConstView {
public:
/// The variable implementation type corresponding to the constant view
typedef typename View::VarImpType VarImpType;
/// The variable type corresponding to the constant view
typedef typename View::VarType VarType;
/// \name Generic view information
//@{
/// Return degree (number of subscribed propagators and advisors)
unsigned int degree(void) const;
/// Return accumulated failure count (plus degree)
double afc(void) const;
/// Return whether this view is derived from a VarImpView
static bool varderived(void);
/// Return dummy variable implementation of view
VarImpType* varimp(void) const;
//@}
/// \name Domain tests
//@{
/// Test whether view is assigned
bool assigned(void) const;
//@}
/// \name View-dependent propagator support
//@{
/// Schedule propagator \a p with modification event \a me
static void schedule(Space& home, Propagator& p, ModEvent me);
/// Return modification event for view type in \a med
static ModEvent me(const ModEventDelta& med);
/// Translate modification event \a me to modification event delta for view
static ModEventDelta med(ModEvent me);
//@}
/// \name Dependencies
//@{
/**
* \brief Subscribe propagator \a p with propagation condition \a pc to view
*
* In case \a schedule is false, the propagator is just subscribed but
* not scheduled for execution (this must be used when creating
* subscriptions during propagation).
*/
void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
/// Cancel subscription of propagator \a p with propagation condition \a pc to view
void cancel(Space& home, Propagator& p, PropCond pc);
/// Subscribe advisor \a a to view
void subscribe(Space& home, Advisor& a);
/// Cancel subscription of advisor \a a
void cancel(Space& home, Advisor& a);
//@}
/// \name Delta information for advisors
//@{
/// Return modification event
static ModEvent modevent(const Delta& d);
//@}
/// \name Cloning
//@{
/// Update this view to be a clone of view \a y
void update(Space& home, bool share, ConstView& y);
//@}
};
/**
* \brief Base-class for variable implementation views
* \ingroup TaskVarView
*/
template<class Var>
class VarImpView {
public:
/// The variable type corresponding to the view
typedef Var VarType;
/// The variable implementation type corresponding to the view
typedef typename Var::VarImpType VarImpType;
protected:
/// Pointer to variable implementation
VarImpType* x;
/// Default constructor
VarImpView(void);
/// Initialize with variable implementation \a y
VarImpView(VarImpType* y);
public:
/// \name Generic view information
//@{
/// Return whether this view is derived from a VarImpView
static bool varderived(void);
/// Return variable implementation of view
VarImpType* varimp(void) const;
/// Return degree (number of subscribed propagators and advisors)
unsigned int degree(void) const;
/// Return accumulated failure count (plus degree)
double afc(void) const;
//@}
/// \name Domain tests
//@{
/// Test whether view is assigned
bool assigned(void) const;
//@}
/// \name View-dependent propagator support
//@{
/// Schedule propagator \a p with modification event \a me
static void schedule(Space& home, Propagator& p, ModEvent me);
/// Return modification event for view type in \a med
static ModEvent me(const ModEventDelta& med);
/// Translate modification event \a me to modification event delta for view
static ModEventDelta med(ModEvent me);
//@}
/// \name Dependencies
//@{
/**
* \brief Subscribe propagator \a p with propagation condition \a pc to view
*
* In case \a schedule is false, the propagator is just subscribed but
* not scheduled for execution (this must be used when creating
* subscriptions during propagation).
*/
void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
/// Cancel subscription of propagator \a p with propagation condition \a pc to view
void cancel(Space& home, Propagator& p, PropCond pc);
/// Subscribe advisor \a a to view
void subscribe(Space& home, Advisor& a);
/// Cancel subscription of advisor \a a
void cancel(Space& home, Advisor& a);
//@}
/// \name Delta information for advisors
//@{
/// Return modification event
static ModEvent modevent(const Delta& d);
//@}
/// \name Cloning
//@{
/// Update this view to be a clone of view \a y
void update(Space& home, bool share, VarImpView<Var>& y);
//@}
};
/** \name View comparison
* \relates VarImpView
*/
//@{
/// Test whether views \a x and \a y are the same
template<class VarA, class VarB>
bool same(const VarImpView<VarA>& x, const VarImpView<VarB>& y);
/// Test whether view \a x comes before \a y (arbitrary order)
template<class ViewA, class ViewB>
bool before(const ViewA& x, const ViewB& y);
//@}
/**
* \brief Base-class for derived views
* \ingroup TaskVarView
*/
template<class View>
class DerivedView {
public:
/// The variable implementation type belonging to the \a View
typedef typename View::VarImpType VarImpType;
/// The variable type belonging to the \a View
typedef typename View::VarType VarType;
protected:
/// View from which this view is derived
View x;
/// Default constructor
DerivedView(void);
/// Initialize with view \a y
DerivedView(const View& y);
public:
/// \name Generic view information
//@{
/// Return whether this view is derived from a VarImpView
static bool varderived(void);
/// Return variable implementation of view
VarImpType* varimp(void) const;
/// Return view from which this view is derived
View base(void) const;
/// Return degree (number of subscribed propagators)
unsigned int degree(void) const;
/// Return accumulated failure count (plus degree)
double afc(void) const;
//@}
/// \name Domain tests
//@{
/// Test whether view is assigned
bool assigned(void) const;
//@}
/// \name View-dependent propagator support
//@{
/// Schedule propagator \a p with modification event \a me
static void schedule(Space& home, Propagator& p, ModEvent me);
/// Return modification event for view type in \a med
static ModEvent me(const ModEventDelta& med);
/// Translate modification event \a me to modification event delta for view
static ModEventDelta med(ModEvent);
//@}
/// \name Dependencies
//@{
/**
* \brief Subscribe propagator \a p with propagation condition \a pc to view
*
* In case \a schedule is false, the propagator is just subscribed but
* not scheduled for execution (this must be used when creating
* subscriptions during propagation).
*/
void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
/// Cancel subscription of propagator \a p with propagation condition \a pc to view
void cancel(Space& home, Propagator& p, PropCond pc);
/// Subscribe advisor \a a to view
void subscribe(Space& home, Advisor& a);
/// Cancel subscription of advisor \a a
void cancel(Space& home, Advisor& a);
//@}
/// \name Delta information for advisors
//@{
/// Return modification event
static ModEvent modevent(const Delta& d);
//@}
/// \name Cloning
//@{
/// Update this view to be a clone of view \a y
void update(Space& home, bool share, DerivedView<View>& y);
//@}
};
/**
* \brief Test whether views share same variable
* \ingroup TaskVarView
*/
template<class ViewA, class ViewB>
bool shared(const ConstView<ViewA>&, const ConstView<ViewB>&);
/**
* \brief Test whether views share same variable
* \ingroup TaskVarView
*/
template<class Var, class View>
bool shared(const VarImpView<Var>&, const ConstView<View>&);
/**
* \brief Test whether views share same variable
* \ingroup TaskVarView
*/
template<class ViewA, class ViewB>
bool shared(const DerivedView<ViewA>&, const ConstView<ViewB>&);
/**
* \brief Test whether views share same variable
* \ingroup TaskVarView
*/
template<class View, class Var>
bool shared(const ConstView<View>&, const VarImpView<Var>&);
/**
* \brief Test whether views share same variable
* \ingroup TaskVarView
*/
template<class ViewA, class ViewB>
bool shared(const ConstView<ViewA>&, const DerivedView<ViewB>&);
/**
* \brief Test whether views share same variable
* \ingroup TaskVarView
*/
template<class VarA, class VarB>
bool shared(const VarImpView<VarA>&, const VarImpView<VarB>&);
/**
* \brief Test whether views share same variable
* \ingroup TaskVarView
*/
template<class Var, class View>
bool shared(const VarImpView<Var>&, const DerivedView<View>&);
/**
* \brief Test whether views share same variable
* \ingroup TaskVarView
*/
template<class View, class Var>
bool shared(const DerivedView<View>&, const VarImpView<Var>&);
/**
* \brief Test whether views share same variable
* \ingroup TaskVarView
*/
template<class ViewA, class ViewB>
bool shared(const DerivedView<ViewA>&, const DerivedView<ViewB>&);
/*
* Constant view: has no variable implementation
*
*/
template<class View>
forceinline unsigned int
ConstView<View>::degree(void) const {
return 0;
}
template<class View>
forceinline double
ConstView<View>::afc(void) const {
return 0.0;
}
template<class View>
forceinline bool
ConstView<View>::varderived(void) {
return false;
}
template<class View>
forceinline typename View::VarImpType*
ConstView<View>::varimp(void) const {
return NULL;
}
template<class View>
forceinline bool
ConstView<View>::assigned(void) const {
return true;
}
template<class View>
forceinline void
ConstView<View>::subscribe(Space& home, Propagator& p, PropCond,
bool schedule) {
if (schedule)
View::schedule(home,p,ME_GEN_ASSIGNED);
}
template<class View>
forceinline void
ConstView<View>::cancel(Space&, Propagator&, PropCond) {
}
template<class View>
forceinline void
ConstView<View>::subscribe(Space&, Advisor&) {
}
template<class View>
forceinline void
ConstView<View>::cancel(Space&, Advisor&) {
}
template<class View>
forceinline void
ConstView<View>::schedule(Space& home, Propagator& p, ModEvent me) {
View::schedule(home,p,me);
}
template<class View>
forceinline ModEvent
ConstView<View>::me(const ModEventDelta& med) {
return View::me(med);
}
template<class View>
forceinline ModEventDelta
ConstView<View>::med(ModEvent me) {
return View::med(me);
}
template<class View>
forceinline ModEvent
ConstView<View>::modevent(const Delta& d) {
(void) d;
return ME_GEN_NONE;
}
template<class View>
forceinline void
ConstView<View>::update(Space&, bool, ConstView<View>&) {
}
/*
* Variable view: contains a pointer to a variable implementation
*
*/
template<class Var>
forceinline
VarImpView<Var>::VarImpView(void)
: x(NULL) {}
template<class Var>
forceinline
VarImpView<Var>::VarImpView(VarImpType* y)
: x(y) {}
template<class Var>
forceinline bool
VarImpView<Var>::varderived(void) {
return true;
}
template<class Var>
forceinline typename Var::VarImpType*
VarImpView<Var>::varimp(void) const {
return x;
}
template<class Var>
forceinline unsigned int
VarImpView<Var>::degree(void) const {
return x->degree();
}
template<class Var>
forceinline double
VarImpView<Var>::afc(void) const {
return x->afc();
}
template<class Var>
forceinline bool
VarImpView<Var>::assigned(void) const {
return x->assigned();
}
template<class Var>
forceinline void
VarImpView<Var>::subscribe(Space& home, Propagator& p, PropCond pc,
bool schedule) {
x->subscribe(home,p,pc,schedule);
}
template<class Var>
forceinline void
VarImpView<Var>::cancel(Space& home, Propagator& p, PropCond pc) {
x->cancel(home,p,pc);
}
template<class Var>
forceinline void
VarImpView<Var>::subscribe(Space& home, Advisor& a) {
x->subscribe(home,a);
}
template<class Var>
forceinline void
VarImpView<Var>::cancel(Space& home, Advisor& a) {
x->cancel(home,a);
}
template<class Var>
forceinline void
VarImpView<Var>::schedule(Space& home, Propagator& p, ModEvent me) {
VarImpType::schedule(home,p,me);
}
template<class Var>
forceinline ModEvent
VarImpView<Var>::me(const ModEventDelta& med) {
return VarImpType::me(med);
}
template<class Var>
forceinline ModEventDelta
VarImpView<Var>::med(ModEvent me) {
return VarImpType::med(me);
}
template<class Var>
forceinline ModEvent
VarImpView<Var>::modevent(const Delta& d) {
return VarImpType::modevent(d);
}
template<class Var>
forceinline void
VarImpView<Var>::update(Space& home, bool share, VarImpView<Var>& y) {
x = y.x->copy(home,share);
}
/*
* Derived view: contain the base view from which they are derived
*
*/
template<class View>
forceinline
DerivedView<View>::DerivedView(void) {}
template<class View>
forceinline
DerivedView<View>::DerivedView(const View& y)
: x(y) {}
template<class View>
forceinline bool
DerivedView<View>::varderived(void) {
return View::varderived();
}
template<class View>
forceinline typename View::VarImpType*
DerivedView<View>::varimp(void) const {
return x.varimp();
}
template<class View>
forceinline View
DerivedView<View>::base(void) const {
return x;
}
template<class View>
forceinline unsigned int
DerivedView<View>::degree(void) const {
return x.degree();
}
template<class View>
forceinline double
DerivedView<View>::afc(void) const {
return x.afc();
}
template<class View>
forceinline bool
DerivedView<View>::assigned(void) const {
return x.assigned();
}
template<class View>
forceinline void
DerivedView<View>::schedule(Space& home, Propagator& p, ModEvent me) {
return View::schedule(home,p,me);
}
template<class View>
forceinline ModEvent
DerivedView<View>::me(const ModEventDelta& med) {
return View::me(med);
}
template<class View>
forceinline ModEventDelta
DerivedView<View>::med(ModEvent me) {
return View::med(me);
}
template<class View>
forceinline void
DerivedView<View>::subscribe(Space& home, Propagator& p, PropCond pc,
bool schedule) {
x.subscribe(home,p,pc,schedule);
}
template<class View>
forceinline void
DerivedView<View>::cancel(Space& home, Propagator& p, PropCond pc) {
x.cancel(home,p,pc);
}
template<class View>
forceinline void
DerivedView<View>::subscribe(Space& home, Advisor& a) {
x.subscribe(home,a);
}
template<class View>
forceinline void
DerivedView<View>::cancel(Space& home, Advisor& a) {
x.cancel(home,a);
}
template<class View>
forceinline ModEvent
DerivedView<View>::modevent(const Delta& d) {
return View::modevent(d);
}
template<class View>
forceinline void
DerivedView<View>::update(Space& home, bool share, DerivedView<View>& y) {
x.update(home,share,y.x);
}
/*
* Tests whether two views are the same
*
*/
/// Test whether two views are the same
template<class ViewA, class ViewB>
forceinline bool
same(const ConstView<ViewA>&, const ConstView<ViewB>&) {
return false;
}
/// Test whether two views are the same
template<class Var, class View>
forceinline bool
same(const VarImpView<Var>&, const ConstView<View>&) {
return false;
}
/// Test whether two views are the same
template<class ViewA, class ViewB>
forceinline bool
same(const ConstView<ViewA>&, const DerivedView<ViewB>&) {
return false;
}
/// Test whether two views are the same
template<class Var, class View>
forceinline bool
same(const VarImpView<Var>&, const DerivedView<View>&) {
return false;
}
/// Test whether two views are the same
template<class View, class Var>
forceinline bool
same(const DerivedView<View>&, const VarImpView<Var>&) {
return false;
}
/// Test whether two views are the same
template<class Var>
forceinline bool
same(const VarImpView<Var>& x, const VarImpView<Var>& y) {
return x.varimp() == y.varimp();
}
/// Test whether two views are the same
template<class ViewA, class ViewB>
forceinline bool
same(const DerivedView<ViewA>& x, const DerivedView<ViewB>& y) {
return same(x.base(),y.base());
}
/*
* Tests whether one view is before the other
*
*/
template<class ViewA, class ViewB>
forceinline bool
before(const ViewA& x, const ViewB& y) {
return x.varimp() < y.varimp();
}
/*
* Testing whether two views share the same variable
*
*/
template<class ViewA, class ViewB>
forceinline bool
shared(const ConstView<ViewA>&, const ConstView<ViewB>&) {
return false;
}
template<class Var, class View>
forceinline bool
shared(const VarImpView<Var>&, const ConstView<View>&) {
return false;
}
template<class ViewA, class ViewB>
forceinline bool
shared(const DerivedView<ViewA>&, const ConstView<ViewB>&) {
return false;
}
template<class View, class Var>
forceinline bool
shared(const ConstView<View>&, const VarImpView<Var>&) {
return false;
}
template<class ViewA, class ViewB>
forceinline bool
shared(const ConstView<ViewA>&, const DerivedView<ViewB>&) {
return false;
}
template<class VarA, class VarB>
forceinline bool
shared(const VarImpView<VarA>& x, const VarImpView<VarB>& y) {
return (static_cast<VarImpBase*>(x.varimp()) ==
static_cast<VarImpBase*>(y.varimp()));
}
template<class Var, class View>
forceinline bool
shared(const VarImpView<Var>& x, const DerivedView<View>& y) {
return (View::varderived() &&
static_cast<VarImpBase*>(x.varimp()) ==
static_cast<VarImpBase*>(y.varimp()));
}
template<class View, class Var>
forceinline bool
shared(const DerivedView<View>& x, const VarImpView<Var>& y) {
return (View::varderived() &&
static_cast<VarImpBase*>(x.varimp()) ==
static_cast<VarImpBase*>(y.varimp()));
}
template<class ViewA, class ViewB>
forceinline bool
shared(const DerivedView<ViewA>& x, const DerivedView<ViewB>& y) {
return (ViewA::varderived() && ViewB::varderived() &&
static_cast<VarImpBase*>(x.varimp()) ==
static_cast<VarImpBase*>(y.varimp()));
}
}
// STATISTICS: kernel-var
|