print.cc
Go to the documentation of this file.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 "gecode/set.hh"
00041
00042 using namespace Gecode::Set;
00043 using namespace Gecode::Int;
00044
00045 namespace Gecode { namespace Set {
00046
00047
00048
00049
00050
00051 template <class I>
00052 static void
00053 printBound(std::ostream& os, I& r) {
00054 os << '{';
00055 while (r()) {
00056 if (r.min() == r.max()) {
00057 os << r.min();
00058 } else if (r.min()+1 == r.max()) {
00059 os << r.min() << "," << r.max();
00060 } else {
00061 os << r.min() << ".." << r.max();
00062 }
00063 ++r;
00064 if (!r()) break;
00065 os << ',';
00066 }
00067 os << '}';
00068 }
00069
00070
00071
00072
00073
00074 template <class IL, class IU>
00075 static void
00076 printVar(std::ostream& os, const bool assigned, IL& lb, IU& ub,
00077 unsigned int cardMin, unsigned int cardMax) {
00078 if (assigned) {
00079 printBound(os, ub);
00080 os << "#(" << cardMin << ")";
00081 } else {
00082 printBound(os,lb);
00083 os << "..";
00084 printBound(os,ub);
00085 if (cardMin==cardMax) {
00086 os << "#(" <<cardMin << ")";
00087 } else {
00088 os << "#(" << cardMin << "," << cardMax << ")";
00089 }
00090 }
00091 }
00092
00093 }}
00094
00095 std::ostream&
00096 operator<<(std::ostream& os, const SetVarImp& x) {
00097 LubRanges<SetVarImp*> ub(&x);
00098 GlbRanges<SetVarImp*> lb(&x);
00099 printVar(os, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
00100 return os;
00101 }
00102
00103 std::ostream&
00104 operator<<(std::ostream& os, const SetView& x) {
00105 LubRanges<SetView> ub(x);
00106 GlbRanges<SetView> lb(x);
00107 printVar(os, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
00108 return os;
00109 }
00110
00111 std::ostream&
00112 operator<<(std::ostream& os, const EmptyView&) {
00113 return os << "{}#0";
00114 }
00115
00116 std::ostream&
00117 operator<<(std::ostream& os, const UniverseView&) {
00118 return os << "{" << Gecode::Set::Limits::min << ".."
00119 << Gecode::Set::Limits::max << "}#("
00120 << Gecode::Set::Limits::card << ")";
00121 }
00122
00123 std::ostream&
00124 operator<<(std::ostream& os, const ConstantView& s) {
00125 LubRanges<ConstantView> ub(s);
00126 printBound(os, ub);
00127 return os << "#(" << s.cardMin() << ")";
00128 }
00129
00130 std::ostream&
00131 operator<<(std::ostream& os, const SingletonView& s) {
00132 if (s.assigned()) {
00133 return os << "{" << s.glbMin() << "}#(1)";
00134 }
00135 LubRanges<SingletonView> ub(s);
00136 os << "{}..";
00137 printBound(os, ub);
00138 return os << "#(1)";
00139 }
00140
00141