this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Contributing authors:
7 * Samuel Gagnon <samuel.gagnon92@gmail.com>
8 *
9 * Copyright:
10 * Christian Schulte, 2005
11 * Samuel Gagnon, 2018
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.org
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37
38#include <iostream>
39
40namespace Gecode { namespace Int {
41
42 /**
43 * \brief Range iterator for integer views
44 *
45 * This class provides (by specialization) a range iterator
46 * for all integer views.
47 *
48 * Note that this template class serves only as a specification
49 * of the interface of the various specializations.
50 *
51 * \ingroup TaskActorInt
52 */
53 template<class View>
54 class ViewRanges {
55 public:
56 /// \name Constructors and initialization
57 //@{
58 /// Default constructor
59 ViewRanges(void);
60 /// Initialize with ranges for view \a x
61 ViewRanges(const View& x);
62 /// Initialize with ranges for view \a x
63 void init(const View& x);
64 //@}
65
66 /// \name Iteration control
67 //@{
68 /// Test whether iterator is still at a range or done
69 bool operator ()(void) const;
70 /// Move iterator to next range (if possible)
71 void operator ++(void);
72 //@}
73
74 /// \name Range access
75 //@{
76 /// Return smallest value of range
77 int min(void) const;
78 /// Return largest value of range
79 int max(void) const;
80 /// Return width of range (distance between minimum and maximum)
81 unsigned int width(void) const;
82 //@}
83 };
84
85 /**
86 * \brief Value iterator for integer views
87 *
88 * This class provides a value iterator for all
89 * integer views.
90 *
91 * \ingroup TaskActorInt
92 */
93 template<class View>
94 class ViewValues : public Iter::Ranges::ToValues<ViewRanges<View> > {
95 public:
96 /// \name Constructors and initialization
97 //@{
98 /// Default constructor
99 ViewValues(void);
100 /// Initialize with values for \a x
101 ViewValues(const View& x);
102 /// Initialize with values \a x
103 void init(const View& x);
104 //@}
105 };
106
107}}
108
109#include <gecode/int/view/iter.hpp>
110
111namespace Gecode { namespace Int {
112
113 /**
114 * \defgroup TaskActorIntView Integer views
115 *
116 * Integer propagators and branchers compute with integer views.
117 * Integer views provide views on integer variable implementations,
118 * integer constants, and also allow to scale, translate, and negate
119 * variables. Additionally, a special Boolean view is provided that
120 * offers convenient and efficient operations for Boolean (0/1)
121 * views.
122 * \ingroup TaskActorInt
123 */
124
125 /**
126 * \brief Integer view for integer variables
127 * \ingroup TaskActorIntView
128 */
129 class IntView : public VarImpView<IntVar> {
130 protected:
131 using VarImpView<IntVar>::x;
132 public:
133 /// \name Constructors and initialization
134 //@{
135 /// Default constructor
136 IntView(void);
137 /// Initialize from integer variable \a y
138 IntView(const IntVar& y);
139 /// Initialize from integer variable \a y
140 IntView(IntVarImp* y);
141 //@}
142
143 /// \name Value access
144 //@{
145 /// Return minimum of domain
146 int min(void) const;
147 /// Return maximum of domain
148 int max(void) const;
149 /// Return median of domain (greatest element not greater than the median)
150 int med(void) const;
151 /// Return assigned value (only if assigned)
152 int val(void) const;
153#ifdef GECODE_HAS_CBS
154 /// Return reverse transformation of value according to view
155 int baseval(int val) const;
156#endif
157
158 /// Return size (cardinality) of domain
159 unsigned int size(void) const;
160 /// Return width of domain (distance between maximum and minimum)
161 unsigned int width(void) const;
162 /// Return regret of domain minimum (distance to next larger value)
163 unsigned int regret_min(void) const;
164 /// Return regret of domain maximum (distance to next smaller value)
165 unsigned int regret_max(void) const;
166 //@}
167
168 /// \name Domain tests
169 //@{
170 /// Test whether domain is a range
171 bool range(void) const;
172
173 /// Test whether \a n is contained in domain
174 bool in(int n) const;
175 /// Test whether \a n is contained in domain
176 bool in(long long int n) const;
177 //@}
178
179 /// \name Domain update by value
180 //@{
181 /// Restrict domain values to be less or equal than \a n
182 ModEvent lq(Space& home, int n);
183 /// Restrict domain values to be less or equal than \a n
184 ModEvent lq(Space& home, long long int n);
185
186 /// Restrict domain values to be less than \a n
187 ModEvent le(Space& home, int n);
188 /// Restrict domain values to be less than \a n
189 ModEvent le(Space& home, long long int n);
190
191 /// Restrict domain values to be greater or equal than \a n
192 ModEvent gq(Space& home, int n);
193 /// Restrict domain values to be greater or equal than \a n
194 ModEvent gq(Space& home, long long int n);
195
196 /// Restrict domain values to be greater than \a n
197 ModEvent gr(Space& home, int n);
198 /// Restrict domain values to be greater than \a n
199 ModEvent gr(Space& home, long long int n);
200
201 /// Restrict domain values to be different from \a n
202 ModEvent nq(Space& home, int n);
203 /// Restrict domain values to be different from \a n
204 ModEvent nq(Space& home, long long int n);
205
206 /// Restrict domain values to be equal to \a n
207 ModEvent eq(Space& home, int n);
208 /// Restrict domain values to be equal to \a n
209 ModEvent eq(Space& home, long long int n);
210 //@}
211
212 /**
213 * \name Domain update by iterator
214 *
215 * Views can be both updated by range and value iterators.
216 * Value iterators do not need to be strict in that the same value
217 * is allowed to occur more than once in the iterated sequence.
218 *
219 * The argument \a depends must be true, if the iterator
220 * passed as argument depends on the view on which the operation
221 * is invoked. In this case, the view is only updated after the
222 * iterator has been consumed. Otherwise, the domain might be updated
223 * concurrently while following the iterator.
224 *
225 */
226 //@{
227 /// Replace domain by ranges described by \a i
228 template<class I>
229 ModEvent narrow_r(Space& home, I& i, bool depends=true);
230 /// Intersect domain with ranges described by \a i
231 template<class I>
232 ModEvent inter_r(Space& home, I& i, bool depends=true);
233 /// Remove from domain the ranges described by \a i
234 template<class I>
235 ModEvent minus_r(Space& home, I& i, bool depends=true);
236 /// Replace domain by values described by \a i
237 template<class I>
238 ModEvent narrow_v(Space& home, I& i, bool depends=true);
239 /// Intersect domain with values described by \a i
240 template<class I>
241 ModEvent inter_v(Space& home, I& i, bool depends=true);
242 /// Remove from domain the values described by \a i
243 template<class I>
244 ModEvent minus_v(Space& home, I& i, bool depends=true);
245 //@}
246
247 /// \name Delta information for advisors
248 //@{
249 /// Return minimum value just pruned
250 int min(const Delta& d) const;
251 /// Return maximum value just pruned
252 int max(const Delta& d) const;
253 /// Return width of values just pruned
254 unsigned int width(const Delta& d) const;
255 /// Test whether arbitrary values got pruned
256 bool any(const Delta& d) const;
257 //@}
258
259 /// \name View-dependent propagator support
260 //@{
261 /// Translate modification event \a me to modification event delta for view
262 static ModEventDelta med(ModEvent me);
263 //@}
264 };
265
266 /**
267 * \brief Print integer variable view
268 * \relates Gecode::Int::IntView
269 */
270 template<class Char, class Traits>
271 std::basic_ostream<Char,Traits>&
272 operator <<(std::basic_ostream<Char,Traits>& os, const IntView& x);
273
274
275 /**
276 * \brief Minus integer view
277 *
278 * A minus integer view \f$m\f$ for an integer view \f$x\f$ provides
279 * operations such that \f$m\f$ behaves as \f$-x\f$.
280 * \ingroup TaskActorIntView
281 */
282 class MinusView : public DerivedView<IntView> {
283 protected:
284 using DerivedView<IntView>::x;
285 public:
286 /// \name Constructors and initialization
287 //@{
288 /// Default constructor
289 MinusView(void);
290 /// Initialize with integer view \a y
291 explicit MinusView(const IntView& y);
292 //@}
293
294 /// \name Value access
295 //@{
296 /// Return minimum of domain
297 int min(void) const;
298 /// Return maximum of domain
299 int max(void) const;
300 /// Return median of domain
301 int med(void) const;
302 /// Return assigned value (only if assigned)
303 int val(void) const;
304#ifdef GECODE_HAS_CBS
305 /// Return reverse transformation of value according to view
306 int baseval(int val) const;
307#endif
308
309 /// Return size (cardinality) of domain
310 unsigned int size(void) const;
311 /// Return width of domain (distance between maximum and minimum)
312 unsigned int width(void) const;
313 /// Return regret of domain minimum (distance to next larger value)
314 unsigned int regret_min(void) const;
315 /// Return regret of domain maximum (distance to next smaller value)
316 unsigned int regret_max(void) const;
317 //@}
318
319 /// \name Domain tests
320 //@{
321 /// Test whether domain is a range
322 bool range(void) const;
323
324 /// Test whether \a n is contained in domain
325 bool in(int n) const;
326 /// Test whether \a n is contained in domain
327 bool in(long long int n) const;
328 //@}
329
330 /// \name Domain update by value
331 //@{
332 /// Restrict domain values to be less or equal than \a n
333 ModEvent lq(Space& home, int n);
334 /// Restrict domain values to be less or equal than \a n
335 ModEvent lq(Space& home, long long int n);
336
337 /// Restrict domain values to be less than \a n
338 ModEvent le(Space& home, int n);
339 /// Restrict domain values to be less than \a n
340 ModEvent le(Space& home, long long int n);
341
342 /// Restrict domain values to be greater or equal than \a n
343 ModEvent gq(Space& home, int n);
344 /// Restrict domain values to be greater or equal than \a n
345 ModEvent gq(Space& home, long long int n);
346
347 /// Restrict domain values to be greater than \a n
348 ModEvent gr(Space& home, int n);
349 /// Restrict domain values to be greater than \a n
350 ModEvent gr(Space& home, long long int n);
351
352 /// Restrict domain values to be different from \a n
353 ModEvent nq(Space& home, int n);
354 /// Restrict domain values to be different from \a n
355 ModEvent nq(Space& home, long long int n);
356
357 /// Restrict domain values to be equal to \a n
358 ModEvent eq(Space& home, int n);
359 /// Restrict domain values to be equal to \a n
360 ModEvent eq(Space& home, long long int n);
361 //@}
362
363 /**
364 * \name Domain update by iterator
365 *
366 * Views can be both updated by range and value iterators.
367 * Value iterators do not need to be strict in that the same value
368 * is allowed to occur more than once in the iterated sequence.
369 *
370 * The argument \a depends must be true, if the iterator
371 * passed as argument depends on the view on which the operation
372 * is invoked. In this case, the view is only updated after the
373 * iterator has been consumed. Otherwise, the domain might be updated
374 * concurrently while following the iterator.
375 *
376 */
377 //@{
378 /// Replace domain by ranges described by \a i
379 template<class I>
380 ModEvent narrow_r(Space& home, I& i, bool depends=true);
381 /// Intersect domain with ranges described by \a i
382 template<class I>
383 ModEvent inter_r(Space& home, I& i, bool depends=true);
384 /// Remove from domain the ranges described by \a i
385 template<class I>
386 ModEvent minus_r(Space& home, I& i, bool depends=true);
387 /// Replace domain by values described by \a i
388 template<class I>
389 ModEvent narrow_v(Space& home, I& i, bool depends=true);
390 /// Intersect domain with values described by \a i
391 template<class I>
392 ModEvent inter_v(Space& home, I& i, bool depends=true);
393 /// Remove from domain the values described by \a i
394 template<class I>
395 ModEvent minus_v(Space& home, I& i, bool depends=true);
396 //@}
397
398 /// \name View-dependent propagator support
399 //@{
400 /// Translate modification event \a me to modification event delta for view
401 static ModEventDelta med(ModEvent me);
402 //@}
403
404 /// \name Delta information for advisors
405 //@{
406 /// Return minimum value just pruned
407 int min(const Delta& d) const;
408 /// Return maximum value just pruned
409 int max(const Delta& d) const;
410 /// Return width of values just pruned
411 unsigned int width(const Delta& d) const;
412 /// Test whether arbitrary values got pruned
413 bool any(const Delta& d) const;
414 //@}
415 };
416
417 /**
418 * \brief Print integer minus view
419 * \relates Gecode::Int::MinusView
420 */
421 template<class Char, class Traits>
422 std::basic_ostream<Char,Traits>&
423 operator <<(std::basic_ostream<Char,Traits>& os, const MinusView& x);
424
425 /** \name View comparison
426 * \relates Gecode::Int::MinusView
427 */
428 //@{
429 /// Test whether views \a x and \a y are the same
430 bool operator ==(const MinusView& x, const MinusView& y);
431 /// Test whether views \a x and \a y are not the same
432 bool operator !=(const MinusView& x, const MinusView& y);
433 //@}
434
435 /**
436 * \brief Offset integer view
437 *
438 * An offset integer view \f$o\f$ for an integer view \f$x\f$ and
439 * an integer \f$c\f$ provides operations such that \f$o\f$
440 * behaves as \f$x+c\f$.
441 * \ingroup TaskActorIntView
442 */
443 class OffsetView : public DerivedView<IntView> {
444 protected:
445 /// Offset
446 int c;
447 using DerivedView<IntView>::x;
448 public:
449 /// \name Constructors and initialization
450 //@{
451 /// Default constructor
452 OffsetView(void);
453 /// Initialize with integer view \a y and offset \a c
454 OffsetView(const IntView& y, int c);
455 //@}
456
457 /// \name Value access
458 //@{
459 /// Return offset
460 int offset(void) const;
461 /// Change offset to \a n
462 void offset(int n);
463 /// Return minimum of domain
464 int min(void) const;
465 /// Return maximum of domain
466 int max(void) const;
467 /// Return median of domain (greatest element not greater than the median)
468 int med(void) const;
469 /// Return assigned value (only if assigned)
470 int val(void) const;
471#ifdef GECODE_HAS_CBS
472 /// Return reverse transformation of value according to view
473 int baseval(int val) const;
474#endif
475
476 /// Return size (cardinality) of domain
477 unsigned int size(void) const;
478 /// Return width of domain (distance between maximum and minimum)
479 unsigned int width(void) const;
480 /// Return regret of domain minimum (distance to next larger value)
481 unsigned int regret_min(void) const;
482 /// Return regret of domain maximum (distance to next smaller value)
483 unsigned int regret_max(void) const;
484 //@}
485
486 /// \name Domain tests
487 //@{
488 /// Test whether domain is a range
489 bool range(void) const;
490
491 /// Test whether \a n is contained in domain
492 bool in(int n) const;
493 /// Test whether \a n is contained in domain
494 bool in(long long int n) const;
495 //@}
496
497 /// \name Domain update by value
498 //@{
499 /// Restrict domain values to be less or equal than \a n
500 ModEvent lq(Space& home, int n);
501 /// Restrict domain values to be less or equal than \a n
502 ModEvent lq(Space& home, long long int n);
503
504 /// Restrict domain values to be less than \a n
505 ModEvent le(Space& home, int n);
506 /// Restrict domain values to be less than \a n
507 ModEvent le(Space& home, long long int n);
508
509 /// Restrict domain values to be greater or equal than \a n
510 ModEvent gq(Space& home, int n);
511 /// Restrict domain values to be greater or equal than \a n
512 ModEvent gq(Space& home, long long int n);
513
514 /// Restrict domain values to be greater than \a n
515 ModEvent gr(Space& home, int n);
516 /// Restrict domain values to be greater than \a n
517 ModEvent gr(Space& home, long long int n);
518
519 /// Restrict domain values to be different from \a n
520 ModEvent nq(Space& home, int n);
521 /// Restrict domain values to be different from \a n
522 ModEvent nq(Space& home, long long int n);
523
524 /// Restrict domain values to be equal to \a n
525 ModEvent eq(Space& home, int n);
526 /// Restrict domain values to be equal to \a n
527 ModEvent eq(Space& home, long long int n);
528 //@}
529
530 /**
531 * \name Domain update by iterator
532 *
533 * Views can be both updated by range and value iterators.
534 * Value iterators do not need to be strict in that the same value
535 * is allowed to occur more than once in the iterated sequence.
536 *
537 * The argument \a depends must be true, if the iterator
538 * passed as argument depends on the view on which the operation
539 * is invoked. In this case, the view is only updated after the
540 * iterator has been consumed. Otherwise, the domain might be updated
541 * concurrently while following the iterator.
542 *
543 */
544 //@{
545 /// Replace domain by ranges described by \a i
546 template<class I>
547 ModEvent narrow_r(Space& home, I& i, bool depends=true);
548 /// Intersect domain with ranges described by \a i
549 template<class I>
550 ModEvent inter_r(Space& home, I& i, bool depends=true);
551 /// Remove from domain the ranges described by \a i
552 template<class I>
553 ModEvent minus_r(Space& home, I& i, bool depends=true);
554 /// Replace domain by values described by \a i
555 template<class I>
556 ModEvent narrow_v(Space& home, I& i, bool depends=true);
557 /// Intersect domain with values described by \a i
558 template<class I>
559 ModEvent inter_v(Space& home, I& i, bool depends=true);
560 /// Remove from domain the values described by \a i
561 template<class I>
562 ModEvent minus_v(Space& home, I& i, bool depends=true);
563 //@}
564
565 /// \name View-dependent propagator support
566 //@{
567 /// Translate modification event \a me to modification event delta for view
568 static ModEventDelta med(ModEvent me);
569 //@}
570
571 /// \name Delta information for advisors
572 //@{
573 /// Return minimum value just pruned
574 int min(const Delta& d) const;
575 /// Return maximum value just pruned
576 int max(const Delta& d) const;
577 /// Return width of values just pruned
578 unsigned int width(const Delta& d) const;
579 /// Test whether arbitrary values got pruned
580 bool any(const Delta& d) const;
581 //@}
582
583 /// \name Cloning
584 //@{
585 /// Update this view to be a clone of view \a y
586 void update(Space& home, OffsetView& y);
587 //@}
588
589 /// \name Ordering
590 //@{
591 /// Whether this view comes before view \a y (arbitray order)
592 bool operator <(const OffsetView& y) const;
593 //@}
594 };
595
596 /**
597 * \brief Print integer offset view
598 * \relates Gecode::Int::OffsetView
599 */
600 template<class Char, class Traits>
601 std::basic_ostream<Char,Traits>&
602 operator <<(std::basic_ostream<Char,Traits>& os, const OffsetView& x);
603
604 /** \name View comparison
605 * \relates Gecode::Int::OffsetView
606 */
607 //@{
608 /// Test whether views \a x and \a y are the same
609 bool operator ==(const OffsetView& x, const OffsetView& y);
610 /// Test whether views \a x and \a y are not the same
611 bool operator !=(const OffsetView& x, const OffsetView& y);
612 //@}
613
614 /**
615 * \brief Converter without offsets
616 */
617 template<class View>
618 class NoOffset {
619 public:
620 /// The view type
621 typedef View ViewType;
622 /// Pass through \a x
623 View& operator ()(View& x);
624 /// Update during cloning
625 void update(const NoOffset&);
626 /// Access offset
627 int offset(void) const;
628 };
629
630 template<class View>
631 forceinline View&
632 NoOffset<View>::operator ()(View& x) {
633 return x;
634 }
635
636 template<class View>
637 forceinline void
638 NoOffset<View>::update(const NoOffset&) {}
639
640 template<class View>
641 forceinline int
642 NoOffset<View>::offset(void) const {
643 return 0;
644 }
645
646
647 /**
648 * \brief Converter with fixed offset
649 */
650 class Offset {
651 public:
652 /// The view type
653 typedef OffsetView ViewType;
654 /// The offset
655 int c;
656 /// Constructor with offset \a off
657 Offset(int off = 0);
658 /// Return OffsetRefView for \a x
659 OffsetView operator()(IntView& x);
660 /// Update during cloning
661 void update(const Offset& o);
662 /// Access offset
663 int offset(void) const;
664 };
665
666 forceinline
667 Offset::Offset(int off) : c(off) {}
668
669 forceinline void
670 Offset::update(const Offset& o) { c = o.c; }
671
672 forceinline int
673 Offset::offset(void) const { return c; }
674
675 forceinline OffsetView
676 Offset::operator ()(IntView& x) {
677 return OffsetView(x,c);
678 }
679
680 /**
681 * \brief Scale integer view (template)
682 *
683 * A scale integer view \f$s\f$ for an integer view \f$x\f$ and
684 * a non-negative integer \f$a\f$ provides operations such that \f$s\f$
685 * behaves as \f$a\cdot x\f$.
686 *
687 * The precision of a scale integer view is defined by the value types
688 * \a Val and \a UnsVal. \a Val can be either \c int or \c long \c long
689 * \c int where \a UnsVal must be the unsigned variant of \a Val. The
690 * range which is allowed for the two types is defined by the values in
691 * Gecode::Limits.
692 *
693 * Note that scale integer views currently do not provide operations
694 * for updating domains by range iterators.
695 *
696 * The template is not to be used directly (as it is very clumsy). Use
697 * the following instead:
698 * - IntScaleView for scale views with integer precision
699 * - LLongScaleView for scale views with long long precision
700 *
701 * \ingroup TaskActorIntView
702 */
703 template<class Val, class UnsVal>
704 class ScaleView : public DerivedView<IntView> {
705 protected:
706 using DerivedView<IntView>::x;
707 /// Scale factor
708 int a;
709 public:
710 /// \name Constructors and initialization
711 //@{
712 /// Default constructor
713 ScaleView(void);
714 /// Initialize as \f$b\cdot y\f$
715 ScaleView(int b, const IntView& y);
716 //@}
717
718 /// \name Value access
719 //@{
720 /// Return scale factor of scale view
721 int scale(void) const;
722 /// Return minimum of domain
723 Val min(void) const;
724 /// Return maximum of domain
725 Val max(void) const;
726 /// Return median of domain (greatest element not greater than the median)
727 Val med(void) const;
728 /// Return assigned value (only if assigned)
729 Val val(void) const;
730#ifdef GECODE_HAS_CBS
731 /// Return reverse transformation of value according to view
732 Val baseval(Val val) const;
733#endif
734
735 /// Return size (cardinality) of domain
736 UnsVal size(void) const;
737 /// Return width of domain (distance between maximum and minimum)
738 UnsVal width(void) const;
739 /// Return regret of domain minimum (distance to next larger value)
740 UnsVal regret_min(void) const;
741 /// Return regret of domain maximum (distance to next smaller value)
742 UnsVal regret_max(void) const;
743 //@}
744
745 /// \name Domain tests
746 //@{
747 /// Test whether domain is a range
748 bool range(void) const;
749 /// Test whether \a n is contained in domain
750 bool in(Val n) const;
751 //@}
752
753 /// \name Domain update by value
754 //@{
755 /// Restrict domain values to be less or equal than \a n
756 ModEvent lq(Space& home, Val n);
757 /// Restrict domain values to be less than \a n
758 ModEvent le(Space& home, Val n);
759 /// Restrict domain values to be greater or equal than \a n
760 ModEvent gq(Space& home, Val n);
761 /// Restrict domain values to be greater than \a n
762 ModEvent gr(Space& home, Val n);
763 /// Restrict domain values to be different from \a n
764 ModEvent nq(Space& home, Val n);
765 /// Restrict domain values to be equal to \a n
766 ModEvent eq(Space& home, Val n);
767 //@}
768
769 /// \name View-dependent propagator support
770 //@{
771 /// Translate modification event \a me to modification event delta for view
772 static ModEventDelta med(ModEvent me);
773 //@}
774
775 /// \name Delta information for advisors
776 //@{
777 /// Return minimum value just pruned
778 Val min(const Delta& d) const;
779 /// Return maximum value just pruned
780 Val max(const Delta& d) const;
781 /// Return width of values just pruned
782 UnsVal width(const Delta& d) const;
783 /// Test whether arbitrary values got pruned
784 bool any(const Delta& d) const;
785 //@}
786
787 /// \name Cloning
788 //@{
789 /// Update this view to be a clone of view \a y
790 void update(Space& home, ScaleView<Val,UnsVal>& y);
791 //@}
792
793 /// \name Ordering
794 //@{
795 /// Whether this view comes before view \a y (arbitray order)
796 bool operator <(const ScaleView<Val,UnsVal>& y) const;
797 //@}
798 };
799
800 /**
801 * \brief Integer-precision integer scale view
802 * \ingroup TaskActorIntView
803 */
804 typedef ScaleView<int,unsigned int> IntScaleView;
805
806 /**
807 * \brief Long long-precision integer scale view
808 * \ingroup TaskActorIntView
809 */
810 typedef ScaleView<long long int,unsigned long long int> LLongScaleView;
811
812 /**
813 * \brief Print integer-precision integer scale view
814 * \relates Gecode::Int::ScaleView
815 */
816 template<class Char, class Traits>
817 std::basic_ostream<Char,Traits>&
818 operator <<(std::basic_ostream<Char,Traits>& os, const IntScaleView& x);
819
820 /**
821 * \brief Print long long-precision integer scale view
822 * \relates Gecode::Int::ScaleView
823 */
824 template<class Char, class Traits>
825 std::basic_ostream<Char,Traits>&
826 operator <<(std::basic_ostream<Char,Traits>& os, const LLongScaleView& x);
827
828 /** \name View comparison
829 * \relates Gecode::Int::ScaleView
830 */
831 //@{
832 /// Test whether views \a x and \a y are the same
833 template<class Val, class UnsVal>
834 bool operator ==(const ScaleView<Val,UnsVal>& x,
835 const ScaleView<Val,UnsVal>& y);
836 /// Test whether views \a x and \a y are not the same
837 template<class Val, class UnsVal>
838 bool operator !=(const ScaleView<Val,UnsVal>& x,
839 const ScaleView<Val,UnsVal>& y);
840 //@}
841
842
843
844 /**
845 * \brief Constant integer view
846 *
847 * A constant integer view \f$x\f$ for an integer \f$c\f$ provides
848 * operations such that \f$x\f$ behaves as a view assigned to \f$c\f$.
849 * \ingroup TaskActorIntView
850 */
851 class ConstIntView : public ConstView<IntView> {
852 protected:
853 int x;
854 public:
855 /// \name Constructors and initialization
856 //@{
857 /// Default constructor
858 ConstIntView(void);
859 /// Initialize with integer value \a n
860 ConstIntView(int n);
861 //@}
862
863 /// \name Value access
864 //@{
865 /// Return minimum of domain
866 int min(void) const;
867 /// Return maximum of domain
868 int max(void) const;
869 /// Return median of domain (greatest element not greater than the median)
870 int med(void) const;
871 /// Return assigned value (only if assigned)
872 int val(void) const;
873
874 /// Return size (cardinality) of domain
875 unsigned int size(void) const;
876 /// Return width of domain (distance between maximum and minimum)
877 unsigned int width(void) const;
878 /// Return regret of domain minimum (distance to next larger value)
879 unsigned int regret_min(void) const;
880 /// Return regret of domain maximum (distance to next smaller value)
881 unsigned int regret_max(void) const;
882 //@}
883
884 /// \name Domain tests
885 //@{
886 /// Test whether domain is a range
887 bool range(void) const;
888 /// Test whether \a n is contained in domain
889 bool in(int n) const;
890 /// Test whether \a n is contained in domain
891 bool in(long long int n) const;
892 //@}
893
894 /// \name Domain update by value
895 //@{
896 /// Restrict domain values to be less or equal than \a n
897 ModEvent lq(Space& home, int n);
898 /// Restrict domain values to be less or equal than \a n
899 ModEvent lq(Space& home, long long int n);
900
901 /// Restrict domain values to be less than \a n
902 ModEvent le(Space& home, int n);
903 /// Restrict domain values to be less than \a n
904 ModEvent le(Space& home, long long int n);
905
906 /// Restrict domain values to be greater or equal than \a n
907 ModEvent gq(Space& home, int n);
908 /// Restrict domain values to be greater or equal than \a n
909 ModEvent gq(Space& home, long long int n);
910
911 /// Restrict domain values to be greater than \a n
912 ModEvent gr(Space& home, int n);
913 /// Restrict domain values to be greater than \a n
914 ModEvent gr(Space& home, long long int n);
915
916 /// Restrict domain values to be different from \a n
917 ModEvent nq(Space& home, int n);
918 /// Restrict domain values to be different from \a n
919 ModEvent nq(Space& home, long long int n);
920
921 /// Restrict domain values to be equal to \a n
922 ModEvent eq(Space& home, int n);
923 /// Restrict domain values to be equal to \a n
924 ModEvent eq(Space& home, long long int n);
925 //@}
926
927 /**
928 * \name Domain update by iterator
929 *
930 * Views can be both updated by range and value iterators.
931 * Value iterators do not need to be strict in that the same value
932 * is allowed to occur more than once in the iterated sequence.
933 *
934 * The argument \a depends must be true, if the iterator
935 * passed as argument depends on the view on which the operation
936 * is invoked. In this case, the view is only updated after the
937 * iterator has been consumed. Otherwise, the domain might be updated
938 * concurrently while following the iterator.
939 *
940 */
941 //@{
942 /// Replace domain by ranges described by \a i
943 template<class I>
944 ModEvent narrow_r(Space& home, I& i, bool depends=true);
945 /// Intersect domain with ranges described by \a i
946 template<class I>
947 ModEvent inter_r(Space& home, I& i, bool depends=true);
948 /// Remove from domain the ranges described by \a i
949 template<class I>
950 ModEvent minus_r(Space& home, I& i, bool depends=true);
951 /// Replace domain by values described by \a i
952 template<class I>
953 ModEvent narrow_v(Space& home, I& i, bool depends=true);
954 /// Intersect domain with values described by \a i
955 template<class I>
956 ModEvent inter_v(Space& home, I& i, bool depends=true);
957 /// Remove from domain the values described by \a i
958 template<class I>
959 ModEvent minus_v(Space& home, I& i, bool depends=true);
960 //@}
961
962 /// \name Delta information for advisors
963 //@{
964 /// Return minimum value just pruned
965 int min(const Delta& d) const;
966 /// Return maximum value just pruned
967 int max(const Delta& d) const;
968 /// Return width of values just pruned
969 unsigned int width(const Delta& d) const;
970 /// Test whether arbitrary values got pruned
971 bool any(const Delta& d) const;
972 //@}
973
974 /// \name Cloning
975 //@{
976 /// Update this view to be a clone of view \a y
977 void update(Space& home, ConstIntView& y);
978 //@}
979
980 /// \name Ordering
981 //@{
982 /// Whether this view comes before view \a y (arbitray order)
983 bool operator <(const ConstIntView& y) const;
984 //@}
985 };
986
987 /**
988 * \brief Print integer constant integer view
989 * \relates Gecode::Int::ConstIntView
990 */
991 template<class Char, class Traits>
992 std::basic_ostream<Char,Traits>&
993 operator <<(std::basic_ostream<Char,Traits>& os, const ConstIntView& x);
994
995 /**
996 * \name View comparison
997 * \relates Gecode::Int::ConstIntView
998 */
999 //@{
1000 /// Test whether views \a x and \a y are the same
1001 bool operator ==(const ConstIntView& x, const ConstIntView& y);
1002 /// Test whether views \a x and \a y are not the same
1003 bool operator !=(const ConstIntView& x, const ConstIntView& y);
1004 //@}
1005
1006
1007 /**
1008 * \brief Zero integer view
1009 *
1010 * A zero integer view \f$x\f$ for provides
1011 * operations such that \f$x\f$ behaves as a view assigned to \f$0\f$.
1012 * \ingroup TaskActorIntView
1013 */
1014 class ZeroIntView : public ConstView<IntView> {
1015 public:
1016 /// \name Constructors and initialization
1017 //@{
1018 /// Default constructor
1019 ZeroIntView(void);
1020 //@}
1021
1022 /// \name Value access
1023 //@{
1024 /// Return minimum of domain
1025 int min(void) const;
1026 /// Return maximum of domain
1027 int max(void) const;
1028 /// Return median of domain (greatest element not greater than the median)
1029 int med(void) const;
1030 /// Return assigned value (only if assigned)
1031 int val(void) const;
1032
1033 /// Return size (cardinality) of domain
1034 unsigned int size(void) const;
1035 /// Return width of domain (distance between maximum and minimum)
1036 unsigned int width(void) const;
1037 /// Return regret of domain minimum (distance to next larger value)
1038 unsigned int regret_min(void) const;
1039 /// Return regret of domain maximum (distance to next smaller value)
1040 unsigned int regret_max(void) const;
1041 //@}
1042
1043 /// \name Domain tests
1044 //@{
1045 /// Test whether domain is a range
1046 bool range(void) const;
1047 /// Test whether \a n is contained in domain
1048 bool in(int n) const;
1049 /// Test whether \a n is contained in domain
1050 bool in(long long int n) const;
1051 //@}
1052
1053 /// \name Domain update by value
1054 //@{
1055 /// Restrict domain values to be less or equal than \a n
1056 ModEvent lq(Space& home, int n);
1057 /// Restrict domain values to be less or equal than \a n
1058 ModEvent lq(Space& home, long long int n);
1059
1060 /// Restrict domain values to be less than \a n
1061 ModEvent le(Space& home, int n);
1062 /// Restrict domain values to be less than \a n
1063 ModEvent le(Space& home, long long int n);
1064
1065 /// Restrict domain values to be greater or equal than \a n
1066 ModEvent gq(Space& home, int n);
1067 /// Restrict domain values to be greater or equal than \a n
1068 ModEvent gq(Space& home, long long int n);
1069
1070 /// Restrict domain values to be greater than \a n
1071 ModEvent gr(Space& home, int n);
1072 /// Restrict domain values to be greater than \a n
1073 ModEvent gr(Space& home, long long int n);
1074
1075 /// Restrict domain values to be different from \a n
1076 ModEvent nq(Space& home, int n);
1077 /// Restrict domain values to be different from \a n
1078 ModEvent nq(Space& home, long long int n);
1079
1080 /// Restrict domain values to be equal to \a n
1081 ModEvent eq(Space& home, int n);
1082 /// Restrict domain values to be equal to \a n
1083 ModEvent eq(Space& home, long long int n);
1084 //@}
1085
1086 /**
1087 * \name Domain update by iterator
1088 *
1089 * Views can be both updated by range and value iterators.
1090 * Value iterators do not need to be strict in that the same value
1091 * is allowed to occur more than once in the iterated sequence.
1092 *
1093 * The argument \a depends must be true, if the iterator
1094 * passed as argument depends on the view on which the operation
1095 * is invoked. In this case, the view is only updated after the
1096 * iterator has been consumed. Otherwise, the domain might be updated
1097 * concurrently while following the iterator.
1098 *
1099 */
1100 //@{
1101 /// Replace domain by ranges described by \a i
1102 template<class I>
1103 ModEvent narrow_r(Space& home, I& i, bool depends=true);
1104 /// Intersect domain with ranges described by \a i
1105 template<class I>
1106 ModEvent inter_r(Space& home, I& i, bool depends=true);
1107 /// Remove from domain the ranges described by \a i
1108 template<class I>
1109 ModEvent minus_r(Space& home, I& i, bool depends=true);
1110 /// Replace domain by values described by \a i
1111 template<class I>
1112 ModEvent narrow_v(Space& home, I& i, bool depends=true);
1113 /// Intersect domain with values described by \a i
1114 template<class I>
1115 ModEvent inter_v(Space& home, I& i, bool depends=true);
1116 /// Remove from domain the values described by \a i
1117 template<class I>
1118 ModEvent minus_v(Space& home, I& i, bool depends=true);
1119 //@}
1120
1121 /// \name Delta information for advisors
1122 //@{
1123 /// Return minimum value just pruned
1124 int min(const Delta& d) const;
1125 /// Return maximum value just pruned
1126 int max(const Delta& d) const;
1127 /// Return width of values just pruned
1128 unsigned int width(const Delta& d) const;
1129 /// Test whether arbitrary values got pruned
1130 bool any(const Delta& d) const;
1131 //@}
1132 };
1133
1134 /**
1135 * \brief Print integer zero view
1136 * \relates Gecode::Int::ZeroView
1137 */
1138 template<class Char, class Traits>
1139 std::basic_ostream<Char,Traits>&
1140 operator <<(std::basic_ostream<Char,Traits>& os, const ZeroIntView& x);
1141
1142 /**
1143 * \name View comparison
1144 * \relates Gecode::Int::ZeroIntView
1145 */
1146 //@{
1147 /// Test whether views \a x and \a y are the same
1148 bool operator ==(const ZeroIntView& x, const ZeroIntView& y);
1149 /// Test whether views \a x and \a y are the same
1150 bool operator !=(const ZeroIntView& x, const ZeroIntView& y);
1151 //@}
1152
1153 template<class View> class ViewDiffRanges;
1154
1155 /**
1156 * \brief Cached integer view
1157 *
1158 * A cached integer view \f$c\f$ for an integer view \f$x\f$ adds operations
1159 * for cacheing the current domain of \f$x\f$ and comparing the current
1160 * domain to the cached domain. Cached views make it easy to implement
1161 * incremental propagation algorithms.
1162 *
1163 * \ingroup TaskActorIntView
1164 */
1165 template<class View>
1166 class CachedView : public DerivedView<View> {
1167 friend class ViewDiffRanges<View>;
1168 protected:
1169 using DerivedView<View>::x;
1170 /// First cached range
1171 RangeList* _firstRange;
1172 /// Last cached range
1173 RangeList* _lastRange;
1174 /// Size of cached domain
1175 unsigned int _size;
1176 public:
1177 /// \name Constructors and initialization
1178 //@{
1179 /// Default constructor
1180 CachedView(void);
1181 /// Initialize with integer view \a y
1182 explicit CachedView(const View& y);
1183 //@}
1184
1185 /// \name Value access
1186 //@{
1187 /// Return minimum of domain
1188 int min(void) const;
1189 /// Return maximum of domain
1190 int max(void) const;
1191 /// Return median of domain (greatest element not greater than the median)
1192 int med(void) const;
1193 /// Return assigned value (only if assigned)
1194 int val(void) const;
1195#ifdef GECODE_HAS_CBS
1196 /// Return reverse transformation of value according to view
1197 int baseval(int val) const;
1198#endif
1199
1200 /// Return size (cardinality) of domain
1201 unsigned int size(void) const;
1202 /// Return width of domain (distance between maximum and minimum)
1203 unsigned int width(void) const;
1204 /// Return regret of domain minimum (distance to next larger value)
1205 unsigned int regret_min(void) const;
1206 /// Return regret of domain maximum (distance to next smaller value)
1207 unsigned int regret_max(void) const;
1208 //@}
1209
1210 /// \name Domain tests
1211 //@{
1212 /// Test whether domain is a range
1213 bool range(void) const;
1214
1215 /// Test whether \a n is contained in domain
1216 bool in(int n) const;
1217 /// Test whether \a n is contained in domain
1218 bool in(long long int n) const;
1219 //@}
1220
1221 /// \name Domain update by value
1222 //@{
1223 /// Restrict domain values to be less or equal than \a n
1224 ModEvent lq(Space& home, int n);
1225 /// Restrict domain values to be less or equal than \a n
1226 ModEvent lq(Space& home, long long int n);
1227
1228 /// Restrict domain values to be less than \a n
1229 ModEvent le(Space& home, int n);
1230 /// Restrict domain values to be less than \a n
1231 ModEvent le(Space& home, long long int n);
1232
1233 /// Restrict domain values to be greater or equal than \a n
1234 ModEvent gq(Space& home, int n);
1235 /// Restrict domain values to be greater or equal than \a n
1236 ModEvent gq(Space& home, long long int n);
1237
1238 /// Restrict domain values to be greater than \a n
1239 ModEvent gr(Space& home, int n);
1240 /// Restrict domain values to be greater than \a n
1241 ModEvent gr(Space& home, long long int n);
1242
1243 /// Restrict domain values to be different from \a n
1244 ModEvent nq(Space& home, int n);
1245 /// Restrict domain values to be different from \a n
1246 ModEvent nq(Space& home, long long int n);
1247
1248 /// Restrict domain values to be equal to \a n
1249 ModEvent eq(Space& home, int n);
1250 /// Restrict domain values to be equal to \a n
1251 ModEvent eq(Space& home, long long int n);
1252 //@}
1253
1254 /**
1255 * \name Domain update by iterator
1256 *
1257 * Views can be both updated by range and value iterators.
1258 * Value iterators do not need to be strict in that the same value
1259 * is allowed to occur more than once in the iterated sequence.
1260 *
1261 * The argument \a depends must be true, if the iterator
1262 * passed as argument depends on the view on which the operation
1263 * is invoked. In this case, the view is only updated after the
1264 * iterator has been consumed. Otherwise, the domain might be updated
1265 * concurrently while following the iterator.
1266 *
1267 */
1268 //@{
1269 /// Replace domain by ranges described by \a i
1270 template<class I>
1271 ModEvent narrow_r(Space& home, I& i, bool depends=true);
1272 /// Intersect domain with ranges described by \a i
1273 template<class I>
1274 ModEvent inter_r(Space& home, I& i, bool depends=true);
1275 /// Remove from domain the ranges described by \a i
1276 template<class I>
1277 ModEvent minus_r(Space& home, I& i, bool depends=true);
1278 /// Replace domain by values described by \a i
1279 template<class I>
1280 ModEvent narrow_v(Space& home, I& i, bool depends=true);
1281 /// Intersect domain with values described by \a i
1282 template<class I>
1283 ModEvent inter_v(Space& home, I& i, bool depends=true);
1284 /// Remove from domain the values described by \a i
1285 template<class I>
1286 ModEvent minus_v(Space& home, I& i, bool depends=true);
1287 //@}
1288
1289 /// \name View-dependent propagator support
1290 //@{
1291 /// Translate modification event \a me to modification event delta for view
1292 static ModEventDelta med(ModEvent me);
1293 //@}
1294
1295 /// \name Delta information for advisors
1296 //@{
1297 /// Return minimum value just pruned
1298 int min(const Delta& d) const;
1299 /// Return maximum value just pruned
1300 int max(const Delta& d) const;
1301 /// Return width of values just pruned
1302 unsigned int width(const Delta& d) const;
1303 /// Test whether arbitrary values got pruned
1304 bool any(const Delta& d) const;
1305 //@}
1306
1307 /// \name Domain cache operations
1308 //@{
1309 /// Initialize cache to set \a s
1310 void initCache(Space& home, const IntSet& s);
1311 /// Update cache to current domain
1312 void cache(Space& home);
1313 /// Check whether cache differs from current domain
1314 bool modified(void) const;
1315 //@}
1316
1317 /// \name Cloning
1318 //@{
1319 /// Update this view to be a clone of view \a y
1320 void update(Space& home, CachedView<View>& y);
1321 //@}
1322 };
1323
1324 /**
1325 * \brief Print integer cached view
1326 * \relates Gecode::Int::CachedView
1327 */
1328 template<class Char, class Traits, class View>
1329 std::basic_ostream<Char,Traits>&
1330 operator <<(std::basic_ostream<Char,Traits>& os, const CachedView<View>& x);
1331
1332 /** \name View comparison
1333 * \relates Gecode::Int::CachedView
1334 */
1335 //@{
1336 /// Test whether views \a x and \a y are the same
1337 template<class View>
1338 bool operator ==(const CachedView<View>& x, const CachedView<View>& y);
1339 /// Test whether views \a x and \a y are not the same
1340 template<class View>
1341 bool operator !=(const CachedView<View>& x, const CachedView<View>& y);
1342 //@}
1343
1344 /**
1345 * \brief %Range iterator for cached integer views
1346 *
1347 * This iterator iterates the difference between the cached domain
1348 * and the current domain of an integer view.
1349 *
1350 * \ingroup TaskActorInt
1351 */
1352 template<class View>
1353 class ViewDiffRanges
1354 : public Iter::Ranges::Diff<Iter::Ranges::RangeList,ViewRanges<View> > {
1355 typedef Iter::Ranges::Diff<Iter::Ranges::RangeList,ViewRanges<View> >
1356 Super;
1357 protected:
1358 /// Cached domain iterator
1359 Iter::Ranges::RangeList cr;
1360 /// Current domain iterator
1361 ViewRanges<View> dr;
1362 public:
1363 /// \name Constructors and initialization
1364 //@{
1365 /// Default constructor
1366 ViewDiffRanges(void);
1367 /// Initialize with ranges for view \a x
1368 ViewDiffRanges(const CachedView<View>& x);
1369 /// Initialize with ranges for view \a x
1370 void init(const CachedView<View>& x);
1371 //@}
1372 };
1373
1374 /**
1375 * \brief Boolean view for Boolean variables
1376 *
1377 * Provides convenient and efficient operations for Boolean views.
1378 * \ingroup TaskActorIntView
1379 */
1380 class BoolView : public VarImpView<BoolVar> {
1381 protected:
1382 using VarImpView<BoolVar>::x;
1383 public:
1384 /// \name Constructors and initialization
1385 //@{
1386 /// Default constructor
1387 BoolView(void);
1388 /// Initialize from Boolean variable \a y
1389 BoolView(const BoolVar& y);
1390 /// Initialize from Boolean variable implementation \a y
1391 BoolView(BoolVarImp* y);
1392 //@}
1393
1394 /// \name Domain status access
1395 //@{
1396 /// How many bits does the status have
1397 static const int BITS = BoolVarImp::BITS;
1398 /// Status of domain assigned to zero
1399 static const BoolStatus ZERO = BoolVarImp::ZERO;
1400 /// Status of domain assigned to one
1401 static const BoolStatus ONE = BoolVarImp::ONE;
1402 /// Status of domain not yet assigned
1403 static const BoolStatus NONE = BoolVarImp::NONE;
1404 /// Return current domain status
1405 BoolStatus status(void) const;
1406 //@}
1407
1408 /// \name Value access
1409 //@{
1410 /// Return minimum of domain
1411 int min(void) const;
1412 /// Return maximum of domain
1413 int max(void) const;
1414 /// Return median of domain (greatest element not greater than the median)
1415 int med(void) const;
1416 /// Return assigned value (only if assigned)
1417 int val(void) const;
1418#ifdef GECODE_HAS_CBS
1419 /// Return reverse transformation of value according to view
1420 int baseval(int val) const;
1421#endif
1422
1423 /// Return size (cardinality) of domain
1424 unsigned int size(void) const;
1425 /// Return width of domain (distance between maximum and minimum)
1426 unsigned int width(void) const;
1427 /// Return regret of domain minimum (distance to next larger value)
1428 unsigned int regret_min(void) const;
1429 /// Return regret of domain maximum (distance to next smaller value)
1430 unsigned int regret_max(void) const;
1431 //@}
1432
1433 /// \name Domain tests
1434 //@{
1435 /// Test whether domain is a range
1436 bool range(void) const;
1437 /// Test whether \a n is contained in domain
1438 bool in(int n) const;
1439 /// Test whether \a n is contained in domain
1440 bool in(long long int n) const;
1441 //@}
1442
1443 /// \name Boolean domain tests
1444 //@{
1445 /// Test whether view is assigned to be zero
1446 bool zero(void) const;
1447 /// Test whether view is assigned to be one
1448 bool one(void) const;
1449 /// Test whether view is not yet assigned
1450 bool none(void) const;
1451 //@}
1452
1453 /// \name Boolean assignment operations
1454 //@{
1455 /// Try to assign view to one
1456 ModEvent one(Space& home);
1457 /// Try to assign view to zero
1458 ModEvent zero(Space& home);
1459 /// Assign not yet assigned view to one
1460 ModEvent one_none(Space& home);
1461 /// Assign not yet assigned view to zero
1462 ModEvent zero_none(Space& home);
1463 //@}
1464
1465 /// \name Domain update by value
1466 //@{
1467 /// Restrict domain values to be less or equal than \a n
1468 ModEvent lq(Space& home, int n);
1469 /// Restrict domain values to be less or equal than \a n
1470 ModEvent lq(Space& home, long long int n);
1471
1472 /// Restrict domain values to be less than \a n
1473 ModEvent le(Space& home, int n);
1474 /// Restrict domain values to be less than \a n
1475 ModEvent le(Space& home, long long int n);
1476
1477 /// Restrict domain values to be greater or equal than \a n
1478 ModEvent gq(Space& home, int n);
1479 /// Restrict domain values to be greater or equal than \a n
1480 ModEvent gq(Space& home, long long int n);
1481
1482 /// Restrict domain values to be greater than \a n
1483 ModEvent gr(Space& home, int n);
1484 /// Restrict domain values to be greater than \a n
1485 ModEvent gr(Space& home, long long int n);
1486
1487 /// Restrict domain values to be different from \a n
1488 ModEvent nq(Space& home, int n);
1489 /// Restrict domain values to be different from \a n
1490 ModEvent nq(Space& home, long long int n);
1491
1492 /// Restrict domain values to be equal to \a n
1493 ModEvent eq(Space& home, int n);
1494 /// Restrict domain values to be equal to \a n
1495 ModEvent eq(Space& home, long long int n);
1496 //@}
1497
1498 /**
1499 * \name Domain update by iterator
1500 *
1501 * Views can be both updated by range and value iterators.
1502 * Value iterators do not need to be strict in that the same value
1503 * is allowed to occur more than once in the iterated sequence.
1504 *
1505 * The argument \a depends must be true, if the iterator
1506 * passed as argument depends on the view on which the operation
1507 * is invoked. In this case, the view is only updated after the
1508 * iterator has been consumed. Otherwise, the domain might be updated
1509 * concurrently while following the iterator.
1510 *
1511 */
1512 //@{
1513 /// Replace domain by ranges described by \a i
1514 template<class I>
1515 ModEvent narrow_r(Space& home, I& i, bool depends=true);
1516 /// Intersect domain with ranges described by \a i
1517 template<class I>
1518 ModEvent inter_r(Space& home, I& i, bool depends=true);
1519 /// Remove from domain the ranges described by \a i
1520 template<class I>
1521 ModEvent minus_r(Space& home, I& i, bool depends=true);
1522 /// Replace domain by values described by \a i
1523 template<class I>
1524 ModEvent narrow_v(Space& home, I& i, bool depends=true);
1525 /// Intersect domain with values described by \a i
1526 template<class I>
1527 ModEvent inter_v(Space& home, I& i, bool depends=true);
1528 /// Remove from domain the values described by \a i
1529 template<class I>
1530 ModEvent minus_v(Space& home, I& i, bool depends=true);
1531 //@}
1532
1533 /// \name Delta information for advisors
1534 //@{
1535 /// Return minimum value just pruned
1536 int min(const Delta& d) const;
1537 /// Return maximum value just pruned
1538 int max(const Delta& d) const;
1539 /// Return width of values just pruned
1540 unsigned int width(const Delta& d) const;
1541 /// Test whether arbitrary values got pruned
1542 bool any(const Delta& d) const;
1543 /// Test whether a view has been assigned to zero
1544 static bool zero(const Delta& d);
1545 /// Test whether a view has been assigned to one
1546 static bool one(const Delta& d);
1547 //@}
1548
1549 /// \name View-dependent propagator support
1550 //@{
1551 /// Translate modification event \a me to modification event delta for view
1552 static ModEventDelta med(ModEvent me);
1553 //@}
1554 };
1555
1556 /**
1557 * \brief Print Boolean view
1558 * \relates Gecode::Int::BoolView
1559 */
1560 template<class Char, class Traits>
1561 std::basic_ostream<Char,Traits>&
1562 operator <<(std::basic_ostream<Char,Traits>& os, const BoolView& x);
1563
1564
1565
1566 /**
1567 * \brief Negated Boolean view
1568 *
1569 * A negated Boolean view \f$n\f$ for a Boolean view \f$b\f$
1570 * provides operations such that \f$n\f$
1571 * behaves as \f$\neg b\f$.
1572 * \ingroup TaskActorIntView
1573 */
1574 class NegBoolView : public DerivedView<BoolView> {
1575 protected:
1576 using DerivedView<BoolView>::x;
1577 public:
1578 /// \name Constructors and initialization
1579 //@{
1580 /// Default constructor
1581 NegBoolView(void);
1582 /// Initialize with Boolean view \a y
1583 explicit NegBoolView(const BoolView& y);
1584 //@}
1585
1586 /// \name Domain status access
1587 //@{
1588 /// How many bits does the status have
1589 static const int BITS = BoolView::BITS;
1590 /// Status of domain assigned to zero
1591 static const BoolStatus ZERO = BoolView::ONE;
1592 /// Status of domain assigned to one
1593 static const BoolStatus ONE = BoolView::ZERO;
1594 /// Status of domain not yet assigned
1595 static const BoolStatus NONE = BoolView::NONE;
1596 /// Return current domain status
1597 BoolStatus status(void) const;
1598 //@}
1599
1600 /// \name Boolean domain tests
1601 //@{
1602 /// Test whether view is assigned to be zero
1603 bool zero(void) const;
1604 /// Test whether view is assigned to be one
1605 bool one(void) const;
1606 /// Test whether view is not yet assigned
1607 bool none(void) const;
1608 //@}
1609
1610 /// \name Boolean assignment operations
1611 //@{
1612 /// Try to assign view to one
1613 ModEvent one(Space& home);
1614 /// Try to assign view to zero
1615 ModEvent zero(Space& home);
1616 /// Assign not yet assigned view to one
1617 ModEvent one_none(Space& home);
1618 /// Assign not yet assigned view to zero
1619 ModEvent zero_none(Space& home);
1620 //@}
1621
1622 /// \name Domain update by value
1623 //@{
1624 /// Restrict domain values to be less or equal than \a n
1625 ModEvent lq(Space& home, int n);
1626 /// Restrict domain values to be less or equal than \a n
1627 ModEvent lq(Space& home, long long int n);
1628
1629 /// Restrict domain values to be less than \a n
1630 ModEvent le(Space& home, int n);
1631 /// Restrict domain values to be less than \a n
1632 ModEvent le(Space& home, long long int n);
1633
1634 /// Restrict domain values to be greater or equal than \a n
1635 ModEvent gq(Space& home, int n);
1636 /// Restrict domain values to be greater or equal than \a n
1637 ModEvent gq(Space& home, long long int n);
1638
1639 /// Restrict domain values to be greater than \a n
1640 ModEvent gr(Space& home, int n);
1641 /// Restrict domain values to be greater than \a n
1642 ModEvent gr(Space& home, long long int n);
1643
1644 /// Restrict domain values to be different from \a n
1645 ModEvent nq(Space& home, int n);
1646 /// Restrict domain values to be different from \a n
1647 ModEvent nq(Space& home, long long int n);
1648
1649 /// Restrict domain values to be equal to \a n
1650 ModEvent eq(Space& home, int n);
1651 /// Restrict domain values to be equal to \a n
1652 ModEvent eq(Space& home, long long int n);
1653 //@}
1654
1655 /// \name Value access
1656 //@{
1657 /// Return minimum of domain
1658 int min(void) const;
1659 /// Return maximum of domain
1660 int max(void) const;
1661 /// Return assigned value (only if assigned)
1662 int val(void) const;
1663#ifdef GECODE_HAS_CBS
1664 /// Return reverse transformation of value according to view
1665 int baseval(int val) const;
1666#endif
1667 //@}
1668
1669 /// \name Delta information for advisors
1670 //@{
1671 /// Return minimum value just pruned
1672 int min(const Delta& d) const;
1673 /// Return maximum value just pruned
1674 int max(const Delta& d) const;
1675 /// Return width of values just pruned
1676 unsigned int width(const Delta& d) const;
1677 /// Test whether arbitrary values got pruned
1678 bool any(const Delta& d) const;
1679 /// Test whether a view has been assigned to zero
1680 static bool zero(const Delta& d);
1681 /// Test whether a view has been assigned to one
1682 static bool one(const Delta& d);
1683 //@}
1684 };
1685
1686 /** \name View comparison
1687 * \relates Gecode::Int::NegBoolView
1688 */
1689 //@{
1690 /// Test whether views \a x and \a y are the same
1691 bool operator ==(const NegBoolView& x, const NegBoolView& y);
1692 /// Test whether views \a x and \a y are not the same
1693 bool operator !=(const NegBoolView& x, const NegBoolView& y);
1694 //@}
1695
1696 /**
1697 * \brief Print negated Boolean view
1698 * \relates Gecode::Int::NegBoolView
1699 */
1700 template<class Char, class Traits>
1701 std::basic_ostream<Char,Traits>&
1702 operator <<(std::basic_ostream<Char,Traits>& os, const NegBoolView& x);
1703
1704}}
1705
1706#include <gecode/int/var/int.hpp>
1707#include <gecode/int/var/bool.hpp>
1708
1709#include <gecode/int/view/int.hpp>
1710
1711#include <gecode/int/view/constint.hpp>
1712#include <gecode/int/view/zero.hpp>
1713#include <gecode/int/view/minus.hpp>
1714#include <gecode/int/view/offset.hpp>
1715#include <gecode/int/view/scale.hpp>
1716#include <gecode/int/view/cached.hpp>
1717
1718#include <gecode/int/view/bool.hpp>
1719
1720#include <gecode/int/view/neg-bool.hpp>
1721
1722#include <gecode/int/view/print.hpp>
1723#include <gecode/int/var/print.hpp>
1724
1725namespace Gecode { namespace Int {
1726
1727 /**
1728 * \defgroup TaskActorIntTest Testing relations between integer views
1729 * \ingroup TaskActorInt
1730 */
1731
1732 //@{
1733 /// Result of testing relation
1734 enum RelTest {
1735 RT_FALSE = 0, ///< Relation does not hold
1736 RT_MAYBE = 1, ///< Relation may hold or not
1737 RT_TRUE = 2 ///< Relation does hold
1738 };
1739
1740 /// Test whether views \a x and \a y are equal (use bounds information)
1741 template<class VX, class VY> RelTest rtest_eq_bnd(VX x, VY y);
1742 /// Test whether views \a x and \a y are equal (use full domain information)
1743 template<class VX, class VY> RelTest rtest_eq_dom(VX x, VY y);
1744 /// Test whether view \a x and integer \a n are equal (use bounds information)
1745 template<class VX> RelTest rtest_eq_bnd(VX x, int n);
1746 /// Test whether view \a x and integer \a n are equal (use full domain information)
1747 template<class VX> RelTest rtest_eq_dom(VX x, int n);
1748
1749 /// Test whether views \a x and \a y are different (use bounds information)
1750 template<class VX, class VY> RelTest rtest_nq_bnd(VX x, VY y);
1751 /// Test whether views \a x and \a y are different (use full domain information)
1752 template<class VX, class VY> RelTest rtest_nq_dom(VX x, VY y);
1753 /// Test whether view \a x and integer \a n are different (use bounds information)
1754 template<class VX> RelTest rtest_nq_bnd(VX x, int n);
1755 /// Test whether view \a x and integer \a n are different (use full domain information)
1756 template<class VX> RelTest rtest_nq_dom(VX x, int n);
1757
1758 /// Test whether view \a x is less or equal than view \a y
1759 template<class VX, class VY> RelTest rtest_lq(VX x, VY y);
1760 /// Test whether view \a x is less or equal than integer \a n
1761 template<class VX> RelTest rtest_lq(VX x, int n);
1762
1763 /// Test whether view \a x is less than view \a y
1764 template<class VX, class VY> RelTest rtest_le(VX x, VY y);
1765 /// Test whether view \a x is less than integer \a n
1766 template<class VX> RelTest rtest_le(VX x, int n);
1767
1768 /// Test whether view \a x is greater or equal than view \a y
1769 template<class VX, class VY> RelTest rtest_gq(VX x, VY y);
1770 /// Test whether view \a x is greater or equal than integer \a n
1771 template<class VX> RelTest rtest_gq(VX x, int n);
1772
1773 /// Test whether view \a x is greater than view \a y
1774 template<class VX, class VY> RelTest rtest_gr(VX x, VY y);
1775 /// Test whether view \a x is greater than integer \a n
1776 template<class VX> RelTest rtest_gr(VX x, int n);
1777 //@}
1778
1779
1780 /**
1781 * \brief Boolean tests
1782 *
1783 */
1784 enum BoolTest {
1785 BT_NONE, ///< No sharing
1786 BT_SAME, ///< Same variable
1787 BT_COMP ///< Same variable but complement
1788 };
1789
1790 /**
1791 * \name Test sharing between Boolean and negated Boolean views
1792 * \relates BoolView NegBoolView
1793 */
1794 //@{
1795 /// Test whether views \a b0 and \a b1 are the same
1796 BoolTest bool_test(const BoolView& b0, const BoolView& b1);
1797 /// Test whether views \a b0 and \a b1 are complementary
1798 BoolTest bool_test(const BoolView& b0, const NegBoolView& b1);
1799 /// Test whether views \a b0 and \a b1 are complementary
1800 BoolTest bool_test(const NegBoolView& b0, const BoolView& b1);
1801 /// Test whether views \a b0 and \a b1 are the same
1802 BoolTest bool_test(const NegBoolView& b0, const NegBoolView& b1);
1803 //@}
1804
1805}}
1806
1807#include <gecode/int/view/rel-test.hpp>
1808#include <gecode/int/view/bool-test.hpp>
1809
1810// STATISTICS: int-var