Generated on Wed Nov 1 15:04:41 2006 for Gecode by doxygen 1.4.5

print.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Gabor Szokoli <szokoli@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2004, 2005
00008  *     Gabor Szokoli, 2004
00009  *
00010  *  Last modified:
00011  *     $Date: 2006-04-11 15:58:37 +0200 (Tue, 11 Apr 2006) $ by $Author: tack $
00012  *     $Revision: 3188 $
00013  *
00014  *  This file is part of Gecode, the generic constraint
00015  *  development environment:
00016  *     http://www.gecode.org
00017  *
00018  *  See the file "LICENSE" for information on usage and
00019  *  redistribution of this file, and for a
00020  *     DISCLAIMER OF ALL WARRANTIES.
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  * Printing a bound
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  * Printing a variable or view from the data generaly available
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 // STATISTICS: set-var
00120