Generated on Thu Mar 16 2017 03:24:16 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: 2016-06-17 15:43:08 +0200 (Fri, 17 Jun 2016) $ by $Author: schulte $
11  * $Revision: 15116 $
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 ExecInfo& ei, 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 " << ei << 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>::done(id:" << t.id();
96  if (t.group().in())
97  os << ",g:";t.group().id();
98  os << ") slack: 0%" << std::endl;
99  }
100 
102 
103 
104 
105  StdBoolTracer::StdBoolTracer(std::ostream& os0)
106  : os(os0) {}
107 
108  void
110  os << "trace<Bool>::init(id:" << t.id();
111  if (t.group().in())
112  os << ",g:";t.group().id();
113  os << ") slack: 100% (" << t.slack().initial() << " values)"
114  << std::endl;
115  }
116 
117  void
119  const ExecInfo& ei, int i, BoolTraceDelta& d) {
120  os << "trace<Bool>::prune(id:" << t.id();
121  if (t.group().in())
122  os << ",g:";t.group().id();
123  os << "): [" << i << "] = " << t[i] << " - {";
124  os << d.min();
125  if (d.width() > 1)
126  os << ".." << d.max();
127  ++d;
128  while (d()) {
129  os << ',' << d.min();
130  if (d.width() > 1)
131  os << ".." << d.max();
132  ++d;
133  }
134  os << "} by " << ei << std::endl;
135  }
136 
137  void
139  os << "trace<Bool>::fix(id:" << t.id();
140  if (t.group().in())
141  os << ",g:";t.group().id();
142  os << ") slack: ";
143  double sl_i = static_cast<double>(t.slack().initial());
144  double sl_p = static_cast<double>(t.slack().previous());
145  double sl_c = static_cast<double>(t.slack().current());
146  double p_c = 100.0 * (sl_c / sl_i);
147  double p_d = 100.0 * (sl_p / sl_i) - p_c;
148  os << std::showpoint << std::setprecision(4)
149  << p_c << "% - "
150  << std::showpoint << std::setprecision(4)
151  << p_d << '%'
152  << std::endl;
153  }
154 
155  void
157  os << "trace<Bool>::done(id:" << t.id();
158  if (t.group().in())
159  os << ",g:";t.group().id();
160  os << ") slack: 0%" << std::endl;
161  }
162 
164 
165 }
166 
167 // STATISTICS: int-other
NodeType t
Type of node.
Definition: bool-expr.cpp:234
StdBoolTracer(std::ostream &os0=std::cerr)
Initialize with output stream os0.
Definition: tracer.cpp:105
bool in(Group a) const
Check whether actor group a is included in this group.
Definition: core.hpp:4737
const Slack & slack(void) const
Provide access to slack information.
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:4761
virtual void fix(const Space &home, const IntTraceRecorder &t)
Print fixpoint information.
Definition: tracer.cpp:76
SlackValue initial(void) const
Return initial slack value.
int max(void) const
Return largest value of range.
unsigned int id(void) const
Return a unique id for the group.
Definition: core.hpp:4755
Computation spaces.
Definition: core.hpp:1672
Standard integer variable tracer.
Definition: int.hh:4725
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:3463
Gecode::IntSet d(v, 7)
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual void prune(const Space &home, const IntTraceRecorder &t, const ExecInfo &ei, int i, IntTraceDelta &d)
Print prune information.
Definition: tracer.cpp:56
virtual void done(const Space &home, const IntTraceRecorder &t)
Print that trace recorder is done.
Definition: tracer.cpp:94
Propagator for recording trace information.
virtual void prune(const Space &home, const BoolTraceRecorder &t, const ExecInfo &ei, int i, BoolTraceDelta &d)
Print prune information.
Definition: tracer.cpp:118
virtual void done(const Space &home, const BoolTraceRecorder &t)
Print that trace recorder is done.
Definition: tracer.cpp:156
PropagatorGroup group(void) const
Return group propagator belongs to.
Definition: core.hpp:3468
virtual void init(const Space &home, const BoolTraceRecorder &t)
Print init information.
Definition: tracer.cpp:109
std::ostream & os
Output stream to use.
Definition: int.hh:4764
static StdIntTracer def
Default tracer (printing to std::cerr)
Definition: int.hh:4742
Execution information.
Definition: core.hpp:957
StdIntTracer(std::ostream &os0=std::cerr)
Initialize with output stream os0 and events \ e.
Definition: tracer.cpp:43
SlackValue previous(void) const
Return previous slack value.
virtual void fix(const Space &home, const BoolTraceRecorder &t)
Print fixpoint information.
Definition: tracer.cpp:138
Trace delta information for integer variables.
Definition: int.hh:4652
int min(void) const
Return smallest value of range.
Definition: bool-delta.hpp:53
std::ostream & os
Output stream to use.
Definition: int.hh:4728
static StdBoolTracer def
Default tracer (printing to std::cerr)
Definition: int.hh:4778
Gecode toplevel namespace
SlackValue current(void) const
Return current slack value.
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:4672
int max(void) const
Return largest value of range.
Definition: bool-delta.hpp:57