Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
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 
38 namespace 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 << "}#("
103  << Gecode::Set::Limits::card << ")";
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);
112  LubRanges<ConstSetView> ub(x);
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 {
126  LubRanges<SingletonView> ub(x);
127  s << "{}..";
128  printBound(s, ub);
129  s << "#(1)";
130  }
131  return os << s.str();
132  }
133 
134 }}
135 
136 // STATISTICS: set-var
Post propagator for SetVar x
Definition: set.hh:767
Range iterator for least upper bound of set variable views
Definition: set.hpp:211
const int min
Smallest allowed integer in integer set.
Definition: set.hh:99
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:43
unsigned int cardMin(void) const
Return cardinality minimum.
Definition: set.hpp:78
Range iterator for greatest lower bound of set variable views
Definition: set.hpp:242
bool assigned(void) const
Test whether view is assigned.
Definition: var.hpp:111
Gecode toplevel namespace
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
const int max
Largest allowed integer in integer set.
Definition: set.hh:97
const unsigned int card
Maximum cardinality of an integer set.
Definition: set.hh:101
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const CachedView< View > &x)
Definition: cached.hpp:374
unsigned int cardMax(void) const
Return cardinality maximum.
Definition: set.hpp:81
Set view for set variables
Definition: view.hpp:56
int glbMin(void) const
Return minimum element of greatest lower bound.
Definition: set.hpp:90
void printBound(std::basic_ostream< Char, Traits > &s, I &r)
Print bound of a set view or variable.
Definition: print.hpp:43