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