this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2017 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34#include <gecode/search.hh> 35 36namespace Gecode { 37 38 const char* 39 StdSearchTracer::t2s[SearchTracer::EngineType::AOE + 1] = { 40 "DFS", "BAB", "LDS", 41 "RBS", "PBS", 42 "AOE" 43 }; 44 45 StdSearchTracer::StdSearchTracer(std::ostream& os0) 46 : os(os0) {} 47 48 void 49 StdSearchTracer::init(void) { 50 os << "trace<Search>::init()" << std::endl; 51 for (unsigned int e=0U; e<engines(); e++) { 52 os << "\t" << e << ": " 53 << t2s[engine(e).type()]; 54 if (engine(e).meta()) { 55 os << ", engines: {"; 56 for (unsigned int i=engine(e).efst(); i<engine(e).elst(); i++) { 57 os << i; if (i+1 < engine(e).elst()) os << ","; 58 } 59 } else { 60 os << ", workers: {"; 61 for (unsigned int i=engine(e).wfst(); i<engine(e).wlst(); i++) { 62 os << i; if (i+1 < engine(e).wlst()) os << ","; 63 } 64 } 65 os << "}" << std::endl; 66 } 67 } 68 69 void 70 StdSearchTracer::round(unsigned int eid) { 71 os << "trace<Search>::round(e:" << eid << ")" << std::endl; 72 } 73 74 void 75 StdSearchTracer::skip(const EdgeInfo& ei) { 76 os << "trace<Search>Search::skip(w:" << ei.wid() 77 << ",n:" << ei.nid() 78 << ",a:" << ei.alternative() << ")" << std::endl; 79 } 80 81 void 82 StdSearchTracer::node(const EdgeInfo& ei, const NodeInfo& ni) { 83 os << "trace<Search>::node("; 84 switch (ni.type()) { 85 case NodeType::FAILED: 86 os << "FAILED"; 87 break; 88 case NodeType::SOLVED: 89 os << "SOLVED"; 90 break; 91 case NodeType::BRANCH: 92 os << "BRANCH(" << ni.choice().alternatives() << ")"; 93 break; 94 } 95 if (!ei) 96 os << ",root"; 97 os << ",w:" << ni.wid() << ','; 98 if (ei) 99 os << "p:" << ei.nid() << ','; 100 os << "n:" << ni.nid() << ')'; 101 if (ei) { 102 if (ei.wid() != ni.wid()) 103 os << " [stolen from w:" << ei.wid() << "]"; 104 os << std::endl 105 << '\t' << ei.string() 106 << std::endl; 107 } else { 108 os << std::endl; 109 } 110 } 111 112 void 113 StdSearchTracer::done(void) { 114 os << "trace<Search>::done()" << std::endl; 115 } 116 117 StdSearchTracer::~StdSearchTracer(void) {} 118 119 StdSearchTracer StdSearchTracer::def; 120 121} 122 123// STATISTICS: search-trace