Generated on for Gecode by doxygen 1.15.0
tracer.cpp
Go to the documentation of this file.
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.dev>
9 * Stefan Brüns <stefan.bruens@rwth-aachen.de>
10 *
11 * Copyright:
12 * Kevin Leo, 2017
13 * Christian Schulte, 2017
14 * Maxim Shishmarev, 2017
15 * Stefan Brüns, 2022
16 *
17 * This file is part of Gecode, the generic constraint
18 * development environment:
19 * http://www.gecode.dev
20 *
21 * Permission is hereby granted, free of charge, to any person obtaining
22 * a copy of this software and associated documentation files (the
23 * "Software"), to deal in the Software without restriction, including
24 * without limitation the rights to use, copy, modify, merge, publish,
25 * distribute, sublicense, and/or sell copies of the Software, and to
26 * permit persons to whom the Software is furnished to do so, subject to
27 * the following conditions:
28 *
29 * The above copyright notice and this permission notice shall be
30 * included in all copies or substantial portions of the Software.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 *
40 */
41
42#include <gecode/search.hh>
43
44#ifdef GECODE_HAS_CPPROFILER
45
48
49namespace Gecode {
50
52
54
55
57 unsigned int port,
58 const GetInfo* pgetinfo) :
59 connector(new CPProfiler::Connector(port)), execution_id(eid), name(name0), restart(0),
60 pgi(pgetinfo) {
61 }
62
63 void
65 // Try to find out whether engine is a restart engine
66 bool restarts = ((engines() == 2U) &&
67 (engine(0U).type() == EngineType::RBS));
68 connector->connect();
69 connector->start(name, execution_id, restarts);
70 }
71
72 void
74 restart++;
75 connector->restart(restart);
76 }
77
78 void
80 CPProfiler::NodeUID dummy_node{-1, restart, -1};
81 CPProfiler::NodeUID parent{-1,restart,-1};
82
83 int alt = 0;
84 std::string label;
85 if (ei) {
86 parent.nid = static_cast<int>(ei.nid());
87 parent.tid = static_cast<int>(ei.wid());
88 dummy_node.tid = static_cast<int>(ei.wid());
89 alt = static_cast<int>(ei.alternative());
90 label = ei.string();
91 }
92
93 auto node = connector->createNode(dummy_node, parent,
95 .set_label(label)
96 .set_info("");
97 connector->sendNode(node);
98 }
99
100 void
102 CPProfiler::NodeUID this_node{static_cast<int>(ni.nid()),
103 restart,
104 static_cast<int>(ni.wid())};
105 CPProfiler::NodeUID parent {-1,restart,-1};
106
107 int alt = 0;
108 int alts = 0;
109
111 switch(ni.type()) {
112 case NodeType::SOLVED:
114 break;
115 case NodeType::BRANCH:
117 alts = static_cast<int>(ni.choice().alternatives());
118 break;
119 case NodeType::FAILED:
121 break;
122 default:
124 }
125
126 std::string label;
127 if(ei) {
128 parent = {static_cast<int>(ei.nid()),
129 restart,
130 static_cast<int>(ei.wid())};
131
132 alt = static_cast<int>(ei.alternative());
133 label = ei.string();
134 } else {
135 alt = restart;
136 }
137
138 std::string info;
139 if(pgi) {
140 info = pgi->getInfo(ni.space());
141 }
142
143 auto node = connector->createNode(this_node, parent, alt, alts, ns)
144 .set_label(label)
145 .set_info(info);
146 connector->sendNode(node);
147 }
148
149 void
151 connector->done();
152 connector->disconnect();
153 }
154
156 delete connector;
157 delete pgi;
158 }
159
160}
161
162#endif
163
164// STATISTICS: search-trace
Class to send solution information to CPProfiler.
Definition search.hh:427
virtual void node(const EdgeInfo &ei, const NodeInfo &ni)
The engine creates a new node with information ei and ni.
Definition tracer.cpp:101
virtual void init(void)
The search engine initializes.
Definition tracer.cpp:64
virtual void skip(const EdgeInfo &ei)
The engine skips an edge.
Definition tracer.cpp:79
virtual void round(unsigned int eid)
The engine with id eid goes to a next round (restart or next iteration in LDS).
Definition tracer.cpp:73
virtual void done(void)
All workers are done.
Definition tracer.cpp:150
virtual ~CPProfilerSearchTracer(void)
Delete.
Definition tracer.cpp:155
CPProfilerSearchTracer(int eid, std::string name, unsigned int port=Search::Config::cpprofiler_port, const GetInfo *pgi=nullptr)
Initialize.
Definition tracer.cpp:56
unsigned int alternative(void) const
Return number of alternative.
Definition tracer.hpp:148
unsigned int wid(void) const
Return parent worker id.
Definition tracer.hpp:136
std::string string(void) const
Return string for alternative.
Definition tracer.hpp:154
unsigned int nid(void) const
Return parent node id.
Definition tracer.hpp:142
NodeType type(void) const
Return node type.
Definition tracer.hpp:171
const Choice & choice(void) const
Return corresponding choice.
Definition tracer.hpp:191
unsigned int nid(void) const
Return node id.
Definition tracer.hpp:181
unsigned int wid(void) const
Return worker id.
Definition tracer.hpp:176
const Space & space(void) const
Return corresponding space.
Definition tracer.hpp:186
unsigned int eid(unsigned int wid) const
Return the engine id of a worker with id wid.
Definition tracer.hpp:278
@ FAILED
A solution node.
Definition search.hh:282
@ BRANCH
A failed node.
Definition search.hh:283
@ RBS
Engine is a RBS engine.
Definition search.hh:201
unsigned int engines(void) const
Return number of engines.
Definition tracer.hpp:266
Code that is specific to the CPProfiler.
Definition search.hh:410
NodeStatus
Types of nodes for CP Profiler.
Definition message.hpp:51
@ SOLVED
Node representing a solution.
Definition message.hpp:52
@ BRANCH
Node representing a branch.
Definition message.hpp:54
@ SKIPPED
Node skipped by backjumping.
Definition message.hpp:55
@ FAILED
Node representing failure.
Definition message.hpp:53
Gecode toplevel namespace
Unique identifier for a node.
Definition message.hpp:114
int32_t nid
Node number.
Definition message.hpp:116
int32_t tid
Thread id.
Definition message.hpp:120
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56