tracer.cpp
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
00035
00036
00037
00038
00039
00040 #include <gecode/search.hh>
00041
00042 #ifdef GECODE_HAS_CPPROFILER
00043
00044 #include <gecode/search/cpprofiler/message.hpp>
00045 #include <gecode/search/cpprofiler/connector.hpp>
00046
00047 namespace Gecode {
00048
00049 CPProfilerSearchTracer::GetInfo::GetInfo(void) {}
00050
00051 CPProfilerSearchTracer::GetInfo::~GetInfo(void) {}
00052
00053
00054 CPProfilerSearchTracer::CPProfilerSearchTracer(int eid, std::string name0,
00055 unsigned int port,
00056 const GetInfo* pgetinfo) :
00057 connector(new CPProfiler::Connector(port)), execution_id(eid), name(name0), restart(0),
00058 pgi(pgetinfo) {
00059 }
00060
00061 void
00062 CPProfilerSearchTracer::init(void) {
00063
00064 bool restarts = ((engines() == 2U) &&
00065 (engine(0U).type() == EngineType::RBS));
00066 connector->connect();
00067 connector->start(name, execution_id, restarts);
00068 }
00069
00070 void
00071 CPProfilerSearchTracer::round(unsigned int) {
00072 restart++;
00073 connector->restart(restart);
00074 }
00075
00076 void
00077 CPProfilerSearchTracer::skip(const EdgeInfo& ei) {
00078 CPProfiler::NodeUID dummy_node{-1, restart, -1};
00079 CPProfiler::NodeUID parent{-1,restart,-1};
00080
00081 int alt = 0;
00082 std::string label;
00083 if (ei) {
00084 parent.nid = static_cast<int>(ei.nid());
00085 parent.tid = static_cast<int>(ei.wid());
00086 dummy_node.tid = static_cast<int>(ei.wid());
00087 alt = static_cast<int>(ei.alternative());
00088 label = ei.string();
00089 }
00090
00091 auto node = connector->createNode(dummy_node, parent,
00092 alt, 0, CPProfiler::NodeStatus::SKIPPED)
00093 .set_label(label)
00094 .set_info("");
00095 connector->sendNode(node);
00096 }
00097
00098 void
00099 CPProfilerSearchTracer::node(const EdgeInfo& ei, const NodeInfo& ni) {
00100 CPProfiler::NodeUID this_node{static_cast<int>(ni.nid()),
00101 restart,
00102 static_cast<int>(ni.wid())};
00103 CPProfiler::NodeUID parent {-1,restart,-1};
00104
00105 int alt = 0;
00106 int alts = 0;
00107
00108 CPProfiler::NodeStatus ns = CPProfiler::NodeStatus::FAILED;
00109 switch(ni.type()) {
00110 case NodeType::SOLVED:
00111 ns = CPProfiler::NodeStatus::SOLVED;
00112 break;
00113 case NodeType::BRANCH:
00114 ns = CPProfiler::NodeStatus::BRANCH;
00115 alts = static_cast<int>(ni.choice().alternatives());
00116 break;
00117 case NodeType::FAILED:
00118 ns = CPProfiler::NodeStatus::FAILED;
00119 break;
00120 default:
00121 GECODE_NEVER;
00122 }
00123
00124 std::string label;
00125 if(ei) {
00126 parent = {static_cast<int>(ei.nid()),
00127 restart,
00128 static_cast<int>(ei.wid())};
00129
00130 alt = static_cast<int>(ei.alternative());
00131 label = ei.string();
00132 } else {
00133 alt = restart;
00134 }
00135
00136 std::string info;
00137 if(pgi) {
00138 info = pgi->getInfo(ni.space());
00139 }
00140
00141 auto node = connector->createNode(this_node, parent, alt, alts, ns)
00142 .set_label(label)
00143 .set_info(info);
00144 connector->sendNode(node);
00145 }
00146
00147 void
00148 CPProfilerSearchTracer::done(void) {
00149 connector->disconnect();
00150 }
00151
00152 CPProfilerSearchTracer::~CPProfilerSearchTracer(void) {
00153 delete connector;
00154 delete pgi;
00155 }
00156
00157 }
00158
00159 #endif
00160
00161