Generated on Thu Apr 11 13:59:00 2019 for Gecode by doxygen 1.6.3

tracer.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2016
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <iomanip>
00035 #include <gecode/float.hh>
00036 
00037 namespace Gecode {
00038 
00039   StdFloatTracer::StdFloatTracer(std::ostream& os0)
00040     : os(os0) {}
00041 
00042   void
00043   StdFloatTracer::init(const Space&, const FloatTraceRecorder& t) {
00044     os << "trace<Float>::init(id:" << t.id();
00045     if (t.group().in())
00046       os << ",g:" << t.group().id();
00047     os << ") slack: 100.00% (" << t.slack().initial() << " width)"
00048        << std::endl;
00049   }
00050 
00051   void
00052   StdFloatTracer::prune(const Space&, const FloatTraceRecorder& t,
00053                         const ViewTraceInfo& vti, int i, FloatTraceDelta& d) {
00054     os << "trace<Float>::prune(id:" << t.id();
00055     if (t.group().in())
00056       os << ",g:" << t.group().id();
00057     os << "): [" << i << "] = " << t[i] << " - ["
00058        << d.min() << ".." << d.max()
00059        << "] by " << vti << std::endl;
00060   }
00061 
00062   void
00063   StdFloatTracer::fix(const Space&, const FloatTraceRecorder& t) {
00064     os << "trace<Float>::fix(id:" << t.id();
00065     if (t.group().in())
00066       os << ",g:" << t.group().id();
00067     os << ") slack: ";
00068     double sl_i = static_cast<double>(t.slack().initial());
00069     double sl_p = static_cast<double>(t.slack().previous());
00070     double sl_c = static_cast<double>(t.slack().current());
00071     double p_c = 100.0 * (sl_c / sl_i);
00072     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00073     os << std::showpoint << std::setprecision(4)
00074        << p_c << "% - "
00075        << std::showpoint << std::setprecision(4)
00076        << p_d << '%'
00077        << std::endl;
00078   }
00079 
00080   void
00081   StdFloatTracer::fail(const Space&, const FloatTraceRecorder& t) {
00082     os << "trace<Float>::fail(id:" << t.id();
00083     if (t.group().in())
00084       os << ",g:" << t.group().id();
00085     os << ") slack: ";
00086     double sl_i = static_cast<double>(t.slack().initial());
00087     double sl_p = static_cast<double>(t.slack().previous());
00088     double sl_c = static_cast<double>(t.slack().current());
00089     double p_c = 100.0 * (sl_c / sl_i);
00090     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00091     os << std::showpoint << std::setprecision(4)
00092        << p_c << "% - "
00093        << std::showpoint << std::setprecision(4)
00094        << p_d << '%'
00095        << std::endl;
00096   }
00097 
00098   void
00099   StdFloatTracer::done(const Space&, const FloatTraceRecorder& t) {
00100     os << "trace<Float>::done(id:" << t.id();
00101     if (t.group().in())
00102       os << ",g:" << t.group().id();
00103     os << ") slack: ";
00104     double sl_i = static_cast<double>(t.slack().initial());
00105     double sl_p = static_cast<double>(t.slack().previous());
00106     double sl_c = static_cast<double>(t.slack().current());
00107     double p_c = 100.0 * (sl_c / sl_i);
00108     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00109     os << std::showpoint << std::setprecision(4)
00110        << p_c << "% - "
00111        << std::showpoint << std::setprecision(4)
00112        << p_d << '%'
00113        << std::endl;
00114   }
00115 
00116   StdFloatTracer StdFloatTracer::def;
00117 
00118 }
00119 
00120 // STATISTICS: float-trace