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/int.hh> 36 37namespace Gecode { 38 39 StdIntTracer::StdIntTracer(std::ostream& os0) 40 : os(os0) {} 41 42 void 43 StdIntTracer::init(const Space&, const IntTraceRecorder& t) { 44 os << "trace<Int>::init(id:" << t.id(); 45 if (t.group().in()) 46 os << ",g:" << t.group().id(); 47 os << ") slack: 100.00% (" << t.slack().initial() << " values)" 48 << std::endl; 49 } 50 51 void 52 StdIntTracer::prune(const Space&, const IntTraceRecorder& t, 53 const ViewTraceInfo& vti, int i, IntTraceDelta& d) { 54 os << "trace<Int>::prune(id:" << t.id(); 55 if (t.group().in()) 56 os << ",g:" << t.group().id(); 57 os << "): [" << i << "] = " << t[i] << " - {"; 58 os << d.min(); 59 if (d.width() > 1) 60 os << ".." << d.max(); 61 ++d; 62 while (d()) { 63 os << ',' << d.min(); 64 if (d.width() > 1) 65 os << ".." << d.max(); 66 ++d; 67 } 68 os << "} by " << vti << std::endl; 69 } 70 71 void 72 StdIntTracer::fix(const Space&, const IntTraceRecorder& t) { 73 os << "trace<Int>::fix(id:" << t.id(); 74 if (t.group().in()) 75 os << ",g:" << t.group().id(); 76 os << ") slack: "; 77 double sl_i = static_cast<double>(t.slack().initial()); 78 double sl_p = static_cast<double>(t.slack().previous()); 79 double sl_c = static_cast<double>(t.slack().current()); 80 double p_c = 100.0 * (sl_c / sl_i); 81 double p_d = 100.0 * (sl_p / sl_i) - p_c; 82 os << std::showpoint << std::setprecision(4) 83 << p_c << "% - " 84 << std::showpoint << std::setprecision(4) 85 << p_d << '%' 86 << std::endl; 87 } 88 89 void 90 StdIntTracer::fail(const Space&, const IntTraceRecorder& t) { 91 os << "trace<Int>::fail(id:" << t.id(); 92 if (t.group().in()) 93 os << ",g:" << t.group().id(); 94 os << ") slack: "; 95 double sl_i = static_cast<double>(t.slack().initial()); 96 double sl_p = static_cast<double>(t.slack().previous()); 97 double sl_c = static_cast<double>(t.slack().current()); 98 double p_c = 100.0 * (sl_c / sl_i); 99 double p_d = 100.0 * (sl_p / sl_i) - p_c; 100 os << std::showpoint << std::setprecision(4) 101 << p_c << "% - " 102 << std::showpoint << std::setprecision(4) 103 << p_d << '%' 104 << std::endl; 105 } 106 107 void 108 StdIntTracer::done(const Space&, const IntTraceRecorder& t) { 109 os << "trace<Int>::done(id:" << t.id(); 110 if (t.group().in()) 111 os << ",g:" << t.group().id(); 112 os << ") slack: 0%" << std::endl; 113 } 114 115 StdIntTracer StdIntTracer::def; 116 117 118 119 StdBoolTracer::StdBoolTracer(std::ostream& os0) 120 : os(os0) {} 121 122 void 123 StdBoolTracer::init(const Space&, const BoolTraceRecorder& t) { 124 os << "trace<Bool>::init(id:" << t.id(); 125 if (t.group().in()) 126 os << ",g:" << t.group().id(); 127 os << ") slack: 100% (" << t.slack().initial() << " values)" 128 << std::endl; 129 } 130 131 void 132 StdBoolTracer::prune(const Space&, const BoolTraceRecorder& t, 133 const ViewTraceInfo& vti, int i, BoolTraceDelta& d) { 134 os << "trace<Bool>::prune(id:" << t.id(); 135 if (t.group().in()) 136 os << ",g:" << t.group().id(); 137 os << "): [" << i << "] = " << t[i] << " - {"; 138 os << d.min(); 139 if (d.width() > 1) 140 os << ".." << d.max(); 141 ++d; 142 while (d()) { 143 os << ',' << d.min(); 144 if (d.width() > 1) 145 os << ".." << d.max(); 146 ++d; 147 } 148 os << "} by " << vti << std::endl; 149 } 150 151 void 152 StdBoolTracer::fix(const Space&, const BoolTraceRecorder& t) { 153 os << "trace<Bool>::fix(id:" << t.id(); 154 if (t.group().in()) 155 os << ",g:" << t.group().id(); 156 os << ") slack: "; 157 double sl_i = static_cast<double>(t.slack().initial()); 158 double sl_p = static_cast<double>(t.slack().previous()); 159 double sl_c = static_cast<double>(t.slack().current()); 160 double p_c = 100.0 * (sl_c / sl_i); 161 double p_d = 100.0 * (sl_p / sl_i) - p_c; 162 os << std::showpoint << std::setprecision(4) 163 << p_c << "% - " 164 << std::showpoint << std::setprecision(4) 165 << p_d << '%' 166 << std::endl; 167 } 168 169 void 170 StdBoolTracer::fail(const Space&, const BoolTraceRecorder& t) { 171 os << "trace<Bool>::fail(id:" << t.id(); 172 if (t.group().in()) 173 os << ",g:" << t.group().id(); 174 os << ") slack: "; 175 double sl_i = static_cast<double>(t.slack().initial()); 176 double sl_p = static_cast<double>(t.slack().previous()); 177 double sl_c = static_cast<double>(t.slack().current()); 178 double p_c = 100.0 * (sl_c / sl_i); 179 double p_d = 100.0 * (sl_p / sl_i) - p_c; 180 os << std::showpoint << std::setprecision(4) 181 << p_c << "% - " 182 << std::showpoint << std::setprecision(4) 183 << p_d << '%' 184 << std::endl; 185 } 186 187 void 188 StdBoolTracer::done(const Space&, const BoolTraceRecorder& t) { 189 os << "trace<Bool>::done(id:" << t.id(); 190 if (t.group().in()) 191 os << ",g:" << t.group().id(); 192 os << ") slack: 0%" << std::endl; 193 } 194 195 StdBoolTracer StdBoolTracer::def; 196 197} 198 199// STATISTICS: int-trace