tracer.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2016
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <iomanip>
#include <gecode/int.hh>
namespace Gecode {
StdIntTracer::StdIntTracer(std::ostream& os0)
: os(os0) {}
void
StdIntTracer::init(const Space&, const IntTraceRecorder& t) {
os << "trace<Int>::init(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << ") slack: 100.00% (" << t.slack().initial() << " values)"
<< std::endl;
}
void
StdIntTracer::prune(const Space&, const IntTraceRecorder& t,
const ViewTraceInfo& vti, int i, IntTraceDelta& d) {
os << "trace<Int>::prune(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << "): [" << i << "] = " << t[i] << " - {";
os << d.min();
if (d.width() > 1)
os << ".." << d.max();
++d;
while (d()) {
os << ',' << d.min();
if (d.width() > 1)
os << ".." << d.max();
++d;
}
os << "} by " << vti << std::endl;
}
void
StdIntTracer::fix(const Space&, const IntTraceRecorder& t) {
os << "trace<Int>::fix(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << ") slack: ";
double sl_i = static_cast<double>(t.slack().initial());
double sl_p = static_cast<double>(t.slack().previous());
double sl_c = static_cast<double>(t.slack().current());
double p_c = 100.0 * (sl_c / sl_i);
double p_d = 100.0 * (sl_p / sl_i) - p_c;
os << std::showpoint << std::setprecision(4)
<< p_c << "% - "
<< std::showpoint << std::setprecision(4)
<< p_d << '%'
<< std::endl;
}
void
StdIntTracer::fail(const Space&, const IntTraceRecorder& t) {
os << "trace<Int>::fail(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << ") slack: ";
double sl_i = static_cast<double>(t.slack().initial());
double sl_p = static_cast<double>(t.slack().previous());
double sl_c = static_cast<double>(t.slack().current());
double p_c = 100.0 * (sl_c / sl_i);
double p_d = 100.0 * (sl_p / sl_i) - p_c;
os << std::showpoint << std::setprecision(4)
<< p_c << "% - "
<< std::showpoint << std::setprecision(4)
<< p_d << '%'
<< std::endl;
}
void
StdIntTracer::done(const Space&, const IntTraceRecorder& t) {
os << "trace<Int>::done(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << ") slack: 0%" << std::endl;
}
StdIntTracer StdIntTracer::def;
StdBoolTracer::StdBoolTracer(std::ostream& os0)
: os(os0) {}
void
StdBoolTracer::init(const Space&, const BoolTraceRecorder& t) {
os << "trace<Bool>::init(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << ") slack: 100% (" << t.slack().initial() << " values)"
<< std::endl;
}
void
StdBoolTracer::prune(const Space&, const BoolTraceRecorder& t,
const ViewTraceInfo& vti, int i, BoolTraceDelta& d) {
os << "trace<Bool>::prune(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << "): [" << i << "] = " << t[i] << " - {";
os << d.min();
if (d.width() > 1)
os << ".." << d.max();
++d;
while (d()) {
os << ',' << d.min();
if (d.width() > 1)
os << ".." << d.max();
++d;
}
os << "} by " << vti << std::endl;
}
void
StdBoolTracer::fix(const Space&, const BoolTraceRecorder& t) {
os << "trace<Bool>::fix(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << ") slack: ";
double sl_i = static_cast<double>(t.slack().initial());
double sl_p = static_cast<double>(t.slack().previous());
double sl_c = static_cast<double>(t.slack().current());
double p_c = 100.0 * (sl_c / sl_i);
double p_d = 100.0 * (sl_p / sl_i) - p_c;
os << std::showpoint << std::setprecision(4)
<< p_c << "% - "
<< std::showpoint << std::setprecision(4)
<< p_d << '%'
<< std::endl;
}
void
StdBoolTracer::fail(const Space&, const BoolTraceRecorder& t) {
os << "trace<Bool>::fail(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << ") slack: ";
double sl_i = static_cast<double>(t.slack().initial());
double sl_p = static_cast<double>(t.slack().previous());
double sl_c = static_cast<double>(t.slack().current());
double p_c = 100.0 * (sl_c / sl_i);
double p_d = 100.0 * (sl_p / sl_i) - p_c;
os << std::showpoint << std::setprecision(4)
<< p_c << "% - "
<< std::showpoint << std::setprecision(4)
<< p_d << '%'
<< std::endl;
}
void
StdBoolTracer::done(const Space&, const BoolTraceRecorder& t) {
os << "trace<Bool>::done(id:" << t.id();
if (t.group().in())
os << ",g:" << t.group().id();
os << ") slack: 0%" << std::endl;
}
StdBoolTracer StdBoolTracer::def;
}
// STATISTICS: int-trace
Gecode::BoolTraceDelta
Trace delta information for Boolean variables.
Definition int.hh:5548
Gecode::Group::id
unsigned int id(void) const
Return a unique id for the group.
Definition core.hpp:4974
Gecode::Group::in
bool in(Group a) const
Check whether actor group a is included in this group.
Definition core.hpp:4956
Gecode::IntSet::min
int min(int i) const
Return minimum of range at position i.
Definition int-set-1.hpp:152
Gecode::IntSet::max
int max(int i) const
Return maximum of range at position i.
Definition int-set-1.hpp:158
Gecode::IntSet::width
unsigned int width(int i) const
Return width of range at position i.
Definition int-set-1.hpp:164
Gecode::IntTraceDelta
Trace delta information for integer variables.
Definition int.hh:5530
Gecode::Propagator::id
unsigned int id(void) const
Return propagator id.
Definition core.hpp:3542
Gecode::Propagator::group
PropagatorGroup group(void) const
Return group propagator belongs to.
Definition core.hpp:3547
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::StdBoolTracer
Standard Boolean variable tracer.
Definition int.hh:5639
Gecode::StdBoolTracer::init
virtual void init(const Space &home, const BoolTraceRecorder &t)
Print init information.
Definition tracer.cpp:123
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:132
Gecode::StdBoolTracer::os
std::ostream & os
Output stream to use.
Definition int.hh:5642
Gecode::StdBoolTracer::fix
virtual void fix(const Space &home, const BoolTraceRecorder &t)
Print fixpoint information.
Definition tracer.cpp:152
Gecode::StdBoolTracer::def
static StdBoolTracer def
Default tracer (printing to std::cerr).
Definition int.hh:5658
Gecode::StdBoolTracer::StdBoolTracer
StdBoolTracer(std::ostream &os0=std::cerr)
Initialize with output stream os0.
Definition tracer.cpp:119
Gecode::StdBoolTracer::fail
virtual void fail(const Space &home, const BoolTraceRecorder &t)
Print failure information.
Definition tracer.cpp:170
Gecode::StdBoolTracer::done
virtual void done(const Space &home, const BoolTraceRecorder &t)
Print that trace recorder is done.
Definition tracer.cpp:188
Gecode::StdIntTracer
Standard integer variable tracer.
Definition int.hh:5601
Gecode::StdIntTracer::done
virtual void done(const Space &home, const IntTraceRecorder &t)
Print that trace recorder is done.
Definition tracer.cpp:108
Gecode::StdIntTracer::StdIntTracer
StdIntTracer(std::ostream &os0=std::cerr)
Initialize with output stream os0 and events \ e.
Definition tracer.cpp:39
Gecode::StdIntTracer::os
std::ostream & os
Output stream to use.
Definition int.hh:5604
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:52
Gecode::StdIntTracer::init
virtual void init(const Space &home, const IntTraceRecorder &t)
Print init information.
Definition tracer.cpp:43
Gecode::StdIntTracer::fail
virtual void fail(const Space &home, const IntTraceRecorder &t)
Print failure information.
Definition tracer.cpp:90
Gecode::StdIntTracer::fix
virtual void fix(const Space &home, const IntTraceRecorder &t)
Print fixpoint information.
Definition tracer.cpp:72
Gecode::StdIntTracer::def
static StdIntTracer def
Default tracer (printing to std::cerr).
Definition int.hh:5620
Gecode::ViewTraceInfo
View trace information.
Definition core.hpp:908
Gecode::ViewTraceRecorder::slack
const Slack & slack(void) const
Provide access to slack information.
Definition recorder.hpp:208
int.hh
Gecode::IntTraceRecorder
ViewTraceRecorder< Int::IntView > IntTraceRecorder
Trace recorder for integer variables.
Definition int.hh:5595
Gecode::BoolTraceRecorder
ViewTraceRecorder< Int::BoolView > BoolTraceRecorder
Trace recorder for Boolean variables.
Definition int.hh:5633
Gecode
Gecode toplevel namespace