Generated on Tue May 22 09:39:49 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/set.hh>
00036 
00037 namespace Gecode {
00038 
00039   StdSetTracer::StdSetTracer(std::ostream& os0)
00040     : os(os0) {}
00041 
00042   void
00043   StdSetTracer::init(const Space&, const SetTraceRecorder& t) {
00044     os << "trace<Set>::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   StdSetTracer::prune(const Space&, const SetTraceRecorder& t,
00053                       const ViewTraceInfo& vti, int i, SetTraceDelta& d) {
00054     os << "trace<Set>::prune(id:" << t.id();
00055     if (t.group().in())
00056       os << ",g:" << t.group().id();
00057     os << "): [" << i << "] = " << t[i] << " + {";
00058     {
00059       SetTraceDelta::Glb glb(d.glb());
00060       if (glb()) {
00061         os << glb.min() << ".." << glb.max();
00062         ++glb;
00063         while (glb()) {
00064           os << "," << glb.min() << ".." << glb.max();
00065           ++glb;
00066         }
00067       }
00068     }
00069     os << "} - {";
00070     {
00071       SetTraceDelta::Lub lub(d.lub());
00072       if (lub()) {
00073         os << lub.min() << ".." << lub.max();
00074         ++lub;
00075         while (lub()) {
00076           os << "," << lub.min() << ".." << lub.max();
00077           ++lub;
00078         }
00079       }
00080     }
00081     os << "} by " << vti << std::endl;
00082   }
00083 
00084   void
00085   StdSetTracer::fix(const Space&, const SetTraceRecorder& t) {
00086     os << "trace<Set>::fix(id:" << t.id();
00087     if (t.group().in())
00088       os << ",g:" << t.group().id();
00089     os << ") slack: ";
00090     double sl_i = static_cast<double>(t.slack().initial());
00091     double sl_p = static_cast<double>(t.slack().previous());
00092     double sl_c = static_cast<double>(t.slack().current());
00093     double p_c = 100.0 * (sl_c / sl_i);
00094     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00095     os << std::showpoint << std::setprecision(4)
00096        << p_c << "% - "
00097        << std::showpoint << std::setprecision(4)
00098        << p_d << '%'
00099        << std::endl;
00100   }
00101 
00102   void
00103   StdSetTracer::fail(const Space&, const SetTraceRecorder& t) {
00104     os << "trace<Set>::fail(id:" << t.id();
00105     if (t.group().in())
00106       os << ",g:" << t.group().id();
00107     os << ") slack: ";
00108     double sl_i = static_cast<double>(t.slack().initial());
00109     double sl_p = static_cast<double>(t.slack().previous());
00110     double sl_c = static_cast<double>(t.slack().current());
00111     double p_c = 100.0 * (sl_c / sl_i);
00112     double p_d = 100.0 * (sl_p / sl_i) - p_c;
00113     os << std::showpoint << std::setprecision(4)
00114        << p_c << "% - "
00115        << std::showpoint << std::setprecision(4)
00116        << p_d << '%'
00117        << std::endl;
00118   }
00119 
00120   void
00121   StdSetTracer::done(const Space&, const SetTraceRecorder& t) {
00122     os << "trace<Set>::done(id:" << t.id();
00123     if (t.group().in())
00124       os << ",g:" << t.group().id();
00125     os << ") slack: 0%" << std::endl;
00126   }
00127 
00128   StdSetTracer StdSetTracer::def;
00129 
00130 }
00131 
00132 // STATISTICS: set-trace