this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2016 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34#include <iomanip> 35#include <gecode/float.hh> 36 37namespace Gecode { 38 39 StdFloatTracer::StdFloatTracer(std::ostream& os0) 40 : os(os0) {} 41 42 void 43 StdFloatTracer::init(const Space&, const FloatTraceRecorder& t) { 44 os << "trace<Float>::init(id:" << t.id(); 45 if (t.group().in()) 46 os << ",g:" << t.group().id(); 47 os << ") slack: 100.00% (" << t.slack().initial() << " width)" 48 << std::endl; 49 } 50 51 void 52 StdFloatTracer::prune(const Space&, const FloatTraceRecorder& t, 53 const ViewTraceInfo& vti, int i, FloatTraceDelta& d) { 54 os << "trace<Float>::prune(id:" << t.id(); 55 if (t.group().in()) 56 os << ",g:" << t.group().id(); 57 os << "): [" << i << "] = " << t[i] << " - [" 58 << d.min() << ".." << d.max() 59 << "] by " << vti << std::endl; 60 } 61 62 void 63 StdFloatTracer::fix(const Space&, const FloatTraceRecorder& t) { 64 os << "trace<Float>::fix(id:" << t.id(); 65 if (t.group().in()) 66 os << ",g:" << t.group().id(); 67 os << ") slack: "; 68 double sl_i = static_cast<double>(t.slack().initial()); 69 double sl_p = static_cast<double>(t.slack().previous()); 70 double sl_c = static_cast<double>(t.slack().current()); 71 double p_c = 100.0 * (sl_c / sl_i); 72 double p_d = 100.0 * (sl_p / sl_i) - p_c; 73 os << std::showpoint << std::setprecision(4) 74 << p_c << "% - " 75 << std::showpoint << std::setprecision(4) 76 << p_d << '%' 77 << std::endl; 78 } 79 80 void 81 StdFloatTracer::fail(const Space&, const FloatTraceRecorder& t) { 82 os << "trace<Float>::fail(id:" << t.id(); 83 if (t.group().in()) 84 os << ",g:" << t.group().id(); 85 os << ") slack: "; 86 double sl_i = static_cast<double>(t.slack().initial()); 87 double sl_p = static_cast<double>(t.slack().previous()); 88 double sl_c = static_cast<double>(t.slack().current()); 89 double p_c = 100.0 * (sl_c / sl_i); 90 double p_d = 100.0 * (sl_p / sl_i) - p_c; 91 os << std::showpoint << std::setprecision(4) 92 << p_c << "% - " 93 << std::showpoint << std::setprecision(4) 94 << p_d << '%' 95 << std::endl; 96 } 97 98 void 99 StdFloatTracer::done(const Space&, const FloatTraceRecorder& t) { 100 os << "trace<Float>::done(id:" << t.id(); 101 if (t.group().in()) 102 os << ",g:" << t.group().id(); 103 os << ") slack: "; 104 double sl_i = static_cast<double>(t.slack().initial()); 105 double sl_p = static_cast<double>(t.slack().previous()); 106 double sl_c = static_cast<double>(t.slack().current()); 107 double p_c = 100.0 * (sl_c / sl_i); 108 double p_d = 100.0 * (sl_p / sl_i) - p_c; 109 os << std::showpoint << std::setprecision(4) 110 << p_c << "% - " 111 << std::showpoint << std::setprecision(4) 112 << p_d << '%' 113 << std::endl; 114 } 115 116 StdFloatTracer StdFloatTracer::def; 117 118} 119 120// STATISTICS: float-trace