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 #include "gecode/cpltset.hh"
00039 #include "gecode/support/buddy/kernel.h"
00040
00041 namespace Gecode { namespace CpltSet {
00042
00043
00044
00045
00046
00047 template <class I>
00048 static void
00049 printBound(std::ostream& os, I& r) {
00050 os << '{';
00051 while (r()) {
00052 if (r.min() == r.max()) {
00053 os << r.min();
00054 } else if (r.min()+1 == r.max()) {
00055 os << r.min() << "," << r.max();
00056 } else {
00057 os << r.min() << ".." << r.max();
00058 }
00059 ++r;
00060 if (!r()) break;
00061 os << ',';
00062 }
00063 os << '}';
00064 }
00065
00067 bool printBddDom(std::ostream& os, int off, int min, int width, bool first,
00068 char* profile, bdd& r) {
00069 if (r == bdd_true())
00070 {
00071 if (!first)
00072 os << ",";
00073 bool assigned = true;
00074 int last = -1;
00075 int lastUnknown = -1;
00076 for (int i = 0; i<width; i++) {
00077 if (profile[i] < 0) {
00078 assigned = false; lastUnknown = i;
00079 }
00080 if (profile[i] == 1) {
00081 last = i; lastUnknown = i;
00082 }
00083 }
00084 if (assigned) {
00085 os << "{";
00086 for (int i = 0; i<=last; i++) {
00087 if (profile[i] == 1)
00088 os << min+i << (i<last ? "," : "");
00089 }
00090 os << "}";
00091 } else {
00092 os << "{";
00093 for (int i = 0; i<=last; i++) {
00094 if (profile[i] == 1)
00095 os << min+i << (i<last ? "," : "");
00096 }
00097 os << "}..{";
00098 for (int i = 0; i<=lastUnknown; i++) {
00099 if (profile[i] != 0)
00100 os << min+i << (i<lastUnknown ? "," : "");
00101 }
00102 os << "}";
00103 }
00104 return false;
00105 }
00106
00107 if (r == bdd_false())
00108 return first;
00109
00110 if (bdd_low(r) != bdd_false()) {
00111 profile[bddlevel2var[r.getlevel()]-off] = 0;
00112 for (int v=bdd_low(r).getlevel()-1 ; v>r.getlevel() ; --v) {
00113 profile[bddlevel2var[v]-off] = -1;
00114 }
00115 bdd rlow = bdd_low(r);
00116 first = printBddDom(os, off, min, width, first, profile, rlow);
00117 }
00118
00119 if (bdd_high(r) != bdd_false()) {
00120 profile[bddlevel2var[r.getlevel()]-off] = 1;
00121 for (int v=bdd_high(r).getlevel()-1 ; v>r.getlevel() ; --v) {
00122 profile[bddlevel2var[v]-off] = -1;
00123 }
00124 bdd rhigh = bdd_high(r);
00125 first = printBddDom(os, off, min, width, first, profile, rhigh);
00126 }
00127 return first;
00128 }
00129
00130 }}
00131
00132 using namespace Gecode;
00133 using namespace Gecode::CpltSet;
00134
00139 std::ostream&
00140 operator<<(std::ostream& os, const CpltSetView& x) {
00141 bool assigned = x.assigned();
00142 if (assigned) {
00143 GlbValues<CpltSetView> glb(x);
00144 Iter::Values::ToRanges<GlbValues<CpltSetView> > glbr(glb);
00145 printBound(os, glbr);
00146 } else {
00147 bdd dom = x.dom();
00148 os << "{";
00149 char* profile = Memory::bmalloc<char>(x.tableWidth());
00150 for (int i=x.tableWidth(); i--;)
00151 profile[i] = -1;
00152 printBddDom(os, x.offset(), x.initialLubMin(), x.tableWidth(), true,
00153 profile, dom);
00154 Memory::free(profile);
00155 os << "}";
00156 }
00157 return os;
00158 }
00159
00160 std::ostream&
00161 operator<< (std::ostream& os, const CpltSetVar& x) {
00162 CpltSetView xv(x);
00163 return os << xv;
00164 }
00165
00166