Generated on Fri Oct 19 11:24:59 2018 for Gecode by doxygen 1.6.3

gist.hpp

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  *
00006  *  Copyright:
00007  *     Guido Tack, 2006
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  * Permission is hereby granted, free of charge, to any person obtaining
00014  * a copy of this software and associated documentation files (the
00015  * "Software"), to deal in the Software without restriction, including
00016  * without limitation the rights to use, copy, modify, merge, publish,
00017  * distribute, sublicense, and/or sell copies of the Software, and to
00018  * permit persons to whom the Software is furnished to do so, subject to
00019  * the following conditions:
00020  *
00021  * The above copyright notice and this permission notice shall be
00022  * included in all copies or substantial portions of the Software.
00023  *
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Gist {
00035 
00036   template<class S>
00037   VarComparator<S>::VarComparator(std::string name)
00038     : TextOutput(name) {}
00039 
00040   template<class S>
00041   void
00042   VarComparator<S>::compare(const Space& s0, const Space& s1) {
00043     std::ostringstream result;
00044     dynamic_cast<const S&>(s0).compare(s1,result);
00045     if (result.str() != "") {
00046       init();
00047       addHtml("<pre>\n");
00048       getStream() << result.str() << std::endl;
00049       addHtml("</pre><hr />");
00050     }
00051   }
00052 
00053   template<class S>
00054   std::string
00055   VarComparator<S>::name(void) {
00056     return TextOutput::name();
00057   }
00058 
00059   template<class S>
00060   void
00061   VarComparator<S>::finalize(void) {
00062     TextOutput::finalize();
00063   }
00064 
00065   inline std::string
00066   Comparator::compare(std::string x_n, IntVar x, IntVar y) {
00067     IntVarRanges xr(x), yr(y);
00068     if (!Iter::Ranges::equal(xr,yr)) {
00069       std::ostringstream ret;
00070       ret << x_n << "=" << x << " -> " << y;
00071       return ret.str();
00072     }
00073     return "";
00074   }
00075   inline std::string
00076   Comparator::compare(std::string x_n, BoolVar x, BoolVar y) {
00077     if (! (x.min() == y.min() && x.max() == y.max()) ) {
00078       std::ostringstream ret;
00079       ret << x_n << "=" << x << " -> " << y;
00080       return ret.str();
00081     }
00082     return "";
00083   }
00084 #ifdef GECODE_HAS_SET_VARS
00085   inline std::string
00086   Comparator::compare(std::string x_n, SetVar x, SetVar y) {
00087     SetVarGlbRanges xglbr(x), yglbr(y);
00088     SetVarLubRanges xlubr(x), ylubr(y);
00089     if (! (Iter::Ranges::equal(xglbr,yglbr) &&
00090            Iter::Ranges::equal(xlubr,ylubr) &&
00091            x.cardMin() == y.cardMin() &&
00092            y.cardMax() == y.cardMax()) ) {
00093       std::ostringstream ret;
00094       ret << x_n << "=" << x << " -> " << y;
00095       return ret.str();
00096     }
00097     return "";
00098   }
00099 #endif
00100 #ifdef GECODE_HAS_FLOAT_VARS
00101   inline std::string
00102   Comparator::compare(std::string x_n, FloatVar x, FloatVar y) {
00103     if (! (x.min() == y.min() && x.max() == y.max()) ) {
00104       std::ostringstream ret;
00105       ret << x_n << "=" << x << " -> " << y;
00106       return ret.str();
00107     }
00108     return "";
00109   }
00110 #endif
00111   template<class Var>
00112   std::string
00113   Comparator::compare(std::string x_n, const VarArgArray<Var>& x,
00114     const VarArgArray<Var>& y) {
00115     if (x.size() != y.size())
00116       return "Error: array size mismatch";
00117     std::ostringstream ret;
00118     bool first = true;
00119     for (int i=0; i<x.size(); i++) {
00120       std::ostringstream xni;
00121       xni << x_n << "[" << i << "]";
00122       std::string cmp = compare(xni.str(),x[i],y[i]);
00123       if (cmp != "") {
00124         if (!first) {
00125           ret << ", ";
00126         } else {
00127           first = false;
00128         }
00129         ret << cmp;
00130       }
00131     }
00132     return ret.str();
00133   }
00134 
00135   template<class S>
00136   Print<S>::Print(const std::string& name)
00137     : TextOutput(name) {}
00138 
00139   template<class S>
00140   void
00141   Print<S>::inspect(const Space& node) {
00142     init();
00143     addHtml("<pre>\n");
00144     dynamic_cast<const S&>(node).print(getStream());
00145     flush();
00146     addHtml("</pre><hr />");
00147   }
00148 
00149   template<class S>
00150   std::string
00151   Print<S>::name(void) {
00152     return TextOutput::name();
00153   }
00154 
00155   template<class S>
00156   void
00157   Print<S>::finalize(void) {
00158     TextOutput::finalize();
00159   }
00160 
00161   forceinline
00162   Options::Options(void) {}
00163 
00164   forceinline
00165   Options::_I::_I(void) : _click(heap,1), n_click(0),
00166     _solution(heap,1), n_solution(0),
00167     _move(heap,1), n_move(0), _compare(heap,1), n_compare(0) {}
00168 
00169   forceinline void
00170   Options::_I::click(Inspector* i) {
00171     _click[static_cast<int>(n_click++)] = i;
00172   }
00173   forceinline void
00174   Options::_I::solution(Inspector* i) {
00175     _solution[static_cast<int>(n_solution++)] = i;
00176   }
00177   forceinline void
00178   Options::_I::move(Inspector* i) {
00179     _move[static_cast<int>(n_move++)] = i;
00180   }
00181   forceinline void
00182   Options::_I::compare(Comparator* c) {
00183     _compare[static_cast<int>(n_compare++)] = c;
00184   }
00185   forceinline Inspector*
00186   Options::_I::click(unsigned int i) const {
00187     return (i < n_click) ? _click[i] : NULL;
00188   }
00189   forceinline Inspector*
00190   Options::_I::solution(unsigned int i) const {
00191     return (i < n_solution) ? _solution[i] : NULL;
00192   }
00193   forceinline Inspector*
00194   Options::_I::move(unsigned int i) const {
00195     return (i < n_move) ? _move[i] : NULL;
00196   }
00197   forceinline Comparator*
00198   Options::_I::compare(unsigned int i) const {
00199     return (i < n_compare) ? _compare[i] : NULL;
00200   }
00201 
00202   inline int
00203   dfs(Space* root, const Gist::Options& opt) {
00204     return explore(root, false, opt);
00205   }
00206 
00207   inline int
00208   bab(Space* root, const Gist::Options& opt) {
00209     return Gist::explore(root, true, opt);
00210   }
00211 
00212 }}
00213 
00214 // STATISTICS: gist-any