Generated on Fri Oct 19 11:24:57 2018 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/int.hh>
00036 
00037 namespace Gecode {
00038 
00039   StdIntTracer::StdIntTracer(std::ostream& os0)
00040     : os(os0) {}
00041 
00042   void
00043   StdIntTracer::init(const Space&, const IntTraceRecorder& t) {
00044     os << "trace<Int>::init(id:" << t.id();
00045     if (t.group().in())
00046       os << ",g:" << t.group().id();
00047     os << ") slack: 100.00% (" << t.slack().initial() << " values)"
00048        << std::endl;
00049   }
00050 
00051   void
00052   StdIntTracer::prune(const Space&, const IntTraceRecorder& t,
00053                       const ViewTraceInfo& vti, int i, IntTraceDelta& d) {
00054     os << "trace<Int>::prune(id:" << t.id();
00055     if (t.group().in())
00056       os << ",g:" << t.group().id();
00057     os << "): [" << i << "] = " << t[i] << " - {";
00058     os << d.min();
00059     if (d.width() > 1)
00060       os << ".." << d.max();
00061     ++d;
00062     while (d()) {
00063       os << ',' << d.min();
00064       if (d.width() > 1)
00065         os << ".." << d.max();
00066       ++d;
00067     }
00068     os << "} by " << vti << std::endl;
00069   }
00070 
00071   void
00072   StdIntTracer::fix(const Space&, const IntTraceRecorder& t) {
00073     os << "trace<Int>::fix(id:" << t.id();
00074     if (t.group().in())
00075       os << ",g:" << t.group().id();
00076     os << ") slack: ";
00077     double sl_i = static_cast<double>(t.slack().initial());
00078     double sl_p = static_cast<double>(t.slack().previous());
00079     double sl_c = static_cast<double>(t.slack().current());
00080     double p_c = 100.0 * (sl_c / sl_i);
00081     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00082     os << std::showpoint << std::setprecision(4)
00083        << p_c << "% - "
00084        << std::showpoint << std::setprecision(4)
00085        << p_d << '%'
00086        << std::endl;
00087   }
00088 
00089   void
00090   StdIntTracer::fail(const Space&, const IntTraceRecorder& t) {
00091     os << "trace<Int>::fail(id:" << t.id();
00092     if (t.group().in())
00093       os << ",g:" << t.group().id();
00094     os << ") slack: ";
00095     double sl_i = static_cast<double>(t.slack().initial());
00096     double sl_p = static_cast<double>(t.slack().previous());
00097     double sl_c = static_cast<double>(t.slack().current());
00098     double p_c = 100.0 * (sl_c / sl_i);
00099     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00100     os << std::showpoint << std::setprecision(4)
00101        << p_c << "% - "
00102        << std::showpoint << std::setprecision(4)
00103        << p_d << '%'
00104        << std::endl;
00105   }
00106 
00107   void
00108   StdIntTracer::done(const Space&, const IntTraceRecorder& t) {
00109     os << "trace<Int>::done(id:" << t.id();
00110     if (t.group().in())
00111       os << ",g:" << t.group().id();
00112     os << ") slack: 0%" << std::endl;
00113   }
00114 
00115   StdIntTracer StdIntTracer::def;
00116 
00117 
00118 
00119   StdBoolTracer::StdBoolTracer(std::ostream& os0)
00120     : os(os0) {}
00121 
00122   void
00123   StdBoolTracer::init(const Space&, const BoolTraceRecorder& t) {
00124     os << "trace<Bool>::init(id:" << t.id();
00125     if (t.group().in())
00126       os << ",g:" << t.group().id();
00127     os << ") slack: 100% (" << t.slack().initial() << " values)"
00128        << std::endl;
00129   }
00130 
00131   void
00132   StdBoolTracer::prune(const Space&, const BoolTraceRecorder& t,
00133                        const ViewTraceInfo& vti, int i, BoolTraceDelta& d) {
00134     os << "trace<Bool>::prune(id:" << t.id();
00135     if (t.group().in())
00136       os << ",g:" << t.group().id();
00137     os << "): [" << i << "] = " << t[i] << " - {";
00138     os << d.min();
00139     if (d.width() > 1)
00140       os << ".." << d.max();
00141     ++d;
00142     while (d()) {
00143       os << ',' << d.min();
00144       if (d.width() > 1)
00145         os << ".." << d.max();
00146       ++d;
00147     }
00148     os << "} by " << vti << std::endl;
00149   }
00150 
00151   void
00152   StdBoolTracer::fix(const Space&, const BoolTraceRecorder& t) {
00153     os << "trace<Bool>::fix(id:" << t.id();
00154     if (t.group().in())
00155       os << ",g:" << t.group().id();
00156     os << ") slack: ";
00157     double sl_i = static_cast<double>(t.slack().initial());
00158     double sl_p = static_cast<double>(t.slack().previous());
00159     double sl_c = static_cast<double>(t.slack().current());
00160     double p_c = 100.0 * (sl_c / sl_i);
00161     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00162     os << std::showpoint << std::setprecision(4)
00163        << p_c << "% - "
00164        << std::showpoint << std::setprecision(4)
00165        << p_d << '%'
00166        << std::endl;
00167   }
00168 
00169   void
00170   StdBoolTracer::fail(const Space&, const BoolTraceRecorder& t) {
00171     os << "trace<Bool>::fail(id:" << t.id();
00172     if (t.group().in())
00173       os << ",g:" << t.group().id();
00174     os << ") slack: ";
00175     double sl_i = static_cast<double>(t.slack().initial());
00176     double sl_p = static_cast<double>(t.slack().previous());
00177     double sl_c = static_cast<double>(t.slack().current());
00178     double p_c = 100.0 * (sl_c / sl_i);
00179     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00180     os << std::showpoint << std::setprecision(4)
00181        << p_c << "% - "
00182        << std::showpoint << std::setprecision(4)
00183        << p_d << '%'
00184        << std::endl;
00185   }
00186 
00187   void
00188   StdBoolTracer::done(const Space&, const BoolTraceRecorder& t) {
00189     os << "trace<Bool>::done(id:" << t.id();
00190     if (t.group().in())
00191       os << ",g:" << t.group().id();
00192     os << ") slack: 0%" << std::endl;
00193   }
00194 
00195   StdBoolTracer StdBoolTracer::def;
00196 
00197 }
00198 
00199 // STATISTICS: int-trace