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, 2004 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * 14 * Permission is hereby granted, free of charge, to any person obtaining 15 * a copy of this software and associated documentation files (the 16 * "Software"), to deal in the Software without restriction, including 17 * without limitation the rights to use, copy, modify, merge, publish, 18 * distribute, sublicense, and/or sell copies of the Software, and to 19 * permit persons to whom the Software is furnished to do so, subject to 20 * the following conditions: 21 * 22 * The above copyright notice and this permission notice shall be 23 * included in all copies or substantial portions of the Software. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 * 33 */ 34 35#include <gecode/driver.hh> 36 37#include <cmath> 38 39namespace Gecode { namespace Driver { 40 41 void 42 stop(Support::Timer& timer, std::ostream& os) { 43 double t = timer.stop(); 44 unsigned int sec = static_cast<unsigned int>(floor(t / 1000.0)); 45 unsigned int o_msec = static_cast<unsigned int> 46 (t - 1000.0*static_cast<double>(sec)); 47 unsigned int min = sec / 60; 48 unsigned int o_sec = sec - 60 * min; 49 unsigned int hour = min / 60; 50 unsigned int o_min = min - 60 * hour; 51 unsigned int day = hour / 24; 52 unsigned int o_hour = hour - 24 * day; 53 if (day) 54 os << day << " days, "; 55 if (o_hour) 56 os << o_hour << ":"; 57 if (o_hour || o_min) { 58 if (o_hour) { 59 os.width(2); os.fill('0'); 60 } 61 os << o_min << ":"; 62 os.width(2); os.fill('0'); 63 } 64 os << o_sec << "."; 65 os.width(3); os.fill('0'); 66 os << o_msec 67 << " (" 68 << std::showpoint << std::fixed 69 << std::setprecision(3) << t << " ms)"; 70 } 71 72 73 double 74 am(double t[], unsigned int n) { 75 if (n < 1) 76 return 0.0; 77 double s = 0; 78 for (unsigned int i=0; i<n; i++) 79 s += t[i]; 80 return s / n; 81 } 82 83 double 84 dev(double t[], unsigned int n) { 85 if (n < 2) 86 return 0.0; 87 double m = am(t,n); 88 double s = 0.0; 89 for (unsigned int i=0; i<n; i++) { 90 double d = t[i]-m; 91 s += d*d; 92 } 93 return ::sqrt(s / (n-1)) / m; 94 } 95 96 bool CombinedStop::sigint; 97 98}} 99 100// STATISTICS: driver-any