Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
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  * Last modified:
16  * $Date$ by $Author$
17  * $Revision$
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 #include <gecode/search.hh>
45 
46 #ifdef GECODE_HAS_CPPROFILER
47 
50 
51 namespace Gecode {
52 
54 
56 
57 
59  unsigned int port,
60  const GetInfo* pgetinfo) :
61  connector(new CPProfiler::Connector(port)), execution_id(eid), name(name0), restart(0),
62  pgi(pgetinfo) {
63  }
64 
65  void
67  // Try to find out whether engine is a restart engine
68  bool restarts = ((engines() == 2U) &&
69  (engine(0U).type() == EngineType::RBS));
70  connector->connect();
71  connector->start(name, execution_id, restarts);
72  }
73 
74  void
76  restart++;
77  connector->restart(restart);
78  }
79 
80  void
82  CPProfiler::NodeUID dummy_node{-1, restart, -1};
83  CPProfiler::NodeUID parent{-1,restart,-1};
84 
85  int alt = 0;
86  std::string label;
87  if (ei) {
88  parent.nid = static_cast<int>(ei.nid());
89  parent.tid = static_cast<int>(ei.wid());
90  dummy_node.tid = static_cast<int>(ei.wid());
91  alt = static_cast<int>(ei.alternative());
92  label = ei.string();
93  }
94 
95  auto node = connector->createNode(dummy_node, parent,
97  .set_label(label)
98  .set_info("");
99  connector->sendNode(node);
100  }
101 
102  void
104  CPProfiler::NodeUID this_node{static_cast<int>(ni.nid()),
105  restart,
106  static_cast<int>(ni.wid())};
107  CPProfiler::NodeUID parent {-1,restart,-1};
108 
109  int alt = 0;
110  int alts = 0;
111 
113  switch(ni.type()) {
114  case NodeType::SOLVED:
116  break;
117  case NodeType::BRANCH:
119  alts = static_cast<int>(ni.choice().alternatives());
120  break;
121  case NodeType::FAILED:
123  break;
124  default:
125  GECODE_NEVER;
126  }
127 
128  std::string label;
129  if(ei) {
130  parent = {static_cast<int>(ei.nid()),
131  restart,
132  static_cast<int>(ei.wid())};
133 
134  alt = static_cast<int>(ei.alternative());
135  label = ei.string();
136  } else {
137  alt = restart;
138  }
139 
140  std::string info;
141  if(pgi) {
142  info = pgi->getInfo(ni.space());
143  }
144 
145  auto node = connector->createNode(this_node, parent, alt, alts, ns)
146  .set_label(label)
147  .set_info(info);
148  connector->sendNode(node);
149  }
150 
151  void
153  connector->disconnect();
154  }
155 
157  delete connector;
158  delete pgi;
159  }
160 
161 }
162 
163 #endif
164 
165 // STATISTICS: search-trace
Edge information.
Definition: search.hh:244
unsigned int alternatives(void) const
Return number of alternatives.
Definition: core.hpp:3640
unsigned int nid(void) const
Return node id.
Definition: tracer.hpp:185
virtual ~GetInfo(void)
Delete.
Definition: tracer.cpp:55
void disconnect(void)
disconnect from a socket
Definition: connector.hpp:383
Node & set_info(const std::string &info)
Definition: connector.hpp:179
Class to send solution information to CPProfiler.
Definition: search.hh:425
unsigned int eid(unsigned int wid) const
Return the engine id of a worker with id wid.
Definition: tracer.hpp:287
Node representing a branch.
Definition: spacenode.hh:51
EngineType type(void) const
Return engine type.
Definition: tracer.hpp:55
virtual void done(void)
All workers are done.
Definition: tracer.cpp:152
const Choice & choice(void) const
Return corresponding choice.
Definition: tracer.hpp:195
void connect(void)
connect to a socket via port specified in the construction (6565 by default)
Definition: connector.hpp:272
virtual void skip(const EdgeInfo &ei)
The engine skips an edge.
Definition: tracer.cpp:81
unsigned int wid(void) const
Return parent worker id.
Definition: tracer.hpp:140
Node representing failure.
Definition: spacenode.hh:50
unsigned int engines(void) const
Return number of engines.
Definition: tracer.hpp:275
Node skipped by backjumping.
Definition: message.hpp:59
std::string string(void) const
Return string for alternative.
Definition: tracer.hpp:158
const EngineInfo & engine(unsigned int eid) const
Provide access to engine with id eid.
Definition: tracer.hpp:280
virtual void node(const EdgeInfo &ei, const NodeInfo &ni)
The engine creates a new node with information ei and ni.
Definition: tracer.cpp:103
Node createNode(NodeUID node, NodeUID parent, int alt, int kids, NodeStatus status)
Definition: connector.hpp:406
Node representing a solution.
Definition: spacenode.hh:49
void start(const std::string &file_path="", int execution_id=-1, bool has_restarts=false)
Definition: connector.hpp:332
NodeType type(void) const
Return node type.
Definition: tracer.hpp:175
unsigned int nid(void) const
Return parent node id.
Definition: tracer.hpp:146
virtual ~CPProfilerSearchTracer(void)
Delete.
Definition: tracer.cpp:156
unsigned int alternative(void) const
Return number of alternative.
Definition: tracer.hpp:152
unsigned int wid(void) const
Return worker id.
Definition: tracer.hpp:180
virtual std::string getInfo(const Space &home) const =0
Return info for a space.
Node information.
Definition: search.hh:284
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:75
virtual void init(void)
The search engine initializes.
Definition: tracer.cpp:66
Gecode toplevel namespace
Node & set_label(const std::string &label)
Definition: connector.hpp:159
NodeStatus
Types of nodes for CP Profiler.
Definition: message.hpp:55
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
void restart(int restart_id=-1)
Definition: connector.hpp:361
void sendNode(const Node &node)
Definition: connector.hpp:392
Unique identifier for a node.
Definition: message.hpp:118
CPProfilerSearchTracer(int eid, std::string name, unsigned int port=Search::Config::cpprofiler_port, const GetInfo *pgi=nullptr)
Initialize.
Definition: tracer.cpp:58
const Space & space(void) const
Return corresponding space.
Definition: tracer.hpp:190