Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
print.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.org>
5 * Gabor Szokoli <szokoli@gecode.org>
6 *
7 * Copyright:
8 * Guido Tack, 2004, 2005
9 * Gabor Szokoli, 2004
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.org
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#include <sstream>
37
38namespace Gecode { namespace Set {
39
41 template<class Char, class Traits, class I>
42 void
43 printBound(std::basic_ostream<Char,Traits>& s, I& r) {
44 s << '{';
45 while (r()) {
46 if (r.min() == r.max()) {
47 s << r.min();
48 } else if (r.min()+1 == r.max()) {
49 s << r.min() << "," << r.max();
50 } else {
51 s << r.min() << ".." << r.max();
52 }
53 ++r;
54 if (!r()) break;
55 s << ',';
56 }
57 s << '}';
58 }
59
61 template<class Char, class Traits, class IL, class IU>
62 void
63 print(std::basic_ostream<Char,Traits>& s, bool assigned, IL& lb, IU& ub,
64 unsigned int cardMin, unsigned int cardMax) {
65 if (assigned) {
66 printBound(s, ub);
67 } else {
68 printBound(s,lb);
69 s << "..";
70 printBound(s,ub);
71 if (cardMin==cardMax) {
72 s << "#(" << cardMin << ")";
73 } else {
74 s << "#(" << cardMin << "," << cardMax << ")";
75 }
76 }
77 }
78
79 template<class Char, class Traits>
80 std::basic_ostream<Char,Traits>&
81 operator <<(std::basic_ostream<Char,Traits>& os, const SetView& x) {
82 std::basic_ostringstream<Char,Traits> s;
83 s.copyfmt(os); s.width(0);
86 print(s, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
87 return os << s.str();
88 }
89
90 template<class Char, class Traits>
91 inline std::basic_ostream<Char,Traits>&
92 operator <<(std::basic_ostream<Char,Traits>& os, const EmptyView&) {
93 return os << "{}#0";
94 }
95
96 template<class Char, class Traits>
97 std::basic_ostream<Char,Traits>&
98 operator <<(std::basic_ostream<Char,Traits>& os, const UniverseView&) {
99 std::basic_ostringstream<Char,Traits> s;
100 s.copyfmt(os); s.width(0);
101 s << "{" << Gecode::Set::Limits::min << ".."
102 << Gecode::Set::Limits::max << "}#("
104 return os << s.str();
105 }
106
107 template<class Char, class Traits>
108 std::basic_ostream<Char,Traits>&
109 operator <<(std::basic_ostream<Char,Traits>& os, const ConstSetView& x) {
110 std::basic_ostringstream<Char,Traits> s;
111 s.copyfmt(os); s.width(0);
113 printBound(s, ub);
114 s << "#(" << x.cardMin() << ")";
115 return os << s.str();
116 }
117
118 template<class Char, class Traits>
119 std::basic_ostream<Char,Traits>&
120 operator <<(std::basic_ostream<Char,Traits>& os, const SingletonView& x) {
121 std::basic_ostringstream<Char,Traits> s;
122 s.copyfmt(os); s.width(0);
123 if (x.assigned()) {
124 s << "{" << x.glbMin() << "}#(1)";
125 } else {
127 s << "{}..";
128 printBound(s, ub);
129 s << "#(1)";
130 }
131 return os << s.str();
132 }
133
134}}
135
136// STATISTICS: set-var
int glbMin(void) const
Return minimum element of greatest lower bound.
Definition set.hpp:90
unsigned int cardMin(void) const
Return cardinality minimum.
Definition set.hpp:78
Constant view.
Definition view.hpp:186
Constant view for the empty set.
Definition view.hpp:336
Range iterator for the greatest lower bound.
Definition var-imp.hpp:359
Range iterator for the least upper bound.
Definition var-imp.hpp:317
Set view for set variables
Definition view.hpp:56
unsigned int cardMin(void) const
Return minimum cardinality.
Definition set.hpp:82
unsigned int cardMax(void) const
Return maximum cardinality.
Definition set.hpp:86
Singleton set view.
Definition view.hpp:594
bool assigned(void) const
Test whether view is assigned.
Definition var.hpp:111
bool assigned(void) const
Definition view.hpp:516
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const IdxViewArray< View > &x)
Definition idx-view.hpp:167
const int min
Smallest allowed integer in integer set.
Definition set.hh:99
const unsigned int card
Maximum cardinality of an integer set.
Definition set.hh:101
const int max
Largest allowed integer in integer set.
Definition set.hh:97
Finite integer sets.
Definition var-imp.hpp:137
void printBound(std::basic_ostream< Char, Traits > &s, I &r)
Print bound of a set view or variable.
Definition print.hpp:43
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition print.hpp:63
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:773
Post propagator for SetVar x
Definition set.hh:773