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, 2016
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 <iomanip>
39 #include <gecode/int.hh>
40 
41 namespace Gecode {
42 
43  StdIntTracer::StdIntTracer(std::ostream& os0)
44  : os(os0) {}
45 
46  void
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
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
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
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
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 
120 
121 
122 
123  StdBoolTracer::StdBoolTracer(std::ostream& os0)
124  : os(os0) {}
125 
126  void
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
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
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
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
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 
200 
201 }
202 
203 // STATISTICS: int-trace
NodeType t
Type of node.
Definition: bool-expr.cpp:234
StdBoolTracer(std::ostream &os0=std::cerr)
Initialize with output stream os0.
Definition: tracer.cpp:123
View trace information.
Definition: core.hpp:898
bool in(Group a) const
Check whether actor group a is included in this group.
Definition: core.hpp:4803
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Definition: bool-delta.hpp:61
Standard Boolean variable tracer.
Definition: int.hh:5317
virtual void prune(const Space &home, const BoolTraceRecorder &t, const ViewTraceInfo &vti, int i, BoolTraceDelta &d)
Print prune information.
Definition: tracer.cpp:136
virtual void fix(const Space &home, const IntTraceRecorder &t)
Print fixpoint information.
Definition: tracer.cpp:76
int max(void) const
Return largest value of range.
unsigned int id(void) const
Return a unique id for the group.
Definition: core.hpp:4821
Computation spaces.
Definition: core.hpp:1668
Standard integer variable tracer.
Definition: int.hh:5279
virtual void init(const Space &home, const IntTraceRecorder &t)
Print init information.
Definition: tracer.cpp:47
unsigned int id(void) const
Return propagator id.
Definition: core.hpp:3412
Gecode::IntSet d(v, 7)
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual void fail(const Space &home, const BoolTraceRecorder &t)
Print failure information.
Definition: tracer.cpp:174
virtual void done(const Space &home, const IntTraceRecorder &t)
Print that trace recorder is done.
Definition: tracer.cpp:112
virtual void done(const Space &home, const BoolTraceRecorder &t)
Print that trace recorder is done.
Definition: tracer.cpp:192
PropagatorGroup group(void) const
Return group propagator belongs to.
Definition: core.hpp:3417
virtual void prune(const Space &home, const IntTraceRecorder &t, const ViewTraceInfo &vti, int i, IntTraceDelta &d)
Print prune information.
Definition: tracer.cpp:56
virtual void init(const Space &home, const BoolTraceRecorder &t)
Print init information.
Definition: tracer.cpp:127
std::ostream & os
Output stream to use.
Definition: int.hh:5320
static StdIntTracer def
Default tracer (printing to std::cerr)
Definition: int.hh:5298
SlackValue previous(void) const
Return previous slack value.
Definition: recorder.hpp:227
StdIntTracer(std::ostream &os0=std::cerr)
Initialize with output stream os0 and events \ e.
Definition: tracer.cpp:43
Propagator for recording view trace information.
Definition: recorder.hpp:63
virtual void fix(const Space &home, const BoolTraceRecorder &t)
Print fixpoint information.
Definition: tracer.cpp:156
Trace delta information for integer variables.
Definition: int.hh:5206
int min(void) const
Return smallest value of range.
Definition: bool-delta.hpp:53
virtual void fail(const Space &home, const IntTraceRecorder &t)
Print failure information.
Definition: tracer.cpp:94
std::ostream & os
Output stream to use.
Definition: int.hh:5282
SlackValue current(void) const
Return current slack value.
Definition: recorder.hpp:232
static StdBoolTracer def
Default tracer (printing to std::cerr)
Definition: int.hh:5336
Gecode toplevel namespace
const Slack & slack(void) const
Provide access to slack information.
Definition: recorder.hpp:211
SlackValue initial(void) const
Return initial slack value.
Definition: recorder.hpp:222
int min(void) const
Return smallest value of range.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Trace delta information for Boolean variables.
Definition: int.hh:5226
int max(void) const
Return largest value of range.
Definition: bool-delta.hpp:57