Generated on Thu Apr 11 13:59:00 2019 for Gecode by doxygen 1.6.3

tracer.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, 2017
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <gecode/search.hh>
00035 
00036 namespace Gecode {
00037 
00038   const char*
00039   StdSearchTracer::t2s[SearchTracer::EngineType::AOE + 1] = {
00040     "DFS", "BAB", "LDS",
00041     "RBS", "PBS",
00042     "AOE"
00043   };
00044 
00045   StdSearchTracer::StdSearchTracer(std::ostream& os0)
00046     : os(os0) {}
00047 
00048   void
00049   StdSearchTracer::init(void) {
00050     os << "trace<Search>::init()" << std::endl;
00051       for (unsigned int e=0U; e<engines(); e++) {
00052         os << "\t" << e << ": " 
00053            << t2s[engine(e).type()];
00054         if (engine(e).meta()) {
00055           os << ", engines: {";
00056           for (unsigned int i=engine(e).efst(); i<engine(e).elst(); i++) {
00057             os << i; if (i+1 < engine(e).elst()) os << ",";
00058           }
00059         } else {
00060           os << ", workers: {";
00061           for (unsigned int i=engine(e).wfst(); i<engine(e).wlst(); i++) {
00062             os << i; if (i+1 < engine(e).wlst()) os << ",";
00063           }
00064         }
00065         os << "}" << std::endl;
00066       }
00067     }
00068 
00069   void
00070   StdSearchTracer::round(unsigned int eid) {
00071     os << "trace<Search>::round(e:" << eid << ")" << std::endl;
00072   }
00073 
00074   void
00075   StdSearchTracer::skip(const EdgeInfo& ei) {
00076     os << "trace<Search>Search::skip(w:" << ei.wid()
00077        << ",n:" << ei.nid()
00078        << ",a:" << ei.alternative() << ")" << std::endl;
00079   }
00080 
00081   void 
00082   StdSearchTracer::node(const EdgeInfo& ei, const NodeInfo& ni) {
00083     os << "trace<Search>::node(";
00084     switch (ni.type()) {
00085     case NodeType::FAILED:
00086       os << "FAILED";
00087       break;
00088     case NodeType::SOLVED:
00089       os << "SOLVED";
00090       break;
00091     case NodeType::BRANCH:
00092       os << "BRANCH(" << ni.choice().alternatives() << ")";
00093       break;
00094     }
00095     if (!ei)
00096       os << ",root";
00097     os << ",w:" << ni.wid() << ',';
00098     if (ei)
00099       os << "p:" << ei.nid() << ',';
00100     os << "n:" << ni.nid() << ')';
00101     if (ei) {
00102       if (ei.wid() != ni.wid())
00103         os << " [stolen from w:" << ei.wid() << "]";
00104       os << std::endl
00105          << '\t' << ei.string()
00106          << std::endl;
00107     } else {
00108       os << std::endl;
00109     }
00110   }
00111   
00112   void
00113   StdSearchTracer::done(void) {
00114     os << "trace<Search>::done()" << std::endl;
00115   }
00116 
00117   StdSearchTracer::~StdSearchTracer(void) {}
00118 
00119   StdSearchTracer StdSearchTracer::def;
00120 
00121 }
00122 
00123 // STATISTICS: search-trace