Generated on Mon Aug 25 11:35:34 2008 for Gecode by doxygen 1.5.6

print.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *     Gabor Szokoli <szokoli@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Guido Tack, 2004, 2005
00009  *     Gabor Szokoli, 2004
00010  *
00011  *  Last modified:
00012  *     $Date: 2008-02-06 18:48:22 +0100 (Wed, 06 Feb 2008) $ by $Author: schulte $
00013  *     $Revision: 6102 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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    * Printing a bound
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    * Printing a variable or view from the data generaly available
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 // STATISTICS: set-var