main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
gecode
search
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
45
StdSearchTracer::StdSearchTracer
(std::ostream& os0)
46
: os(os0) {}
47
48
void
49
StdSearchTracer::init
(
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
75
StdSearchTracer::skip
(
const
EdgeInfo
& ei) {
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
113
StdSearchTracer::done
(
void
) {
114
os
<<
"trace<Search>::done()"
<< std::endl;
115
}
116
117
StdSearchTracer::~StdSearchTracer
(
void
) {}
118
119
StdSearchTracer
StdSearchTracer::def
;
120
121
}
122
123
// STATISTICS: search-trace
Gecode::SearchTracer::EngineInfo::wlst
unsigned int wlst(void) const
Return id of last worker plus one.
Definition:
tracer.hpp:68
Gecode::Choice::alternatives
unsigned int alternatives(void) const
Return number of alternatives.
Definition:
core.hpp:3770
Gecode::StdSearchTracer::def
static StdSearchTracer def
Default tracer (printing to std::cerr)
Definition:
search.hh:393
Gecode::StdSearchTracer::node
virtual void node(const EdgeInfo &ei, const NodeInfo &ni)
The engine creates a new node with information ei and ni.
Definition:
tracer.cpp:82
Gecode::SearchTracer::NodeInfo::type
NodeType type(void) const
Return node type.
Definition:
tracer.hpp:171
Gecode::SearchTracer::EdgeInfo::nid
unsigned int nid(void) const
Return parent node id.
Definition:
tracer.hpp:142
search.hh
Gecode::StdSearchTracer::init
virtual void init(void)
The search engine initializes.
Definition:
tracer.cpp:49
Gecode::StdSearchTracer::skip
virtual void skip(const EdgeInfo &ei)
The engine skips an edge.
Definition:
tracer.cpp:75
Gecode::SearchTracer::EngineInfo::type
EngineType type(void) const
Return engine type.
Definition:
tracer.hpp:51
Gecode::SearchTracer::EdgeInfo::alternative
unsigned int alternative(void) const
Return number of alternative.
Definition:
tracer.hpp:148
Gecode::SearchTracer::NodeInfo::wid
unsigned int wid(void) const
Return worker id.
Definition:
tracer.hpp:176
Gecode
Gecode toplevel namespace
Gecode::StdSearchTracer::~StdSearchTracer
virtual ~StdSearchTracer(void)
Delete.
Definition:
tracer.cpp:117
Gecode::SearchTracer::NodeInfo::choice
const Choice & choice(void) const
Return corresponding choice.
Definition:
tracer.hpp:191
Gecode::SearchTracer::NodeInfo
Node information.
Definition:
search.hh:282
Gecode::StdSearchTracer::StdSearchTracer
StdSearchTracer(std::ostream &os=std::cerr)
Initialize with output stream os.
Definition:
tracer.cpp:45
Gecode::StdSearchTracer
Definition:
search.hh:371
Gecode::StdSearchTracer::round
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
Gecode::SearchTracer::EdgeInfo::string
std::string string(void) const
Return string for alternative.
Definition:
tracer.hpp:154
Gecode::SearchTracer::EdgeInfo::wid
unsigned int wid(void) const
Return parent worker id.
Definition:
tracer.hpp:136
Gecode::Gist::BRANCH
@ BRANCH
Node representing a branch.
Definition:
spacenode.hh:47
Gecode::StdSearchTracer::done
virtual void done(void)
All workers are done.
Definition:
tracer.cpp:113
Gecode::SearchTracer::EdgeInfo
Edge information.
Definition:
search.hh:242
Gecode::SearchTracer::eid
unsigned int eid(unsigned int wid) const
Return the engine id of a worker with id wid.
Definition:
tracer.hpp:278
Gecode::SearchTracer::NodeInfo::nid
unsigned int nid(void) const
Return node id.
Definition:
tracer.hpp:181
Gecode::StdSearchTracer::os
std::ostream & os
Output stream to use.
Definition:
search.hh:374
Gecode::SearchTracer::EngineInfo::elst
unsigned int elst(void) const
Return id of last engine.
Definition:
tracer.hpp:86
Gecode::Gist::FAILED
@ FAILED
Node representing failure.
Definition:
spacenode.hh:46
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::SearchTracer::engine
const EngineInfo & engine(unsigned int eid) const
Provide access to engine with id eid.
Definition:
tracer.hpp:271
Gecode::SearchTracer::engines
unsigned int engines(void) const
Return number of engines.
Definition:
tracer.hpp:266
Gecode::StdSearchTracer::t2s
static const char * t2s[EngineType::AOE+1]
Map engine type to string.
Definition:
search.hh:376
Gecode::Gist::SOLVED
@ SOLVED
Node representing a solution.
Definition:
spacenode.hh:45
Gecode::SearchTracer::EngineInfo::wfst
unsigned int wfst(void) const
Return id of first worker.
Definition:
tracer.hpp:61