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  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2017
8  *
9  * Last modified:
10  * $Date$ by $Author$
11  * $Revision$
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/search.hh>
39 
40 namespace Gecode {
41 
42  const char*
43  StdSearchTracer::t2s[SearchTracer::EngineType::AOE + 1] = {
44  "DFS", "BAB", "LDS",
45  "RBS", "PBS",
46  "AOE"
47  };
48 
50  : os(os0) {}
51 
52  void
54  os << "trace<Search>::init()" << std::endl;
55  for (unsigned int e=0U; e<engines(); e++) {
56  os << "\t" << e << ": "
57  << t2s[engine(e).type()];
58  if (engine(e).meta()) {
59  os << ", engines: {";
60  for (unsigned int i=engine(e).efst(); i<engine(e).elst(); i++) {
61  os << i; if (i+1 < engine(e).elst()) os << ",";
62  }
63  } else {
64  os << ", workers: {";
65  for (unsigned int i=engine(e).wfst(); i<engine(e).wlst(); i++) {
66  os << i; if (i+1 < engine(e).wlst()) os << ",";
67  }
68  }
69  os << "}" << std::endl;
70  }
71  }
72 
73  void
74  StdSearchTracer::round(unsigned int eid) {
75  os << "trace<Search>::round(e:" << eid << ")" << std::endl;
76  }
77 
78  void
80  os << "trace<Search>Search::skip(w:" << ei.wid()
81  << ",n:" << ei.nid()
82  << ",a:" << ei.alternative() << ")" << std::endl;
83  }
84 
85  void
86  StdSearchTracer::node(const EdgeInfo& ei, const NodeInfo& ni) {
87  os << "trace<Search>::node(";
88  switch (ni.type()) {
89  case NodeType::FAILED:
90  os << "FAILED";
91  break;
92  case NodeType::SOLVED:
93  os << "SOLVED";
94  break;
95  case NodeType::BRANCH:
96  os << "BRANCH(" << ni.choice().alternatives() << ")";
97  break;
98  }
99  if (!ei)
100  os << ",root";
101  os << ",w:" << ni.wid() << ',';
102  if (ei)
103  os << "p:" << ei.nid() << ',';
104  os << "n:" << ni.nid() << ')';
105  if (ei) {
106  if (ei.wid() != ni.wid())
107  os << " [stolen from w:" << ei.wid() << "]";
108  os << std::endl
109  << '\t' << ei.string()
110  << std::endl;
111  } else {
112  os << std::endl;
113  }
114  }
115 
116  void
118  os << "trace<Search>::done()" << std::endl;
119  }
120 
122 
124 
125 }
126 
127 // STATISTICS: search-trace
Edge information.
Definition: search.hh:244
unsigned int alternatives(void) const
Return number of alternatives.
Definition: core.hpp:3640
unsigned int elst(void) const
Return id of last engine.
Definition: tracer.hpp:90
unsigned int nid(void) const
Return node id.
Definition: tracer.hpp:185
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
const Choice & choice(void) const
Return corresponding choice.
Definition: tracer.hpp:195
unsigned int wid(void) const
Return parent worker id.
Definition: tracer.hpp:140
Node representing failure.
Definition: spacenode.hh:50
unsigned int wlst(void) const
Return id of last worker plus one.
Definition: tracer.hpp:72
unsigned int engines(void) const
Return number of engines.
Definition: tracer.hpp:275
virtual void skip(const EdgeInfo &ei)
The engine skips an edge.
Definition: tracer.cpp:79
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
Gecode::IntArgs i(4, 1, 2, 3, 4)
Node representing a solution.
Definition: spacenode.hh:49
virtual void node(const EdgeInfo &ei, const NodeInfo &ni)
The engine creates a new node with information ei and ni.
Definition: tracer.cpp:86
NodeType type(void) const
Return node type.
Definition: tracer.hpp:175
StdSearchTracer(std::ostream &os=std::cerr)
Initialize with output stream os.
Definition: tracer.cpp:49
virtual void init(void)
The search engine initializes.
Definition: tracer.cpp:53
unsigned int nid(void) const
Return parent node id.
Definition: tracer.hpp:146
virtual ~StdSearchTracer(void)
Delete.
Definition: tracer.cpp:121
virtual void done(void)
All workers are done.
Definition: tracer.cpp:117
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
std::ostream & os
Output stream to use.
Definition: search.hh:376
Node information.
Definition: search.hh:284
static const char * t2s[EngineType::AOE+1]
Map engine type to string.
Definition: search.hh:378
unsigned int wfst(void) const
Return id of first worker.
Definition: tracer.hpp:65
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:74
Gecode toplevel namespace
static StdSearchTracer def
Default tracer (printing to std::cerr)
Definition: search.hh:395