main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
int
trace
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, 2016
8
*
9
* Last modified:
10
* $Date: 2017-03-17 23:04:57 +0100 (Fri, 17 Mar 2017) $ by $Author: schulte $
11
* $Revision: 15597 $
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 <iomanip>
39
#include <
gecode/int.hh
>
40
41
namespace
Gecode
{
42
43
StdIntTracer::StdIntTracer
(std::ostream& os0)
44
: os(os0) {}
45
46
void
47
StdIntTracer::init
(
const
Space
&,
const
IntTraceRecorder
&
t
) {
48
os
<<
"trace<Int>::init(id:"
<<
t
.id();
49
if
(
t
.group().in())
50
os
<<
",g:"
;
t
.group().id();
51
os
<<
") slack: 100.00% ("
<<
t
.slack().initial() <<
" values)"
52
<< std::endl;
53
}
54
55
void
56
StdIntTracer::prune
(
const
Space
&,
const
IntTraceRecorder
&
t
,
57
const
ViewTraceInfo
& vti,
int
i
,
IntTraceDelta
&
d
) {
58
os
<<
"trace<Int>::prune(id:"
<<
t
.id();
59
if
(
t
.group().in())
60
os
<<
",g:"
;
t
.group().id();
61
os
<<
"): ["
<<
i
<<
"] = "
<<
t
[
i
] <<
" - {"
;
62
os
<<
d
.
min
();
63
if
(
d
.
width
() > 1)
64
os
<<
".."
<<
d
.
max
();
65
++
d
;
66
while
(
d
()) {
67
os
<<
','
<<
d
.
min
();
68
if
(
d
.
width
() > 1)
69
os
<<
".."
<<
d
.
max
();
70
++
d
;
71
}
72
os
<<
"} by "
<< vti << std::endl;
73
}
74
75
void
76
StdIntTracer::fix
(
const
Space
&,
const
IntTraceRecorder
&
t
) {
77
os
<<
"trace<Int>::fix(id:"
<<
t
.id();
78
if
(
t
.group().in())
79
os
<<
",g:"
;
t
.group().id();
80
os
<<
") slack: "
;
81
double
sl_i =
static_cast<
double
>
(
t
.slack().initial());
82
double
sl_p =
static_cast<
double
>
(
t
.slack().previous());
83
double
sl_c =
static_cast<
double
>
(
t
.slack().current());
84
double
p_c = 100.0 * (sl_c / sl_i);
85
double
p_d = 100.0 * (sl_p / sl_i) - p_c;
86
os
<< std::showpoint << std::setprecision(4)
87
<< p_c <<
"% - "
88
<< std::showpoint << std::setprecision(4)
89
<< p_d <<
'%'
90
<< std::endl;
91
}
92
93
void
94
StdIntTracer::fail
(
const
Space
&,
const
IntTraceRecorder
&
t
) {
95
os
<<
"trace<Int>::fail(id:"
<<
t
.id();
96
if
(
t
.group().in())
97
os
<<
",g:"
;
t
.group().id();
98
os
<<
") slack: "
;
99
double
sl_i =
static_cast<
double
>
(
t
.slack().initial());
100
double
sl_p =
static_cast<
double
>
(
t
.slack().previous());
101
double
sl_c =
static_cast<
double
>
(
t
.slack().current());
102
double
p_c = 100.0 * (sl_c / sl_i);
103
double
p_d = 100.0 * (sl_p / sl_i) - p_c;
104
os
<< std::showpoint << std::setprecision(4)
105
<< p_c <<
"% - "
106
<< std::showpoint << std::setprecision(4)
107
<< p_d <<
'%'
108
<< std::endl;
109
}
110
111
void
112
StdIntTracer::done
(
const
Space
&,
const
IntTraceRecorder
&
t
) {
113
os
<<
"trace<Int>::done(id:"
<<
t
.id();
114
if
(
t
.group().in())
115
os
<<
",g:"
;
t
.group().id();
116
os
<<
") slack: 0%"
<< std::endl;
117
}
118
119
StdIntTracer
StdIntTracer::def
;
120
121
122
123
StdBoolTracer::StdBoolTracer
(std::ostream& os0)
124
: os(os0) {}
125
126
void
127
StdBoolTracer::init
(
const
Space
&,
const
BoolTraceRecorder
&
t
) {
128
os
<<
"trace<Bool>::init(id:"
<<
t
.id();
129
if
(
t
.group().in())
130
os
<<
",g:"
;
t
.group().id();
131
os
<<
") slack: 100% ("
<<
t
.slack().initial() <<
" values)"
132
<< std::endl;
133
}
134
135
void
136
StdBoolTracer::prune
(
const
Space
&,
const
BoolTraceRecorder
&
t
,
137
const
ViewTraceInfo
& vti,
int
i
,
BoolTraceDelta
&
d
) {
138
os
<<
"trace<Bool>::prune(id:"
<<
t
.id();
139
if
(
t
.group().in())
140
os
<<
",g:"
;
t
.group().id();
141
os
<<
"): ["
<<
i
<<
"] = "
<<
t
[
i
] <<
" - {"
;
142
os
<<
d
.
min
();
143
if
(
d
.
width
() > 1)
144
os
<<
".."
<<
d
.
max
();
145
++
d
;
146
while
(
d
()) {
147
os
<<
','
<<
d
.
min
();
148
if
(
d
.
width
() > 1)
149
os
<<
".."
<<
d
.
max
();
150
++
d
;
151
}
152
os
<<
"} by "
<< vti << std::endl;
153
}
154
155
void
156
StdBoolTracer::fix
(
const
Space
&,
const
BoolTraceRecorder
&
t
) {
157
os
<<
"trace<Bool>::fix(id:"
<<
t
.id();
158
if
(
t
.group().in())
159
os
<<
",g:"
;
t
.group().id();
160
os
<<
") slack: "
;
161
double
sl_i =
static_cast<
double
>
(
t
.slack().initial());
162
double
sl_p =
static_cast<
double
>
(
t
.slack().previous());
163
double
sl_c =
static_cast<
double
>
(
t
.slack().current());
164
double
p_c = 100.0 * (sl_c / sl_i);
165
double
p_d = 100.0 * (sl_p / sl_i) - p_c;
166
os
<< std::showpoint << std::setprecision(4)
167
<< p_c <<
"% - "
168
<< std::showpoint << std::setprecision(4)
169
<< p_d <<
'%'
170
<< std::endl;
171
}
172
173
void
174
StdBoolTracer::fail
(
const
Space
&,
const
BoolTraceRecorder
&
t
) {
175
os
<<
"trace<Bool>::fail(id:"
<<
t
.id();
176
if
(
t
.group().in())
177
os
<<
",g:"
;
t
.group().id();
178
os
<<
") slack: "
;
179
double
sl_i =
static_cast<
double
>
(
t
.slack().initial());
180
double
sl_p =
static_cast<
double
>
(
t
.slack().previous());
181
double
sl_c =
static_cast<
double
>
(
t
.slack().current());
182
double
p_c = 100.0 * (sl_c / sl_i);
183
double
p_d = 100.0 * (sl_p / sl_i) - p_c;
184
os
<< std::showpoint << std::setprecision(4)
185
<< p_c <<
"% - "
186
<< std::showpoint << std::setprecision(4)
187
<< p_d <<
'%'
188
<< std::endl;
189
}
190
191
void
192
StdBoolTracer::done
(
const
Space
&,
const
BoolTraceRecorder
&
t
) {
193
os
<<
"trace<Bool>::done(id:"
<<
t
.id();
194
if
(
t
.group().in())
195
os
<<
",g:"
;
t
.group().id();
196
os
<<
") slack: 0%"
<< std::endl;
197
}
198
199
StdBoolTracer
StdBoolTracer::def
;
200
201
}
202
203
// STATISTICS: int-trace
Gecode::StdIntTracer::StdIntTracer
StdIntTracer(std::ostream &os0=std::cerr)
Initialize with output stream os0 and events \ e.
Definition:
tracer.cpp:43
Gecode::IntSet::min
int min(int i) const
Return minimum of range at position i.
Definition:
int-set-1.hpp:115
Gecode::BoolTraceDelta
Trace delta information for Boolean variables.
Definition:
int.hh:5078
Gecode::StdBoolTracer::prune
virtual void prune(const Space &home, const BoolTraceRecorder &t, const ViewTraceInfo &vti, int i, BoolTraceDelta &d)
Print prune information.
Definition:
tracer.cpp:136
Gecode::StdBoolTracer::StdBoolTracer
StdBoolTracer(std::ostream &os0=std::cerr)
Initialize with output stream os0.
Definition:
tracer.cpp:123
Gecode::IntSet::max
int max(int i) const
Return maximum of range at position i.
Definition:
int-set-1.hpp:121
int.hh
Gecode::StdIntTracer::prune
virtual void prune(const Space &home, const IntTraceRecorder &t, const ViewTraceInfo &vti, int i, IntTraceDelta &d)
Print prune information.
Definition:
tracer.cpp:56
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::StdIntTracer::def
static StdIntTracer def
Default tracer (printing to std::cerr)
Definition:
int.hh:5150
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:234
Gecode::IntTraceDelta
Trace delta information for integer variables.
Definition:
int.hh:5058
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::StdIntTracer::fail
virtual void fail(const Space &home, const IntTraceRecorder &t)
Print failure information.
Definition:
tracer.cpp:94
Gecode::StdIntTracer::os
std::ostream & os
Output stream to use.
Definition:
int.hh:5134
Gecode
Gecode toplevel namespace
Gecode::StdBoolTracer
Standard Boolean variable tracer.
Definition:
int.hh:5169
Gecode::StdBoolTracer::fail
virtual void fail(const Space &home, const BoolTraceRecorder &t)
Print failure information.
Definition:
tracer.cpp:174
Gecode::StdBoolTracer::init
virtual void init(const Space &home, const BoolTraceRecorder &t)
Print init information.
Definition:
tracer.cpp:127
Gecode::StdIntTracer::fix
virtual void fix(const Space &home, const IntTraceRecorder &t)
Print fixpoint information.
Definition:
tracer.cpp:76
Gecode::StdIntTracer
Standard integer variable tracer.
Definition:
int.hh:5131
Gecode::StdBoolTracer::os
std::ostream & os
Output stream to use.
Definition:
int.hh:5172
Gecode::StdBoolTracer::done
virtual void done(const Space &home, const BoolTraceRecorder &t)
Print that trace recorder is done.
Definition:
tracer.cpp:192
Gecode::ViewTraceRecorder
Propagator for recording view trace information.
Definition:
trace-recorder.hpp:63
Gecode::StdBoolTracer::fix
virtual void fix(const Space &home, const BoolTraceRecorder &t)
Print fixpoint information.
Definition:
tracer.cpp:156
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
Gecode::StdBoolTracer::def
static StdBoolTracer def
Default tracer (printing to std::cerr)
Definition:
int.hh:5188
Gecode::ViewTraceInfo
View trace information.
Definition:
core.hpp:974
Gecode::StdIntTracer::init
virtual void init(const Space &home, const IntTraceRecorder &t)
Print init information.
Definition:
tracer.cpp:47
Gecode::IntSet::width
unsigned int width(int i) const
Return width of range at position i.
Definition:
int-set-1.hpp:127
Gecode::StdIntTracer::done
virtual void done(const Space &home, const IntTraceRecorder &t)
Print that trace recorder is done.
Definition:
tracer.cpp:112