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 * 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
36namespace Gecode {
37
38 const char*
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
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()) {
86 os << "FAILED";
87 break;
89 os << "SOLVED";
90 break;
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:3777
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
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
@ AOE
Unspecified engine (any other engine)
Definition search.hh:199
unsigned int engines(void) const
Return number of engines.
Definition tracer.hpp:266
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
Gecode toplevel namespace