filter.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 namespace Gecode {
00035
00036 class TraceFilter;
00037
00042 class TFE {
00043 friend GECODE_KERNEL_EXPORT TFE operator -(const TFE& r);
00044 friend GECODE_KERNEL_EXPORT TFE propagator(PropagatorGroup g);
00045 friend GECODE_KERNEL_EXPORT TFE post(PropagatorGroup g);
00046 friend class TraceFilter;
00047 protected:
00049 enum NodeType {
00050 NT_GROUP,
00051 NT_NEGATE,
00052 NT_ADD
00053 };
00055 class Node : public HeapAllocated {
00056 public:
00058 unsigned int use;
00060 NodeType t;
00062 int n;
00064 Group g;
00066 char w;
00068 Node *l, *r;
00070 Node(void);
00072 GECODE_KERNEL_EXPORT
00073 bool decrement(void);
00074 };
00076 Node* n;
00078 TFE(void);
00080 TFE(Node* n);
00082 void init(Group g, char what);
00084 TFE negate(void) const;
00085 public:
00087 GECODE_KERNEL_EXPORT
00088 TFE(PropagatorGroup g);
00090 GECODE_KERNEL_EXPORT
00091 TFE(BrancherGroup g);
00093 GECODE_KERNEL_EXPORT
00094 static TFE other(void);
00096 GECODE_KERNEL_EXPORT
00097 TFE(const TFE& e);
00099 GECODE_KERNEL_EXPORT
00100 TFE& operator =(const TFE& e);
00102 GECODE_KERNEL_EXPORT
00103 TFE& operator +=(const TFE& e);
00105 GECODE_KERNEL_EXPORT
00106 TFE& operator -=(const TFE& e);
00108 GECODE_KERNEL_EXPORT
00109 ~TFE(void);
00110 };
00111
00113 TFE operator +(TFE l, const TFE& r);
00115 TFE operator +(const TFE& e);
00117 TFE operator -(TFE l, const TFE& r);
00119 GECODE_KERNEL_EXPORT
00120 TFE operator -(const TFE& e);
00122 GECODE_KERNEL_EXPORT
00123 TFE propagator(PropagatorGroup g);
00125 GECODE_KERNEL_EXPORT
00126 TFE post(PropagatorGroup g);
00127
00128
00133 class TraceFilter : public SharedHandle {
00134 protected:
00136 class TFO : public SharedHandle::Object {
00137 public:
00139 struct Filter {
00141 Group g;
00143 bool neg;
00145 char what;
00146 };
00147 class StackFrame {
00148 public:
00150 TFE::Node* n;
00152 bool neg;
00154 StackFrame(void);
00156 StackFrame(TFE::Node* n, bool neg);
00157 };
00159 int n;
00161 Filter* f;
00163 GECODE_KERNEL_EXPORT
00164 void fill(TFE::Node* n);
00166 TFO(void);
00168 TFO(const TFE& e);
00170 TFO(PropagatorGroup g);
00172 TFO(BrancherGroup g);
00174 bool operator ()(const ViewTraceInfo& vti) const;
00176 bool operator ()(PropagatorGroup pg) const;
00178 bool operator ()(BrancherGroup bg) const;
00180 GECODE_KERNEL_EXPORT
00181 virtual ~TFO(void);
00182 };
00183 public:
00185 GECODE_KERNEL_EXPORT
00186 TraceFilter(void);
00188 GECODE_KERNEL_EXPORT
00189 TraceFilter(const TFE& e);
00191 GECODE_KERNEL_EXPORT
00192 TraceFilter(PropagatorGroup g);
00194 GECODE_KERNEL_EXPORT
00195 TraceFilter(BrancherGroup g);
00197 GECODE_KERNEL_EXPORT
00198 TraceFilter(const TraceFilter& tf);
00200 GECODE_KERNEL_EXPORT
00201 TraceFilter& operator =(const TraceFilter& tf);
00203 bool operator ()(const ViewTraceInfo& vti) const;
00205 bool operator ()(PropagatorGroup pg) const;
00207 bool operator ()(BrancherGroup bg) const;
00209 GECODE_KERNEL_EXPORT
00210 static TraceFilter all;
00211 };
00212
00213
00214
00215
00216
00217
00218
00219
00220 forceinline
00221 TFE::Node::Node(void)
00222 : use(1), l(NULL), r(NULL) {}
00223 forceinline
00224 TFE::TFE(void) : n(NULL) {}
00225 forceinline
00226 TFE::TFE(TFE::Node* n0) : n(n0) {}
00227
00228 forceinline TFE
00229 operator +(TFE l, const TFE& r) {
00230 l += r; return l;
00231 }
00232 forceinline TFE
00233 operator +(const TFE& e) {
00234 return e;
00235 }
00236 forceinline TFE
00237 operator -(TFE l, const TFE& r) {
00238 l -= r; return l;
00239 }
00240
00241
00242
00243
00244
00245
00246 forceinline
00247 TraceFilter::TFO::TFO(void) : n(0), f(NULL) {}
00248 forceinline
00249 TraceFilter::TFO::TFO(const TFE& e)
00250 : n(e.n->n),
00251 f((n == 0) ? NULL : heap.alloc<Filter>(n)) {
00252 if (n > 0)
00253 fill(e.n);
00254 }
00255 forceinline
00256 TraceFilter::TFO::TFO(PropagatorGroup g) : n(1) {
00257 f = heap.alloc<Filter>(1);
00258 f[0].g = g; f[0].neg = false;
00259 f[0].what = 1 << ViewTraceInfo::PROPAGATOR;
00260
00261 }
00262 forceinline
00263 TraceFilter::TFO::TFO(BrancherGroup g) : n(1) {
00264 f = heap.alloc<Filter>(1);
00265 f[0].g = g; f[0].neg = false;
00266 f[0].what = 1 << ViewTraceInfo::BRANCHER;
00267
00268 }
00269 forceinline bool
00270 TraceFilter::TFO::operator ()(const ViewTraceInfo& vti) const {
00271 if (n == 0)
00272 return true;
00273 for (int i=0; i<n; i++)
00274 if (f[i].what & (1 << vti.what())) {
00275
00276 switch (vti.what()) {
00277 case ViewTraceInfo::PROPAGATOR:
00278 if (f[i].g.in(vti.propagator().group()) != f[i].neg)
00279 return true;
00280 break;
00281 case ViewTraceInfo::BRANCHER:
00282 if (f[i].g.in(vti.brancher().group()) != f[i].neg)
00283 return true;
00284 break;
00285 case ViewTraceInfo::POST:
00286 if (f[i].g.in(vti.post()) != f[i].neg)
00287 return true;
00288 break;
00289 case ViewTraceInfo::OTHER:
00290 return true;
00291 default:
00292 GECODE_NEVER;
00293 }
00294 }
00295 return false;
00296 }
00297
00298 forceinline bool
00299 TraceFilter::operator ()(const ViewTraceInfo& vti) const {
00300 return static_cast<TFO*>(object())->operator ()(vti);
00301 }
00302
00303 forceinline bool
00304 TraceFilter::TFO::operator ()(PropagatorGroup pg) const {
00305 if (n == 0)
00306 return true;
00307 for (int i=0; i<n; i++)
00308 if ((f[i].what & (1 << ViewTraceInfo::PROPAGATOR)) &&
00309 (f[i].g.in(pg) != f[i].neg))
00310 return true;
00311 return false;
00312 }
00313
00314 forceinline bool
00315 TraceFilter::operator ()(PropagatorGroup pg) const {
00316 return static_cast<TFO*>(object())->operator ()(pg);
00317 }
00318
00319 forceinline bool
00320 TraceFilter::TFO::operator ()(BrancherGroup bg) const {
00321 if (n == 0)
00322 return true;
00323 for (int i=0; i<n; i++)
00324 if ((f[i].what & (1 << ViewTraceInfo::BRANCHER)) &&
00325 (f[i].g.in(bg) != f[i].neg))
00326 return true;
00327 return false;
00328 }
00329
00330 forceinline bool
00331 TraceFilter::operator ()(BrancherGroup bg) const {
00332 return static_cast<TFO*>(object())->operator ()(bg);
00333 }
00334
00335 }
00336
00337