gist.hpp
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 namespace Gecode { namespace Gist {
00039
00040 template<class S>
00041 VarComparator<S>::VarComparator(std::string name)
00042 : TextOutput(name) {}
00043
00044 template<class S>
00045 void
00046 VarComparator<S>::compare(const Space& s0, const Space& s1) {
00047 std::ostringstream result;
00048 dynamic_cast<const S&>(s0).compare(s1,result);
00049 if (result.str() != "") {
00050 init();
00051 addHtml("<pre>\n");
00052 getStream() << result.str() << std::endl;
00053 addHtml("</pre><hr />");
00054 }
00055 }
00056
00057 template<class S>
00058 std::string
00059 VarComparator<S>::name(void) {
00060 return TextOutput::name();
00061 }
00062
00063 template<class S>
00064 void
00065 VarComparator<S>::finalize(void) {
00066 TextOutput::finalize();
00067 }
00068
00069 inline std::string
00070 Comparator::compare(std::string x_n, IntVar x, IntVar y) {
00071 IntVarRanges xr(x), yr(y);
00072 if (!Iter::Ranges::equal(xr,yr)) {
00073 std::ostringstream ret;
00074 ret << x_n << "=" << x << " -> " << y;
00075 return ret.str();
00076 }
00077 return "";
00078 }
00079 inline std::string
00080 Comparator::compare(std::string x_n, BoolVar x, BoolVar y) {
00081 if (! (x.min() == y.min() && x.max() == y.max()) ) {
00082 std::ostringstream ret;
00083 ret << x_n << "=" << x << " -> " << y;
00084 return ret.str();
00085 }
00086 return "";
00087 }
00088 #ifdef GECODE_HAS_SET_VARS
00089 inline std::string
00090 Comparator::compare(std::string x_n, SetVar x, SetVar y) {
00091 SetVarGlbRanges xglbr(x), yglbr(y);
00092 SetVarLubRanges xlubr(x), ylubr(y);
00093 if (! (Iter::Ranges::equal(xglbr,yglbr) &&
00094 Iter::Ranges::equal(xlubr,ylubr) &&
00095 x.cardMin() == y.cardMin() &&
00096 y.cardMax() == y.cardMax()) ) {
00097 std::ostringstream ret;
00098 ret << x_n << "=" << x << " -> " << y;
00099 return ret.str();
00100 }
00101 return "";
00102 }
00103 #endif
00104 template<class Var>
00105 std::string
00106 Comparator::compare(std::string x_n, const VarArgArray<Var>& x,
00107 const VarArgArray<Var>& y) {
00108 if (x.size() != y.size())
00109 return "Error: array size mismatch";
00110 std::ostringstream ret;
00111 bool first = true;
00112 for (int i=0; i<x.size(); i++) {
00113 std::ostringstream xni;
00114 xni << x_n << "[" << i << "]";
00115 std::string cmp = compare(xni.str(),x[i],y[i]);
00116 if (cmp != "") {
00117 if (!first) {
00118 ret << ", ";
00119 } else {
00120 first = false;
00121 }
00122 ret << cmp;
00123 }
00124 }
00125 return ret.str();
00126 }
00127
00128 template<class S>
00129 Print<S>::Print(const std::string& name)
00130 : TextOutput(name) {}
00131
00132 template<class S>
00133 void
00134 Print<S>::inspect(const Space& node) {
00135 init();
00136 addHtml("<pre>\n");
00137 dynamic_cast<const S&>(node).print(getStream());
00138 flush();
00139 addHtml("</pre><hr />");
00140 }
00141
00142 template<class S>
00143 std::string
00144 Print<S>::name(void) {
00145 return TextOutput::name();
00146 }
00147
00148 template<class S>
00149 void
00150 Print<S>::finalize(void) {
00151 TextOutput::finalize();
00152 }
00153
00154 forceinline
00155 Options::Options(void) {}
00156
00157 forceinline
00158 Options::_I::_I(void) : _click(heap,1), n_click(0),
00159 _solution(heap,1), n_solution(0),
00160 _move(heap,1), n_move(0), _compare(heap,1), n_compare(0) {}
00161
00162 forceinline void
00163 Options::_I::click(Inspector* i) {
00164 _click[static_cast<int>(n_click++)] = i;
00165 }
00166 forceinline void
00167 Options::_I::solution(Inspector* i) {
00168 _solution[static_cast<int>(n_solution++)] = i;
00169 }
00170 forceinline void
00171 Options::_I::move(Inspector* i) {
00172 _move[static_cast<int>(n_move++)] = i;
00173 }
00174 forceinline void
00175 Options::_I::compare(Comparator* c) {
00176 _compare[static_cast<int>(n_compare++)] = c;
00177 }
00178 forceinline Inspector*
00179 Options::_I::click(unsigned int i) const {
00180 return (i < n_click) ? _click[i] : NULL;
00181 }
00182 forceinline Inspector*
00183 Options::_I::solution(unsigned int i) const {
00184 return (i < n_solution) ? _solution[i] : NULL;
00185 }
00186 forceinline Inspector*
00187 Options::_I::move(unsigned int i) const {
00188 return (i < n_move) ? _move[i] : NULL;
00189 }
00190 forceinline Comparator*
00191 Options::_I::compare(unsigned int i) const {
00192 return (i < n_compare) ? _compare[i] : NULL;
00193 }
00194
00195 inline int
00196 dfs(Space* root, const Gist::Options& opt) {
00197 return explore(root, false, opt);
00198 }
00199
00200 inline int
00201 bab(Space* root, const Gist::Options& opt) {
00202 return Gist::explore(root, true, opt);
00203 }
00204
00205 }}
00206
00207