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