script.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <gecode/driver.hh>
00036
00037 #include <cmath>
00038
00039 namespace Gecode { namespace Driver {
00040
00041 void
00042 stop(Support::Timer& timer, std::ostream& os) {
00043 double t = timer.stop();
00044 unsigned int sec = static_cast<unsigned int>(floor(t / 1000.0));
00045 unsigned int o_msec = static_cast<unsigned int>
00046 (t - 1000.0*static_cast<double>(sec));
00047 unsigned int min = sec / 60;
00048 unsigned int o_sec = sec - 60 * min;
00049 unsigned int hour = min / 60;
00050 unsigned int o_min = min - 60 * hour;
00051 unsigned int day = hour / 24;
00052 unsigned int o_hour = hour - 24 * day;
00053 if (day)
00054 os << day << " days, ";
00055 if (o_hour)
00056 os << o_hour << ":";
00057 if (o_hour || o_min) {
00058 if (o_hour) {
00059 os.width(2); os.fill('0');
00060 }
00061 os << o_min << ":";
00062 os.width(2); os.fill('0');
00063 }
00064 os << o_sec << ".";
00065 os.width(3); os.fill('0');
00066 os << o_msec
00067 << " ("
00068 << std::showpoint << std::fixed
00069 << std::setprecision(3) << t << " ms)";
00070 }
00071
00072
00073 double
00074 am(double t[], unsigned int n) {
00075 if (n < 1)
00076 return 0.0;
00077 double s = 0;
00078 for (unsigned int i=0; i<n; i++)
00079 s += t[i];
00080 return s / n;
00081 }
00082
00083 double
00084 dev(double t[], unsigned int n) {
00085 if (n < 2)
00086 return 0.0;
00087 double m = am(t,n);
00088 double s = 0.0;
00089 for (unsigned int i=0; i<n; i++) {
00090 double d = t[i]-m;
00091 s += d*d;
00092 }
00093 return ::sqrt(s / (n-1)) / m;
00094 }
00095
00096 bool CombinedStop::sigint;
00097
00098 }}
00099
00100