Generated on Thu Mar 22 10:39:31 2012 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  *  Last modified:
00010  *     $Date: 2012-02-22 06:04:20 +0100 (Wed, 22 Feb 2012) $ by $Author: tack $
00011  *     $Revision: 12537 $
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     unsigned int sec = static_cast<unsigned int>(floor(t / 1000.0));
00049     unsigned int o_msec = static_cast<unsigned int>
00050       (t - 1000.0*static_cast<double>(sec));
00051     unsigned int min = sec / 60;
00052     unsigned int o_sec = sec - 60 * min;
00053     unsigned int hour = min / 60;
00054     unsigned int o_min = min - 60 * hour;
00055     unsigned int day = hour / 24;
00056     unsigned int o_hour = hour - 24 * day;
00057     if (day)
00058       os << day << " days, ";
00059     if (o_hour)
00060       os << o_hour << ":";
00061     if (o_hour || 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(3) << 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