/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * * Copyright: * Guido Tack, 2006 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ namespace Gecode { namespace Gist { template VarComparator::VarComparator(std::string name) : TextOutput(name) {} template void VarComparator::compare(const Space& s0, const Space& s1) { std::ostringstream result; dynamic_cast(s0).compare(s1,result); if (result.str() != "") { init(); addHtml("
\n");
      getStream() << result.str() << std::endl;
      addHtml("

"); } } template std::string VarComparator::name(void) { return TextOutput::name(); } template void VarComparator::finalize(void) { TextOutput::finalize(); } inline std::string Comparator::compare(std::string x_n, IntVar x, IntVar y) { IntVarRanges xr(x), yr(y); if (!Iter::Ranges::equal(xr,yr)) { std::ostringstream ret; ret << x_n << "=" << x << " -> " << y; return ret.str(); } return ""; } inline std::string Comparator::compare(std::string x_n, BoolVar x, BoolVar y) { if (! (x.min() == y.min() && x.max() == y.max()) ) { std::ostringstream ret; ret << x_n << "=" << x << " -> " << y; return ret.str(); } return ""; } #ifdef GECODE_HAS_SET_VARS inline std::string Comparator::compare(std::string x_n, SetVar x, SetVar y) { SetVarGlbRanges xglbr(x), yglbr(y); SetVarLubRanges xlubr(x), ylubr(y); if (! (Iter::Ranges::equal(xglbr,yglbr) && Iter::Ranges::equal(xlubr,ylubr) && x.cardMin() == y.cardMin() && y.cardMax() == y.cardMax()) ) { std::ostringstream ret; ret << x_n << "=" << x << " -> " << y; return ret.str(); } return ""; } #endif #ifdef GECODE_HAS_FLOAT_VARS inline std::string Comparator::compare(std::string x_n, FloatVar x, FloatVar y) { if (! (x.min() == y.min() && x.max() == y.max()) ) { std::ostringstream ret; ret << x_n << "=" << x << " -> " << y; return ret.str(); } return ""; } #endif template std::string Comparator::compare(std::string x_n, const VarArgArray& x, const VarArgArray& y) { if (x.size() != y.size()) return "Error: array size mismatch"; std::ostringstream ret; bool first = true; for (int i=0; i Print::Print(const std::string& name) : TextOutput(name) {} template void Print::inspect(const Space& node) { init(); addHtml("
\n");
    dynamic_cast(node).print(getStream());
    flush();
    addHtml("

"); } template std::string Print::name(void) { return TextOutput::name(); } template void Print::finalize(void) { TextOutput::finalize(); } forceinline Options::Options(void) {} forceinline Options::I_::I_(void) : _click(heap,1), n_click(0), _solution(heap,1), n_solution(0), _move(heap,1), n_move(0), _compare(heap,1), n_compare(0) {} forceinline void Options::I_::click(Inspector* i) { _click[static_cast(n_click++)] = i; } forceinline void Options::I_::solution(Inspector* i) { _solution[static_cast(n_solution++)] = i; } forceinline void Options::I_::move(Inspector* i) { _move[static_cast(n_move++)] = i; } forceinline void Options::I_::compare(Comparator* c) { _compare[static_cast(n_compare++)] = c; } forceinline Inspector* Options::I_::click(unsigned int i) const { return (i < n_click) ? _click[i] : nullptr; } forceinline Inspector* Options::I_::solution(unsigned int i) const { return (i < n_solution) ? _solution[i] : nullptr; } forceinline Inspector* Options::I_::move(unsigned int i) const { return (i < n_move) ? _move[i] : nullptr; } forceinline Comparator* Options::I_::compare(unsigned int i) const { return (i < n_compare) ? _compare[i] : nullptr; } inline int dfs(Space* root, const Gist::Options& opt) { return explore(root, false, opt); } inline int bab(Space* root, const Gist::Options& opt) { return Gist::explore(root, true, opt); } }} // STATISTICS: gist-any