00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <sstream>
00041
00042 namespace Gecode { namespace Set {
00043
00045 template<class Char, class Traits, class I>
00046 void
00047 printBound(std::basic_ostream<Char,Traits>& s, I& r) {
00048 s << '{';
00049 while (r()) {
00050 if (r.min() == r.max()) {
00051 s << r.min();
00052 } else if (r.min()+1 == r.max()) {
00053 s << r.min() << "," << r.max();
00054 } else {
00055 s << r.min() << ".." << r.max();
00056 }
00057 ++r;
00058 if (!r()) break;
00059 s << ',';
00060 }
00061 s << '}';
00062 }
00063
00065 template<class Char, class Traits, class IL, class IU>
00066 void
00067 print(std::basic_ostream<Char,Traits>& s, bool assigned, IL& lb, IU& ub,
00068 unsigned int cardMin, unsigned int cardMax) {
00069 if (assigned) {
00070 printBound(s, ub);
00071 } else {
00072 printBound(s,lb);
00073 s << "..";
00074 printBound(s,ub);
00075 if (cardMin==cardMax) {
00076 s << "#(" << cardMin << ")";
00077 } else {
00078 s << "#(" << cardMin << "," << cardMax << ")";
00079 }
00080 }
00081 }
00082
00083 template<class Char, class Traits>
00084 std::basic_ostream<Char,Traits>&
00085 operator <<(std::basic_ostream<Char,Traits>& os, const SetView& x) {
00086 std::basic_ostringstream<Char,Traits> s;
00087 s.copyfmt(os); s.width(0);
00088 LubRanges<SetView> ub(x);
00089 GlbRanges<SetView> lb(x);
00090 print(s, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
00091 return os << s.str();
00092 }
00093
00094 template<class Char, class Traits>
00095 inline std::basic_ostream<Char,Traits>&
00096 operator <<(std::basic_ostream<Char,Traits>& os, const EmptyView&) {
00097 return os << "{}#0";
00098 }
00099
00100 template<class Char, class Traits>
00101 std::basic_ostream<Char,Traits>&
00102 operator <<(std::basic_ostream<Char,Traits>& os, const UniverseView&) {
00103 std::basic_ostringstream<Char,Traits> s;
00104 s.copyfmt(os); s.width(0);
00105 s << "{" << Gecode::Set::Limits::min << ".."
00106 << Gecode::Set::Limits::max << "}#("
00107 << Gecode::Set::Limits::card << ")";
00108 return os << s.str();
00109 }
00110
00111 template<class Char, class Traits>
00112 std::basic_ostream<Char,Traits>&
00113 operator <<(std::basic_ostream<Char,Traits>& os, const ConstSetView& x) {
00114 std::basic_ostringstream<Char,Traits> s;
00115 s.copyfmt(os); s.width(0);
00116 LubRanges<ConstSetView> ub(x);
00117 printBound(s, ub);
00118 s << "#(" << x.cardMin() << ")";
00119 return os << s.str();
00120 }
00121
00122 template<class Char, class Traits>
00123 std::basic_ostream<Char,Traits>&
00124 operator <<(std::basic_ostream<Char,Traits>& os, const SingletonView& x) {
00125 std::basic_ostringstream<Char,Traits> s;
00126 s.copyfmt(os); s.width(0);
00127 if (x.assigned()) {
00128 s << "{" << x.glbMin() << "}#(1)";
00129 } else {
00130 LubRanges<SingletonView> ub(x);
00131 s << "{}..";
00132 printBound(s, ub);
00133 s << "#(1)";
00134 }
00135 return os << s.str();
00136 }
00137
00138 }}
00139
00140