Generated on Sat Oct 20 2018 12:43:45 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  * 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 
47 namespace 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:
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
149  connector->disconnect();
150  }
151 
153  delete connector;
154  delete pgi;
155  }
156 
157 }
158 
159 #endif
160 
161 // STATISTICS: search-trace
Edge information.
Definition: search.hh:242
unsigned int alternatives(void) const
Return number of alternatives.
Definition: core.hpp:3697
unsigned int nid(void) const
Return node id.
Definition: tracer.hpp:181
virtual ~GetInfo(void)
Delete.
Definition: tracer.cpp:51
void disconnect(void)
disconnect from a socket
Definition: connector.hpp:379
Node & set_info(const std::string &info)
Definition: connector.hpp:175
Class to send solution information to CPProfiler.
Definition: search.hh:423
unsigned int eid(unsigned int wid) const
Return the engine id of a worker with id wid.
Definition: tracer.hpp:283
Node representing a branch.
Definition: spacenode.hh:47
EngineType type(void) const
Return engine type.
Definition: tracer.hpp:51
virtual void done(void)
All workers are done.
Definition: tracer.cpp:148
const Choice & choice(void) const
Return corresponding choice.
Definition: tracer.hpp:191
void connect(void)
connect to a socket via port specified in the construction (6565 by default)
Definition: connector.hpp:268
virtual void skip(const EdgeInfo &ei)
The engine skips an edge.
Definition: tracer.cpp:77
unsigned int wid(void) const
Return parent worker id.
Definition: tracer.hpp:136
Node representing failure.
Definition: spacenode.hh:46
unsigned int engines(void) const
Return number of engines.
Definition: tracer.hpp:271
Node skipped by backjumping.
Definition: message.hpp:55
std::string string(void) const
Return string for alternative.
Definition: tracer.hpp:154
const EngineInfo & engine(unsigned int eid) const
Provide access to engine with id eid.
Definition: tracer.hpp:276
virtual void node(const EdgeInfo &ei, const NodeInfo &ni)
The engine creates a new node with information ei and ni.
Definition: tracer.cpp:99
Node createNode(NodeUID node, NodeUID parent, int alt, int kids, NodeStatus status)
Definition: connector.hpp:402
Node representing a solution.
Definition: spacenode.hh:45
void start(const std::string &file_path="", int execution_id=-1, bool has_restarts=false)
Definition: connector.hpp:328
NodeType type(void) const
Return node type.
Definition: tracer.hpp:171
unsigned int nid(void) const
Return parent node id.
Definition: tracer.hpp:142
virtual ~CPProfilerSearchTracer(void)
Delete.
Definition: tracer.cpp:152
unsigned int alternative(void) const
Return number of alternative.
Definition: tracer.hpp:148
unsigned int wid(void) const
Return worker id.
Definition: tracer.hpp:176
virtual std::string getInfo(const Space &home) const =0
Return info for a space.
Node information.
Definition: search.hh:282
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 init(void)
The search engine initializes.
Definition: tracer.cpp:62
Gecode toplevel namespace
Node & set_label(const std::string &label)
Definition: connector.hpp:155
NodeStatus
Types of nodes for CP Profiler.
Definition: message.hpp:51
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
void restart(int restart_id=-1)
Definition: connector.hpp:357
void sendNode(const Node &node)
Definition: connector.hpp:388
Unique identifier for a node.
Definition: message.hpp:114
CPProfilerSearchTracer(int eid, std::string name, unsigned int port=Search::Config::cpprofiler_port, const GetInfo *pgi=nullptr)
Initialize.
Definition: tracer.cpp:54
const Space & space(void) const
Return corresponding space.
Definition: tracer.hpp:186