Generated on Sat Feb 7 2015 02:01:17 for Gecode by doxygen 1.8.9.1
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  * Last modified:
12  * $Date: 2013-03-07 02:18:29 +0100 (Thu, 07 Mar 2013) $ by $Author: mears $
13  * $Revision: 13455 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include <sstream>
41 
42 namespace Gecode { namespace Set {
43 
45  template<class Char, class Traits, class I>
46  void
47  printBound(std::basic_ostream<Char,Traits>& s, I& r) {
48  s << '{';
49  while (r()) {
50  if (r.min() == r.max()) {
51  s << r.min();
52  } else if (r.min()+1 == r.max()) {
53  s << r.min() << "," << r.max();
54  } else {
55  s << r.min() << ".." << r.max();
56  }
57  ++r;
58  if (!r()) break;
59  s << ',';
60  }
61  s << '}';
62  }
63 
65  template<class Char, class Traits, class IL, class IU>
66  void
67  print(std::basic_ostream<Char,Traits>& s, bool assigned, IL& lb, IU& ub,
68  unsigned int cardMin, unsigned int cardMax) {
69  if (assigned) {
70  printBound(s, ub);
71  } else {
72  printBound(s,lb);
73  s << "..";
74  printBound(s,ub);
75  if (cardMin==cardMax) {
76  s << "#(" << cardMin << ")";
77  } else {
78  s << "#(" << cardMin << "," << cardMax << ")";
79  }
80  }
81  }
82 
83  template<class Char, class Traits>
84  std::basic_ostream<Char,Traits>&
85  operator <<(std::basic_ostream<Char,Traits>& os, const SetView& x) {
86  std::basic_ostringstream<Char,Traits> s;
87  s.copyfmt(os); s.width(0);
90  print(s, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
91  return os << s.str();
92  }
93 
94  template<class Char, class Traits>
95  inline std::basic_ostream<Char,Traits>&
96  operator <<(std::basic_ostream<Char,Traits>& os, const EmptyView&) {
97  return os << "{}#0";
98  }
99 
100  template<class Char, class Traits>
101  std::basic_ostream<Char,Traits>&
102  operator <<(std::basic_ostream<Char,Traits>& os, const UniverseView&) {
103  std::basic_ostringstream<Char,Traits> s;
104  s.copyfmt(os); s.width(0);
105  s << "{" << Gecode::Set::Limits::min << ".."
106  << Gecode::Set::Limits::max << "}#("
107  << Gecode::Set::Limits::card << ")";
108  return os << s.str();
109  }
110 
111  template<class Char, class Traits>
112  std::basic_ostream<Char,Traits>&
113  operator <<(std::basic_ostream<Char,Traits>& os, const ConstSetView& x) {
114  std::basic_ostringstream<Char,Traits> s;
115  s.copyfmt(os); s.width(0);
117  printBound(s, ub);
118  s << "#(" << x.cardMin() << ")";
119  return os << s.str();
120  }
121 
122  template<class Char, class Traits>
123  std::basic_ostream<Char,Traits>&
124  operator <<(std::basic_ostream<Char,Traits>& os, const SingletonView& x) {
125  std::basic_ostringstream<Char,Traits> s;
126  s.copyfmt(os); s.width(0);
127  if (x.assigned()) {
128  s << "{" << x.glbMin() << "}#(1)";
129  } else {
131  s << "{}..";
132  printBound(s, ub);
133  s << "#(1)";
134  }
135  return os << s.str();
136  }
137 
138 }}
139 
140 // STATISTICS: set-var
const int min
Smallest allowed integer in integer set.
Definition: set.hh:101
Range iterator for least upper bound of constant set view
Definition: const.hpp:628
const unsigned int card
Maximum cardinality of an integer set.
Definition: set.hh:103
const int max
Largest allowed integer in integer set.
Definition: set.hh:99
Range iterator for least upper bound of singleton set view
Definition: singleton.hpp:304
Range iterator for least upper bound of set variable views
Definition: set.hpp:205
Constant view for the universe.
Definition: view.hpp:461
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Range iterator for greatest lower bound of set variable views
Definition: set.hpp:236
Singleton set view.
Definition: view.hpp:589
Set view for set variables
Definition: view.hpp:60
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:67
void printBound(std::basic_ostream< Char, Traits > &s, I &r)
Print bound of a set view or variable.
Definition: print.hpp:47
Constant view.
Definition: view.hpp:190
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
Gecode toplevel namespace
Constant view for the empty set.
Definition: view.hpp:335