Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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/set.hh>
36
37namespace Gecode {
38
39 StdSetTracer::StdSetTracer(std::ostream& os0)
40 : os(os0) {}
41
42 void
44 os << "trace<Set>::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, SetTraceDelta& d) {
54 os << "trace<Set>::prune(id:" << t.id();
55 if (t.group().in())
56 os << ",g:" << t.group().id();
57 os << "): [" << i << "] = " << t[i] << " + {";
58 {
59 SetTraceDelta::Glb glb(d.glb());
60 if (glb()) {
61 os << glb.min() << ".." << glb.max();
62 ++glb;
63 while (glb()) {
64 os << "," << glb.min() << ".." << glb.max();
65 ++glb;
66 }
67 }
68 }
69 os << "} - {";
70 {
71 SetTraceDelta::Lub lub(d.lub());
72 if (lub()) {
73 os << lub.min() << ".." << lub.max();
74 ++lub;
75 while (lub()) {
76 os << "," << lub.min() << ".." << lub.max();
77 ++lub;
78 }
79 }
80 }
81 os << "} by " << vti << std::endl;
82 }
83
84 void
86 os << "trace<Set>::fix(id:" << t.id();
87 if (t.group().in())
88 os << ",g:" << t.group().id();
89 os << ") slack: ";
90 double sl_i = static_cast<double>(t.slack().initial());
91 double sl_p = static_cast<double>(t.slack().previous());
92 double sl_c = static_cast<double>(t.slack().current());
93 double p_c = 100.0 * (sl_c / sl_i);
94 double p_d = 100.0 * (sl_p / sl_i) - p_c;
95 os << std::showpoint << std::setprecision(4)
96 << p_c << "% - "
97 << std::showpoint << std::setprecision(4)
98 << p_d << '%'
99 << std::endl;
100 }
101
102 void
104 os << "trace<Set>::fail(id:" << t.id();
105 if (t.group().in())
106 os << ",g:" << t.group().id();
107 os << ") slack: ";
108 double sl_i = static_cast<double>(t.slack().initial());
109 double sl_p = static_cast<double>(t.slack().previous());
110 double sl_c = static_cast<double>(t.slack().current());
111 double p_c = 100.0 * (sl_c / sl_i);
112 double p_d = 100.0 * (sl_p / sl_i) - p_c;
113 os << std::showpoint << std::setprecision(4)
114 << p_c << "% - "
115 << std::showpoint << std::setprecision(4)
116 << p_d << '%'
117 << std::endl;
118 }
119
120 void
122 os << "trace<Set>::done(id:" << t.id();
123 if (t.group().in())
124 os << ",g:" << t.group().id();
125 os << ") slack: 0%" << std::endl;
126 }
127
129
130}
131
132// STATISTICS: set-trace
unsigned int id(void) const
Return a unique id for the group.
Definition core.hpp:4981
bool in(Group a) const
Check whether actor group a is included in this group.
Definition core.hpp:4963
int min(void) const
Return smallest value of range.
int max(void) const
Return largest value of range.
unsigned int id(void) const
Return propagator id.
Definition core.hpp:3549
PropagatorGroup group(void) const
Return group propagator belongs to.
Definition core.hpp:3554
Delta for the greatest lower bound.
Definition set.hh:1761
Delta for the least upper bound.
Definition set.hh:1778
Trace delta information for set variables.
Definition set.hh:1754
Computation spaces.
Definition core.hpp:1744
Standard set variable tracer.
Definition set.hh:1829
virtual void done(const Space &home, const SetTraceRecorder &t)
Print that trace recorder is done.
Definition tracer.cpp:121
virtual void init(const Space &home, const SetTraceRecorder &t)
Print init information.
Definition tracer.cpp:43
StdSetTracer(std::ostream &os0=std::cerr)
Initialize with output stream os0.
Definition tracer.cpp:39
virtual void fail(const Space &home, const SetTraceRecorder &t)
Print failure information.
Definition tracer.cpp:103
virtual void prune(const Space &home, const SetTraceRecorder &t, const ViewTraceInfo &vti, int i, SetTraceDelta &d)
Print prune information.
Definition tracer.cpp:52
virtual void fix(const Space &home, const SetTraceRecorder &t)
Print fixpoint information.
Definition tracer.cpp:85
std::ostream & os
Output stream to use.
Definition set.hh:1832
static StdSetTracer def
Default tracer (printing to std::cerr)
Definition set.hh:1848
View trace information.
Definition core.hpp:910
const Slack & slack(void) const
Provide access to slack information.
Definition recorder.hpp:208
ViewTraceRecorder< Set::SetView > SetTraceRecorder
Trace recorder for set variables.
Definition set.hh:1823
Gecode toplevel namespace