SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
src
tstat.cc
Go to the documentation of this file.
1
/////////////////////////////////////////////////////////////////////////////
2
//! \file tstat.cc time dependent statistics
3
//
4
// Copyright (c) 1991-2004 Petr Peringer
5
//
6
// This library is licensed under GNU Library GPL. See the file COPYING.
7
//
8
9
//
10
// class TStat --- time statistic
11
//
12
13
////////////////////////////////////////////////////////////////////////////
14
// interface
15
//
16
17
#include "
simlib.h
"
18
#include "
internal.h
"
19
20
////////////////////////////////////////////////////////////////////////////
21
// implementation
22
//
23
24
namespace
simlib3
{
25
26
SIMLIB_IMPLEMENTATION
;
27
28
29
////////////////////////////////////////////////////////////////////////////
30
// constructors
31
//
32
TStat::TStat
(
double
initval):
33
sxt
(0),
sx2t
(0),
34
min
(initval),
max
(initval),
35
t0
(
Time
),
tl
(
Time
),
// time of initialization and last op
36
xl
(initval),
// last value
37
n
(0UL)
// number of records
38
{
39
Dprintf
((
"TStat::TStat()"
));
40
}
41
42
TStat::TStat
(
const
char
*name,
double
initval) :
43
sxt
(0),
sx2t
(0),
44
min
(initval),
max
(initval),
45
t0
(
Time
),
tl
(
Time
),
46
xl
(initval),
47
n
(0UL)
48
{
49
Dprintf
((
"TStat::TStat(\"%s\")"
,name));
50
SetName
(name);
51
}
52
53
////////////////////////////////////////////////////////////////////////////
54
// destructor
55
//
56
TStat::~TStat
()
57
{
58
Dprintf
((
"TStat::~TStat() // \"%s\" "
,
Name
().c_str()));
59
}
60
61
////////////////////////////////////////////////////////////////////////////
62
// operator ()
63
//
64
void
TStat::operator ()
(
double
x)
65
{
66
if
(
Time
<
tl
)
SIMLIB_warning
(
TStatNotInitialized
);
67
double
tt =
xl
*(double(
Time
)-
tl
);
68
sxt
+= tt;
69
sx2t
+=
xl
*tt;
70
xl
= x;
71
tl
=
Time
;
72
if
(++
n
==1)
min
=
max
=x;
// TODO: check
73
else
74
{
75
if
(x<
min
)
min
= x;
76
if
(x>
max
)
max
= x;
77
}
78
}
79
80
////////////////////////////////////////////////////////////////////////////
81
// Clear
82
//
83
void
TStat::Clear
(
double
initval)
84
{
85
Dprintf
((
"TStat::Clear() // \"%s\" "
,
Name
().c_str()));
86
sxt
=
sx2t
= 0;
87
min
=
max
= initval;
88
t0
=
tl
=
Time
;
89
xl
= initval;
// last value
90
n
= 0UL;
91
}
92
93
////////////////////////////////////////////////////////////////////////////
94
// TStat::MeanValue
95
//
96
double
TStat::MeanValue
()
const
97
{
98
// if(n==0) Error(111); // FIXME: error message
99
if
(
Time
<
t0
)
100
SIMLIB_error
(
TStatNotInitialized
);;
101
if
(
Time
==
t0
)
return
xl
;
102
double
sumxt =
sxt
+
xl
*(double(
Time
)-
tl
);
// count last period
103
return
sumxt/(double(
Time
)-
t0
);
104
}
105
106
}
107
// end
108
simlib3::SimObject::SetName
void SetName(const std::string &name)
assign the name
Definition
object.cc:125
simlib3::SimObject::Name
virtual std::string Name() const
get object name
Definition
object.cc:134
simlib3::TStat::MeanValue
double MeanValue() const
Definition
tstat.cc:96
simlib3::TStat::sx2t
double sx2t
Definition
simlib.h:600
simlib3::TStat::min
double min
Definition
simlib.h:601
simlib3::TStat::n
unsigned long n
Definition
simlib.h:606
simlib3::TStat::xl
double xl
Definition
simlib.h:605
simlib3::TStat::operator()
virtual void operator()(double x)
record the value
Definition
tstat.cc:64
simlib3::TStat::tl
double tl
Definition
simlib.h:604
simlib3::TStat::TStat
TStat(double initval=0.0)
Definition
tstat.cc:32
simlib3::TStat::t0
double t0
Definition
simlib.h:603
simlib3::TStat::Clear
virtual void Clear(double initval=0.0)
initialize
Definition
tstat.cc:83
simlib3::TStat::max
double max
Definition
simlib.h:602
simlib3::TStat::sxt
double sxt
Definition
simlib.h:599
simlib3::TStat::~TStat
~TStat()
Definition
tstat.cc:56
internal.h
Internal header file for SIMLIB/C++.
Dprintf
#define Dprintf(f)
Definition
internal.h:100
simlib3
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition
algloop.cc:32
simlib3::Time
const double & Time
model time (is NOT the block)
Definition
run.cc:48
simlib3::SIMLIB_error
void SIMLIB_error(const enum _ErrEnum N)
print error message and abort program
Definition
error.cc:38
simlib3::SIMLIB_IMPLEMENTATION
SIMLIB_IMPLEMENTATION
Definition
algloop.cc:34
simlib3::SIMLIB_warning
void SIMLIB_warning(const enum _ErrEnum N)
print warning message and continue
Definition
error.cc:74
simlib3::TStatNotInitialized
@ TStatNotInitialized
Definition
errors.cc:41
simlib.h
Main SIMLIB/C++ interface.
Generated on
for SIMLIB/C++ by
1.18.0