Generated on Fri Oct 19 11:24:50 2018 for Gecode by doxygen 1.6.3

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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *
00014  *  Permission is hereby granted, free of charge, to any person obtaining
00015  *  a copy of this software and associated documentation files (the
00016  *  "Software"), to deal in the Software without restriction, including
00017  *  without limitation the rights to use, copy, modify, merge, publish,
00018  *  distribute, sublicense, and/or sell copies of the Software, and to
00019  *  permit persons to whom the Software is furnished to do so, subject to
00020  *  the following conditions:
00021  *
00022  *  The above copyright notice and this permission notice shall be
00023  *  included in all copies or substantial portions of the Software.
00024  *
00025  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00026  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00027  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00028  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00029  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00030  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00031  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: driver-any