script.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, 2004 00008 * 00009 * Last modified: 00010 * $Date: 2010-05-11 12:33:38 +0200 (Tue, 11 May 2010) $ by $Author: tack $ 00011 * $Revision: 10940 $ 00012 * 00013 * This file is part of Gecode, the generic constraint 00014 * development environment: 00015 * http://www.gecode.org 00016 * 00017 * 00018 * Permission is hereby granted, free of charge, to any person obtaining 00019 * a copy of this software and associated documentation files (the 00020 * "Software"), to deal in the Software without restriction, including 00021 * without limitation the rights to use, copy, modify, merge, publish, 00022 * distribute, sublicense, and/or sell copies of the Software, and to 00023 * permit persons to whom the Software is furnished to do so, subject to 00024 * the following conditions: 00025 * 00026 * The above copyright notice and this permission notice shall be 00027 * included in all copies or substantial portions of the Software. 00028 * 00029 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00030 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00031 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00032 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00033 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00034 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00035 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00036 * 00037 */ 00038 00039 #include <gecode/driver.hh> 00040 00041 #include <cmath> 00042 00043 namespace Gecode { namespace Driver { 00044 00045 void 00046 stop(Support::Timer& timer, std::ostream& os) { 00047 double t = timer.stop(); 00048 double sec = floor(t / 1000.0); 00049 int o_msec = static_cast<int>(t - 1000.0*sec); 00050 double min = floor(sec / 60.0); 00051 int o_sec = static_cast<int>(sec - 60.0*min); 00052 double hour = floor(min / 60.0); 00053 int o_min = static_cast<int>(min - 60.0*hour); 00054 double day = floor(hour / 24.0); 00055 int o_hour = static_cast<int>(hour - 24.0*day); 00056 int o_day = static_cast<int>(day); 00057 if (o_day) 00058 os << o_day << " days, "; 00059 if (o_hour) 00060 os << o_hour << ":"; 00061 if (o_min) { 00062 if (o_hour) { 00063 os.width(2); os.fill('0'); 00064 } 00065 os << o_min << ":"; 00066 os.width(2); os.fill('0'); 00067 } 00068 os << o_sec << "."; 00069 os.width(3); os.fill('0'); 00070 os << o_msec 00071 << " (" 00072 << std::showpoint << std::fixed 00073 << std::setprecision(6) << t << " ms)"; 00074 } 00075 00076 00077 double 00078 am(double t[], int n) { 00079 if (n < 1) 00080 return 0.0; 00081 double s = 0; 00082 for (int i=n; i--; ) 00083 s += t[i]; 00084 return s / n; 00085 } 00086 00087 double 00088 dev(double t[], int n) { 00089 if (n < 2) 00090 return 0.0; 00091 double m = am(t,n); 00092 double s = 0.0; 00093 for (int i=n; i--; ) { 00094 double d = t[i]-m; 00095 s += d*d; 00096 } 00097 return ::sqrt(s / (n-1)) / m; 00098 } 00099 00100 bool Cutoff::sigint; 00101 00102 }} 00103 00104 // STATISTICS: driver-any