Generated on Tue Apr 18 10:22:07 2017 for Gecode by doxygen 1.6.3

trace-filter.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2016
00008  *
00009  *  Last modified:
00010  *     $Date: 2017-03-17 23:04:57 +0100 (Fri, 17 Mar 2017) $ by $Author: schulte $
00011  *     $Revision: 15597 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <gecode/kernel.hh>
00039 
00040 namespace Gecode {
00041 
00042   /*
00043    * Trace filter expressions
00044    *
00045    */
00046   bool
00047   TFE::Node::decrement(void) {
00048     if (--use == 0) {
00049       if ((l != NULL) && l->decrement())
00050         delete l;
00051       if ((r != NULL) && r->decrement())
00052         delete r;
00053       return true;
00054     }
00055     return false;
00056   }
00057 
00058 
00059   forceinline void
00060   TFE::init(Group g, char what) {
00061     n = new Node;
00062     n->t = NT_GROUP;
00063     n->g = g;
00064     n->n = 1;
00065     n->w = what;
00066   }
00067 
00068   inline TFE
00069   TFE::negate(void) const {
00070     Node* m = new Node;
00071     m->t = NT_NEGATE;
00072     m->n = n->n;
00073     m->l = n; n->use++;
00074     return TFE(m);
00075   }
00076 
00077   TFE::TFE(PropagatorGroup g) {
00078     init(g,(1 << ViewTraceInfo::PROPAGATOR) | (1 << ViewTraceInfo::POST));
00079   }
00080 
00081   TFE::TFE(BrancherGroup g) {
00082     init(g,(1 << ViewTraceInfo::BRANCHER));
00083   }
00084 
00085   TFE
00086   TFE::other(void) {
00087     TFE e;
00088     e.init(Group::all,(1 << ViewTraceInfo::OTHER));
00089     return e;
00090   }
00091 
00092   TFE::TFE(const TFE& e) : n(e.n) {
00093     n->use++;
00094   }
00095 
00096   TFE&
00097   TFE::operator =(const TFE& e) {
00098     if (&e != this) {
00099       if (n->decrement())
00100         delete n;
00101       n = e.n;
00102       n->use++;
00103     }
00104     return *this;
00105   }
00106 
00107   TFE&
00108   TFE::operator +=(const TFE& e) {
00109     Node* a = new Node;
00110     a->t = NT_ADD;
00111     a->n = n->n + e.n->n;
00112     a->l = n;
00113     a->r = e.n; e.n->use++;
00114     n = a;
00115     return *this;
00116   }
00117 
00118   TFE&
00119   TFE::operator -=(const TFE& e) {
00120     return operator +=(e.negate());
00121   }
00122 
00123   TFE::~TFE(void) {
00124     if (n->decrement())
00125       delete n;
00126   }
00127 
00128 
00129   TFE
00130   operator -(const TFE& e) {
00131     return e.negate();
00132   }
00133 
00134   TFE
00135   propagator(PropagatorGroup g) {
00136     TFE e;
00137     e.init(g,(1 << ViewTraceInfo::PROPAGATOR));
00138     return e;
00139   }
00140 
00141   TFE
00142   post(PropagatorGroup g) {
00143     TFE e;
00144     e.init(g,(1 << ViewTraceInfo::POST));
00145     return e;
00146   }
00147 
00148 
00149 
00150   /*
00151    * Trace filters
00152    *
00153    */
00154 
00155 
00156   forceinline
00157   TraceFilter::TFO::StackFrame::StackFrame(void) {}
00158   forceinline
00159   TraceFilter::TFO::StackFrame::StackFrame(TFE::Node* n0, bool neg0)
00160     : n(n0), neg(neg0) {}
00161 
00162   void
00163   TraceFilter::TFO::fill(TFE::Node* n) {
00164     Support::DynamicStack<StackFrame,Heap> next(heap);
00165     int i=0;
00166     next.push(StackFrame(n,false));
00167     do {
00168       StackFrame s = next.pop();
00169       switch (s.n->t) {
00170       case TFE::NT_GROUP:
00171         f[i].g = s.n->g; f[i].neg = s.neg; f[i].what=s.n->w;
00172         i++;
00173         break;
00174       case TFE::NT_NEGATE:
00175         next.push(StackFrame(s.n->l,!s.neg));
00176         break;
00177       case TFE::NT_ADD:
00178         next.push(StackFrame(s.n->l,s.neg));
00179         next.push(StackFrame(s.n->r,s.neg));
00180         break;
00181       default: GECODE_NEVER;
00182       }
00183     } while (!next.empty());
00184   }
00185 
00186   SharedHandle::Object*
00187   TraceFilter::TFO::copy(void) const {
00188     return new TFO(*this);
00189   }
00190   TraceFilter::TFO::~TFO(void) {
00191     heap.free<Filter>(f,n);
00192   }
00193 
00194   TraceFilter::TraceFilter(void) : SharedHandle(new TFO) {}
00195 
00196   TraceFilter::TraceFilter(const TFE& e) : SharedHandle(new TFO(e)) {}
00197 
00198   TraceFilter::TraceFilter(PropagatorGroup g) : SharedHandle(new TFO(g)) {}
00199 
00200   TraceFilter::TraceFilter(BrancherGroup g) : SharedHandle(new TFO(g)) {}
00201 
00202   TraceFilter::TraceFilter(const TraceFilter& tf) : SharedHandle(tf) {}
00203 
00204   TraceFilter&
00205   TraceFilter::operator =(const TraceFilter& tf) {
00206     return static_cast<TraceFilter&>(SharedHandle::operator =(tf));
00207   }
00208 
00209   TraceFilter TraceFilter::all;
00210 
00211 }
00212 
00213 // STATISTICS: kernel-trace