Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.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.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
46
47namespace Gecode {
48
50
52
53
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
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
72 restart++;
73 connector->restart(restart);
74 }
75
76 void
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,
93 .set_label(label)
94 .set_info("");
95 connector->sendNode(node);
96 }
97
98 void
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
109 switch(ni.type()) {
110 case NodeType::SOLVED:
112 break;
113 case NodeType::BRANCH:
115 alts = static_cast<int>(ni.choice().alternatives());
116 break;
117 case NodeType::FAILED:
119 break;
120 default:
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
149 connector->disconnect();
150 }
151
153 delete connector;
154 delete pgi;
155 }
156
157}
158
159#endif
160
161// STATISTICS: search-trace
Class to send solution information to CPProfiler.
Definition search.hh:423
virtual void node(const EdgeInfo &ei, const NodeInfo &ni)
The engine creates a new node with information ei and ni.
Definition tracer.cpp:99
virtual void init(void)
The search engine initializes.
Definition tracer.cpp:62
virtual void skip(const EdgeInfo &ei)
The engine skips an edge.
Definition tracer.cpp:77
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:71
virtual void done(void)
All workers are done.
Definition tracer.cpp:148
virtual ~CPProfilerSearchTracer(void)
Delete.
Definition tracer.cpp:152
CPProfilerSearchTracer(int eid, std::string name, unsigned int port=Search::Config::cpprofiler_port, const GetInfo *pgi=nullptr)
Initialize.
Definition tracer.cpp:54
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:278
@ BRANCH
A failed node.
Definition search.hh:279
@ RBS
Engine is a RBS engine.
Definition search.hh:197
unsigned int engines(void) const
Return number of engines.
Definition tracer.hpp:266
Code that is specific to the CPProfiler.
Definition search.hh:406
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