Generated on Tue Apr 18 10:21:42 2017 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  *  Last modified:
00010  *     $Date: 2017-03-17 23:04:57 +0100 (Fri, 17 Mar 2017) $ by $Author: schulte $
00011  *     $Revision: 15597 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <iomanip>
00039 #include <gecode/int.hh>
00040 
00041 namespace Gecode {
00042 
00043   StdIntTracer::StdIntTracer(std::ostream& os0)
00044     : os(os0) {}
00045 
00046   void
00047   StdIntTracer::init(const Space&, const IntTraceRecorder& t) {
00048     os << "trace<Int>::init(id:" << t.id();
00049     if (t.group().in())
00050       os << ",g:";t.group().id();
00051     os << ") slack: 100.00% (" << t.slack().initial() << " values)"
00052        << std::endl;
00053   }
00054 
00055   void
00056   StdIntTracer::prune(const Space&, const IntTraceRecorder& t,
00057                       const ViewTraceInfo& vti, int i, IntTraceDelta& d) {
00058     os << "trace<Int>::prune(id:" << t.id();
00059     if (t.group().in())
00060       os << ",g:";t.group().id();
00061     os << "): [" << i << "] = " << t[i] << " - {";
00062     os << d.min();
00063     if (d.width() > 1)
00064       os << ".." << d.max();
00065     ++d;
00066     while (d()) {
00067       os << ',' << d.min();
00068       if (d.width() > 1)
00069         os << ".." << d.max();
00070       ++d;
00071     }
00072     os << "} by " << vti << std::endl;
00073   }
00074 
00075   void
00076   StdIntTracer::fix(const Space&, const IntTraceRecorder& t) {
00077     os << "trace<Int>::fix(id:" << t.id();
00078     if (t.group().in())
00079       os << ",g:";t.group().id();
00080     os << ") slack: ";
00081     double sl_i = static_cast<double>(t.slack().initial());
00082     double sl_p = static_cast<double>(t.slack().previous());
00083     double sl_c = static_cast<double>(t.slack().current());
00084     double p_c = 100.0 * (sl_c / sl_i);
00085     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00086     os << std::showpoint << std::setprecision(4)
00087        << p_c << "% - "
00088        << std::showpoint << std::setprecision(4)
00089        << p_d << '%'
00090        << std::endl;
00091   }
00092 
00093   void
00094   StdIntTracer::fail(const Space&, const IntTraceRecorder& t) {
00095     os << "trace<Int>::fail(id:" << t.id();
00096     if (t.group().in())
00097       os << ",g:";t.group().id();
00098     os << ") slack: ";
00099     double sl_i = static_cast<double>(t.slack().initial());
00100     double sl_p = static_cast<double>(t.slack().previous());
00101     double sl_c = static_cast<double>(t.slack().current());
00102     double p_c = 100.0 * (sl_c / sl_i);
00103     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00104     os << std::showpoint << std::setprecision(4)
00105        << p_c << "% - "
00106        << std::showpoint << std::setprecision(4)
00107        << p_d << '%'
00108        << std::endl;
00109   }
00110 
00111   void
00112   StdIntTracer::done(const Space&, const IntTraceRecorder& t) {
00113     os << "trace<Int>::done(id:" << t.id();
00114     if (t.group().in())
00115       os << ",g:";t.group().id();
00116     os << ") slack: 0%" << std::endl;
00117   }
00118 
00119   StdIntTracer StdIntTracer::def;
00120 
00121 
00122 
00123   StdBoolTracer::StdBoolTracer(std::ostream& os0)
00124     : os(os0) {}
00125 
00126   void
00127   StdBoolTracer::init(const Space&, const BoolTraceRecorder& t) {
00128     os << "trace<Bool>::init(id:" << t.id();
00129     if (t.group().in())
00130       os << ",g:";t.group().id();
00131     os << ") slack: 100% (" << t.slack().initial() << " values)"
00132        << std::endl;
00133   }
00134 
00135   void
00136   StdBoolTracer::prune(const Space&, const BoolTraceRecorder& t,
00137                        const ViewTraceInfo& vti, int i, BoolTraceDelta& d) {
00138     os << "trace<Bool>::prune(id:" << t.id();
00139     if (t.group().in())
00140       os << ",g:";t.group().id();
00141     os << "): [" << i << "] = " << t[i] << " - {";
00142     os << d.min();
00143     if (d.width() > 1)
00144       os << ".." << d.max();
00145     ++d;
00146     while (d()) {
00147       os << ',' << d.min();
00148       if (d.width() > 1)
00149         os << ".." << d.max();
00150       ++d;
00151     }
00152     os << "} by " << vti << std::endl;
00153   }
00154 
00155   void
00156   StdBoolTracer::fix(const Space&, const BoolTraceRecorder& t) {
00157     os << "trace<Bool>::fix(id:" << t.id();
00158     if (t.group().in())
00159       os << ",g:";t.group().id();
00160     os << ") slack: ";
00161     double sl_i = static_cast<double>(t.slack().initial());
00162     double sl_p = static_cast<double>(t.slack().previous());
00163     double sl_c = static_cast<double>(t.slack().current());
00164     double p_c = 100.0 * (sl_c / sl_i);
00165     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00166     os << std::showpoint << std::setprecision(4)
00167        << p_c << "% - "
00168        << std::showpoint << std::setprecision(4)
00169        << p_d << '%'
00170        << std::endl;
00171   }
00172 
00173   void
00174   StdBoolTracer::fail(const Space&, const BoolTraceRecorder& t) {
00175     os << "trace<Bool>::fail(id:" << t.id();
00176     if (t.group().in())
00177       os << ",g:";t.group().id();
00178     os << ") slack: ";
00179     double sl_i = static_cast<double>(t.slack().initial());
00180     double sl_p = static_cast<double>(t.slack().previous());
00181     double sl_c = static_cast<double>(t.slack().current());
00182     double p_c = 100.0 * (sl_c / sl_i);
00183     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00184     os << std::showpoint << std::setprecision(4)
00185        << p_c << "% - "
00186        << std::showpoint << std::setprecision(4)
00187        << p_d << '%'
00188        << std::endl;
00189   }
00190 
00191   void
00192   StdBoolTracer::done(const Space&, const BoolTraceRecorder& t) {
00193     os << "trace<Bool>::done(id:" << t.id();
00194     if (t.group().in())
00195       os << ",g:";t.group().id();
00196     os << ") slack: 0%" << std::endl;
00197   }
00198 
00199   StdBoolTracer StdBoolTracer::def;
00200 
00201 }
00202 
00203 // STATISTICS: int-trace