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