this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Maxim Shishmarev <maxim.shishmarev@monash.edu> 5 * 6 * Contributing authors: 7 * Kevin Leo <kevin.leo@monash.edu> 8 * Christian Schulte <schulte@gecode.org> 9 * 10 * Copyright: 11 * Kevin Leo, 2017 12 * Christian Schulte, 2017 13 * Maxim Shishmarev, 2017 14 * 15 * This file is part of Gecode, the generic constraint 16 * development environment: 17 * http://www.gecode.org 18 * 19 * Permission is hereby granted, free of charge, to any person obtaining 20 * a copy of this software and associated documentation files (the 21 * "Software"), to deal in the Software without restriction, including 22 * without limitation the rights to use, copy, modify, merge, publish, 23 * distribute, sublicense, and/or sell copies of the Software, and to 24 * permit persons to whom the Software is furnished to do so, subject to 25 * the following conditions: 26 * 27 * The above copyright notice and this permission notice shall be 28 * included in all copies or substantial portions of the Software. 29 * 30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 31 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 34 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 35 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 36 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 * 38 */ 39 40#include <gecode/search.hh> 41 42#ifdef GECODE_HAS_CPPROFILER 43 44#include <gecode/search/cpprofiler/message.hpp> 45#include <gecode/search/cpprofiler/connector.hpp> 46 47namespace Gecode { 48 49 CPProfilerSearchTracer::GetInfo::GetInfo(void) {} 50 51 CPProfilerSearchTracer::GetInfo::~GetInfo(void) {} 52 53 54 CPProfilerSearchTracer::CPProfilerSearchTracer(int eid, std::string name0, 55 unsigned int port, 56 const GetInfo* pgetinfo) : 57 connector(new CPProfiler::Connector(port)), execution_id(eid), name(name0), restart(0), 58 pgi(pgetinfo) { 59 } 60 61 void 62 CPProfilerSearchTracer::init(void) { 63 // Try to find out whether engine is a restart engine 64 bool restarts = ((engines() == 2U) && 65 (engine(0U).type() == EngineType::RBS)); 66 connector->connect(); 67 connector->start(name, execution_id, restarts); 68 } 69 70 void 71 CPProfilerSearchTracer::round(unsigned int) { 72 restart++; 73 connector->restart(restart); 74 } 75 76 void 77 CPProfilerSearchTracer::skip(const EdgeInfo& ei) { 78 CPProfiler::NodeUID dummy_node{-1, restart, -1}; 79 CPProfiler::NodeUID parent{-1,restart,-1}; 80 81 int alt = 0; 82 std::string label; 83 if (ei) { 84 parent.nid = static_cast<int>(ei.nid()); 85 parent.tid = static_cast<int>(ei.wid()); 86 dummy_node.tid = static_cast<int>(ei.wid()); 87 alt = static_cast<int>(ei.alternative()); 88 label = ei.string(); 89 } 90 91 auto node = connector->createNode(dummy_node, parent, 92 alt, 0, CPProfiler::NodeStatus::SKIPPED) 93 .set_label(label) 94 .set_info(""); 95 connector->sendNode(node); 96 } 97 98 void 99 CPProfilerSearchTracer::node(const EdgeInfo& ei, const NodeInfo& ni) { 100 CPProfiler::NodeUID this_node{static_cast<int>(ni.nid()), 101 restart, 102 static_cast<int>(ni.wid())}; 103 CPProfiler::NodeUID parent {-1,restart,-1}; 104 105 int alt = 0; 106 int alts = 0; 107 108 CPProfiler::NodeStatus ns = CPProfiler::NodeStatus::FAILED; 109 switch(ni.type()) { 110 case NodeType::SOLVED: 111 ns = CPProfiler::NodeStatus::SOLVED; 112 break; 113 case NodeType::BRANCH: 114 ns = CPProfiler::NodeStatus::BRANCH; 115 alts = static_cast<int>(ni.choice().alternatives()); 116 break; 117 case NodeType::FAILED: 118 ns = CPProfiler::NodeStatus::FAILED; 119 break; 120 default: 121 GECODE_NEVER; 122 } 123 124 std::string label; 125 if(ei) { 126 parent = {static_cast<int>(ei.nid()), 127 restart, 128 static_cast<int>(ei.wid())}; 129 130 alt = static_cast<int>(ei.alternative()); 131 label = ei.string(); 132 } else { 133 alt = restart; 134 } 135 136 std::string info; 137 if(pgi) { 138 info = pgi->getInfo(ni.space()); 139 } 140 141 auto node = connector->createNode(this_node, parent, alt, alts, ns) 142 .set_label(label) 143 .set_info(info); 144 connector->sendNode(node); 145 } 146 147 void 148 CPProfilerSearchTracer::done(void) { 149 connector->disconnect(); 150 } 151 152 CPProfilerSearchTracer::~CPProfilerSearchTracer(void) { 153 delete connector; 154 delete pgi; 155 } 156 157} 158 159#endif 160 161// STATISTICS: search-trace