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 #ifdef GECODE_HAS_FLOAT_VARS
00105 inline std::string
00106 Comparator::compare(std::string x_n, FloatVar x, FloatVar y) {
00107 if (! (x.min() == y.min() && x.max() == y.max()) ) {
00108 std::ostringstream ret;
00109 ret << x_n << "=" << x << " -> " << y;
00110 return ret.str();
00111 }
00112 return "";
00113 }
00114 #endif
00115 template<class Var>
00116 std::string
00117 Comparator::compare(std::string x_n, const VarArgArray<Var>& x,
00118 const VarArgArray<Var>& y) {
00119 if (x.size() != y.size())
00120 return "Error: array size mismatch";
00121 std::ostringstream ret;
00122 bool first = true;
00123 for (int i=0; i<x.size(); i++) {
00124 std::ostringstream xni;
00125 xni << x_n << "[" << i << "]";
00126 std::string cmp = compare(xni.str(),x[i],y[i]);
00127 if (cmp != "") {
00128 if (!first) {
00129 ret << ", ";
00130 } else {
00131 first = false;
00132 }
00133 ret << cmp;
00134 }
00135 }
00136 return ret.str();
00137 }
00138
00139 template<class S>
00140 Print<S>::Print(const std::string& name)
00141 : TextOutput(name) {}
00142
00143 template<class S>
00144 void
00145 Print<S>::inspect(const Space& node) {
00146 init();
00147 addHtml("<pre>\n");
00148 dynamic_cast<const S&>(node).print(getStream());
00149 flush();
00150 addHtml("</pre><hr />");
00151 }
00152
00153 template<class S>
00154 std::string
00155 Print<S>::name(void) {
00156 return TextOutput::name();
00157 }
00158
00159 template<class S>
00160 void
00161 Print<S>::finalize(void) {
00162 TextOutput::finalize();
00163 }
00164
00165 forceinline
00166 Options::Options(void) {}
00167
00168 forceinline
00169 Options::_I::_I(void) : _click(heap,1), n_click(0),
00170 _solution(heap,1), n_solution(0),
00171 _move(heap,1), n_move(0), _compare(heap,1), n_compare(0) {}
00172
00173 forceinline void
00174 Options::_I::click(Inspector* i) {
00175 _click[static_cast<int>(n_click++)] = i;
00176 }
00177 forceinline void
00178 Options::_I::solution(Inspector* i) {
00179 _solution[static_cast<int>(n_solution++)] = i;
00180 }
00181 forceinline void
00182 Options::_I::move(Inspector* i) {
00183 _move[static_cast<int>(n_move++)] = i;
00184 }
00185 forceinline void
00186 Options::_I::compare(Comparator* c) {
00187 _compare[static_cast<int>(n_compare++)] = c;
00188 }
00189 forceinline Inspector*
00190 Options::_I::click(unsigned int i) const {
00191 return (i < n_click) ? _click[i] : NULL;
00192 }
00193 forceinline Inspector*
00194 Options::_I::solution(unsigned int i) const {
00195 return (i < n_solution) ? _solution[i] : NULL;
00196 }
00197 forceinline Inspector*
00198 Options::_I::move(unsigned int i) const {
00199 return (i < n_move) ? _move[i] : NULL;
00200 }
00201 forceinline Comparator*
00202 Options::_I::compare(unsigned int i) const {
00203 return (i < n_compare) ? _compare[i] : NULL;
00204 }
00205
00206 inline int
00207 dfs(Space* root, const Gist::Options& opt) {
00208 return explore(root, false, opt);
00209 }
00210
00211 inline int
00212 bab(Space* root, const Gist::Options& opt) {
00213 return Gist::explore(root, true, opt);
00214 }
00215
00216 }}
00217
00218