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 #include "gecode/set.hh"
00025
00026 using namespace Gecode::Set;
00027 using namespace Gecode::Int;
00028
00029 namespace Gecode { namespace Set {
00030
00031
00032
00033
00034
00035 template <class I>
00036 static void
00037 printBound(std::ostream& os, I& r) {
00038 os << '{';
00039 while (r()) {
00040 if (r.min() == r.max()) {
00041 os << r.min();
00042 } else if (r.min()+1 == r.max()) {
00043 os << r.min() << " " << r.max();
00044 } else {
00045 os << r.min() << "#" << r.max();
00046 }
00047 ++r;
00048 if (!r()) break;
00049 os << ' ';
00050 }
00051 os << '}';
00052 }
00053
00054
00055
00056
00057
00058 template <class IL, class IU>
00059 static void
00060 printVar(std::ostream& os, const bool assigned, IL& lb, IU& ub,
00061 unsigned int cardMin, unsigned int cardMax) {
00062 if (assigned) {
00063 printBound(os, ub);
00064 os << "#" << cardMin;
00065 } else {
00066 os << "_{";
00067 printBound(os,lb);
00068 os << "..";
00069 printBound(os,ub);
00070 os << "}";
00071 if (cardMin==cardMax) {
00072 os << "#" <<cardMin;
00073 } else {
00074 os << "#{" << cardMin << "," << cardMax << "}";
00075 }
00076 }
00077 }
00078
00079 }}
00080
00081 std::ostream&
00082 operator<<(std::ostream& os, const SetVarImp& x) {
00083 LubRanges<SetVarImp*> ub(&x);
00084 GlbRanges<SetVarImp*> lb(&x);
00085 printVar(os, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
00086 return os;
00087 }
00088
00089 std::ostream&
00090 operator<<(std::ostream& os, const SetView& x) {
00091 LubRanges<SetView> ub(x);
00092 GlbRanges<SetView> lb(x);
00093 printVar(os, x.assigned(), lb, ub, x.cardMin(), x.cardMax()) ;
00094 return os;
00095 }
00096
00097 std::ostream&
00098 operator<<(std::ostream& os, const EmptyView&) {
00099 return os << "{}#0";
00100 }
00101
00102 std::ostream&
00103 operator<<(std::ostream& os, const UniverseView&) {
00104 return os << "{" << Gecode::Limits::Set::int_min << "#"
00105 << Gecode::Limits::Set::int_max << "}#"
00106 << Gecode::Limits::Set::card_max;
00107 }
00108
00109 std::ostream&
00110 operator<<(std::ostream& os, const ConstantView& s) {
00111 return os << "{?}#?";
00112 }
00113
00114 std::ostream&
00115 operator<<(std::ostream& os, const SingletonView&) {
00116 return os << "{?}#1";
00117 }
00118
00119
00120