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/set.hh> 36 37namespace Gecode { 38 39 StdSetTracer::StdSetTracer(std::ostream& os0) 40 : os(os0) {} 41 42 void 43 StdSetTracer::init(const Space&, const SetTraceRecorder& t) { 44 os << "trace<Set>::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 StdSetTracer::prune(const Space&, const SetTraceRecorder& t, 53 const ViewTraceInfo& vti, int i, SetTraceDelta& d) { 54 os << "trace<Set>::prune(id:" << t.id(); 55 if (t.group().in()) 56 os << ",g:" << t.group().id(); 57 os << "): [" << i << "] = " << t[i] << " + {"; 58 { 59 SetTraceDelta::Glb glb(d.glb()); 60 if (glb()) { 61 os << glb.min() << ".." << glb.max(); 62 ++glb; 63 while (glb()) { 64 os << "," << glb.min() << ".." << glb.max(); 65 ++glb; 66 } 67 } 68 } 69 os << "} - {"; 70 { 71 SetTraceDelta::Lub lub(d.lub()); 72 if (lub()) { 73 os << lub.min() << ".." << lub.max(); 74 ++lub; 75 while (lub()) { 76 os << "," << lub.min() << ".." << lub.max(); 77 ++lub; 78 } 79 } 80 } 81 os << "} by " << vti << std::endl; 82 } 83 84 void 85 StdSetTracer::fix(const Space&, const SetTraceRecorder& t) { 86 os << "trace<Set>::fix(id:" << t.id(); 87 if (t.group().in()) 88 os << ",g:" << t.group().id(); 89 os << ") slack: "; 90 double sl_i = static_cast<double>(t.slack().initial()); 91 double sl_p = static_cast<double>(t.slack().previous()); 92 double sl_c = static_cast<double>(t.slack().current()); 93 double p_c = 100.0 * (sl_c / sl_i); 94 double p_d = 100.0 * (sl_p / sl_i) - p_c; 95 os << std::showpoint << std::setprecision(4) 96 << p_c << "% - " 97 << std::showpoint << std::setprecision(4) 98 << p_d << '%' 99 << std::endl; 100 } 101 102 void 103 StdSetTracer::fail(const Space&, const SetTraceRecorder& t) { 104 os << "trace<Set>::fail(id:" << t.id(); 105 if (t.group().in()) 106 os << ",g:" << t.group().id(); 107 os << ") slack: "; 108 double sl_i = static_cast<double>(t.slack().initial()); 109 double sl_p = static_cast<double>(t.slack().previous()); 110 double sl_c = static_cast<double>(t.slack().current()); 111 double p_c = 100.0 * (sl_c / sl_i); 112 double p_d = 100.0 * (sl_p / sl_i) - p_c; 113 os << std::showpoint << std::setprecision(4) 114 << p_c << "% - " 115 << std::showpoint << std::setprecision(4) 116 << p_d << '%' 117 << std::endl; 118 } 119 120 void 121 StdSetTracer::done(const Space&, const SetTraceRecorder& t) { 122 os << "trace<Set>::done(id:" << t.id(); 123 if (t.group().in()) 124 os << ",g:" << t.group().id(); 125 os << ") slack: 0%" << std::endl; 126 } 127 128 StdSetTracer StdSetTracer::def; 129 130} 131 132// STATISTICS: set-trace