summaryrefslogtreecommitdiff
path: root/src/util/stats_base.cpp
blob: f55e2f5ab4826ef86b93d1bd7a368f2c3e3b0cd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*********************                                                        */
/*! \file stats_base.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Gereon Kremer
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 ** in the top-level source directory and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief Base statistic classes
 **
 ** Base statistic classes
 **/

#include "util/stats_base.h"

#include "util/statistics_registry.h"

namespace CVC4 {

Stat::Stat(const std::string& name) : d_name(name)
{
  if (CVC4_USE_STATISTICS)
  {
    CheckArgument(d_name.find(", ") == std::string::npos,
                  name,
                  "Statistics names cannot include a comma (',')");
  }
}

IntStat::IntStat(const std::string& name, int64_t init)
    : BackedStat<int64_t>(name, init)
{
}

/** Increment the underlying integer statistic. */
IntStat& IntStat::operator++()
{
  if (CVC4_USE_STATISTICS)
  {
    ++d_data;
  }
  return *this;
}
/** Increment the underlying integer statistic. */
IntStat& IntStat::operator++(int)
{
  if (CVC4_USE_STATISTICS)
  {
    ++d_data;
  }
  return *this;
}

/** Increment the underlying integer statistic by the given amount. */
IntStat& IntStat::operator+=(int64_t val)
{
  if (CVC4_USE_STATISTICS)
  {
    d_data += val;
  }
  return *this;
}

/** Keep the maximum of the current statistic value and the given one. */
void IntStat::maxAssign(int64_t val)
{
  if (CVC4_USE_STATISTICS)
  {
    if (d_data < val)
    {
      d_data = val;
    }
  }
}

/** Keep the minimum of the current statistic value and the given one. */
void IntStat::minAssign(int64_t val)
{
  if (CVC4_USE_STATISTICS)
  {
    if (d_data > val)
    {
      d_data = val;
    }
  }
}

AverageStat::AverageStat(const std::string& name)
    : BackedStat<double>(name, 0.0)
{
}

/** Add an entry to the running-average calculation. */
AverageStat& AverageStat::operator<<(double e)
{
  if (CVC4_USE_STATISTICS)
  {
    ++d_count;
    d_sum += e;
    set(d_sum / d_count);
  }
  return *this;
}

SExpr AverageStat::getValue() const
{
  std::stringstream ss;
  ss << std::fixed << std::setprecision(8) << d_data;
  return SExpr(Rational::fromDecimal(ss.str()));
}

}  // namespace CVC4
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback