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 Iter::Ranges::IsRangeIter<I>();
00049 s << '{';
00050 while (r()) {
00051 if (r.min() == r.max()) {
00052 s << r.min();
00053 } else if (r.min()+1 == r.max()) {
00054 s << r.min() << "," << r.max();
00055 } else {
00056 s << r.min() << ".." << r.max();
00057 }
00058 ++r;
00059 if (!r()) break;
00060 s << ',';
00061 }
00062 s << '}';
00063 }
00064
00066 template<class Char, class Traits, class IL, class IU>
00067 void
00068 print(std::basic_ostream<Char,Traits>& s, bool assigned, IL& lb, IU& ub,
00069 unsigned int cardMin, unsigned int cardMax) {
00070 if (assigned) {
00071 printBound(s, ub);
00072 s << "#(" << cardMin << ")";
00073 } else {
00074 printBound(s,lb);
00075 s << "..";
00076 printBound(s,ub);
00077 if (cardMin==cardMax) {
00078 s << "#(" << cardMin << ")";
00079 } else {
00080 s << "#(" << cardMin << "," << cardMax << ")";
00081 }
00082 }
00083 }
00084
00085 template<class Char, class Traits>
00086 std::basic_ostream<Char,Traits>&
00087 operator <<(std::basic_ostream<Char,Traits>& os, const SetView& x) {
00088 std::basic_ostringstream<Char,Traits> s;
00089 s.copyfmt(os); s.width(0);
00090 LubRanges<SetView> ub(x);
00091 GlbRanges<SetView> lb(x);
00092 print(s, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
00093 return os << s.str();
00094 }
00095
00096 template<class Char, class Traits>
00097 inline std::basic_ostream<Char,Traits>&
00098 operator <<(std::basic_ostream<Char,Traits>& os, const EmptyView&) {
00099 return os << "{}#0";
00100 }
00101
00102 template<class Char, class Traits>
00103 std::basic_ostream<Char,Traits>&
00104 operator <<(std::basic_ostream<Char,Traits>& os, const UniverseView&) {
00105 std::basic_ostringstream<Char,Traits> s;
00106 s.copyfmt(os); s.width(0);
00107 s << "{" << Gecode::Set::Limits::min << ".."
00108 << Gecode::Set::Limits::max << "}#("
00109 << Gecode::Set::Limits::card << ")";
00110 return os << s.str();
00111 }
00112
00113 template<class Char, class Traits>
00114 std::basic_ostream<Char,Traits>&
00115 operator <<(std::basic_ostream<Char,Traits>& os, const ConstantView& x) {
00116 std::basic_ostringstream<Char,Traits> s;
00117 s.copyfmt(os); s.width(0);
00118 LubRanges<ConstantView> ub(x);
00119 printBound(s, ub);
00120 s << "#(" << x.cardMin() << ")";
00121 return os << s.str();
00122 }
00123
00124 template<class Char, class Traits>
00125 std::basic_ostream<Char,Traits>&
00126 operator <<(std::basic_ostream<Char,Traits>& os, const SingletonView& x) {
00127 std::basic_ostringstream<Char,Traits> s;
00128 s.copyfmt(os); s.width(0);
00129 if (x.assigned()) {
00130 s << "{" << x.glbMin() << "}#(1)";
00131 } else {
00132 LubRanges<SingletonView> ub(x);
00133 s << "{}..";
00134 printBound(s, ub);
00135 s << "#(1)";
00136 }
00137 return os << s.str();
00138 }
00139
00140 }}
00141
00142