SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
src
graph.cc
Go to the documentation of this file.
1
/////////////////////////////////////////////////////////////////////////////
2
// graph.cc
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
// description:
11
// Graph object has a name (= output file name)
12
// may send given values to output
13
// (is an output port of simulation model)
14
//
15
// NEW! output ports ('measuring device') + output stream
16
// + assign(port, stream)
17
//
18
// X parameters - inputs (from zero to Nmax)
19
// - name of graph file (and graph itself)
20
// - period of automatic sampling (can be changed)
21
//
22
//----
23
// Init initialization of stream
24
// Run initialize samplers
25
//----
26
//
27
28
// ZMENA! pouzit jen pro pojmenovani a registraci vystupu!
29
// spec proces bude vzorkovat? (Sampler) + output stream
30
31
32
////////////////////////////////////////////////////////////////////////////
33
// interface
34
//
35
36
#include "
simlib.h
"
37
#include "
internal.h
"
38
39
#ifdef hdsfjfhsaj
40
#include <cstdio>
41
42
////////////////////////////////////////////////////////////////////////////
43
// implementation
44
//
45
46
namespace
simlib3
{
47
48
SIMLIB_IMPLEMENTATION
;
49
50
////////////////////////////////////////////////////////////////////////////
51
// Sample - output event
52
//
53
void
Graph::Sample()
54
{
55
// prozatimni
56
double
value = in.Value();
57
Print
(
"Graph'%s': %g \n"
, Name().c_str(), value);
58
}
59
60
61
////////////////////////////////////////////////////////////////////////////
62
// graph constructors
63
//
64
Graph *Graph::First = 0;
65
66
void
Graph::CtrInit(
char
*name)
// common initialization
67
{
68
Next = First;
69
First =
this
;
70
SetName
(name);
71
}
72
73
////////////////////////////////////////////////////////////////////////////
74
// constructor
75
//
76
Graph::Graph(
char
*_name,
Input
i,
double
dTime) : in(i), TimeStep(dTime)
77
{
78
CtrInit(_name);
79
StartSampling();
// default
80
Dprintf
((
"Graph::Graph(\"%s\")"
,_name));
81
}
82
83
////////////////////////////////////////////////////////////////////////////
84
// destructor
85
//
86
Graph::~Graph()
87
{
88
Dprintf
((
"Graph::~Graph() // \"%s\" "
, Name().c_str()));
89
if
(
this
==First)
90
First = Next;
91
else
92
{
93
Graph *i;
94
for
(i=First; i && i->Next!=
this
; i=i->Next);
95
if
(i) i->Next = Next;
96
}
97
}
98
99
////////////////////////////////////////////////////////////////////////////
100
// Graph::Behavior
101
//
102
void
Graph::Behavior()
103
{
104
Sample
();
105
106
if
(TimeStep<=0)
107
TimeStep = (double(
EndTime
)-double(
StartTime
))/100;
108
109
Activate
(
double
(
Time
)+
double
(TimeStep));
110
}
111
112
113
////////////////////////////////////////////////////////////////////////////
114
// Graph::StartSampling
115
//
116
void
Graph::StartSampling()
117
{
118
if
(
Phase
!=
SIMULATION
&&
Phase
!=
INITIALIZATION
)
return
;
119
//Behavior()
120
Sample
();
121
122
if
(TimeStep<=0)
123
TimeStep = (double(
EndTime
)-double(
StartTime
))/100;
124
125
Activate
(
double
(
Time
)+
double
(TimeStep));
126
}
127
128
////////////////////////////////////////////////////////////////////////////
129
// Graph::StopSampling
130
//
131
void
Graph::StopSampling()
132
{
133
Sample
();
134
Passivate
();
135
}
136
137
138
////////////////////////////////////////////////////////////////////////////
139
// Graph::Initialize
140
//
141
void
Graph::Initialize()
142
{
143
Graph *p;
144
for
(p=First; p; p=p->Next)
145
p->StartSampling();
146
}
147
148
149
void
_GraphInit()
150
{
151
Graph::Initialize();
152
}
153
154
}
155
#endif
156
157
////////////////////////////////////////////////////////////////////////////
158
// end of GRAPH.CPP
159
////////////////////////////////////////////////////////////////////////////
160
Sample
void Sample()
Definition
_test_.cc:38
simlib3::Input
continuous block connection (transparent reference) wrapper for pointer to objects of aContiBlock der...
Definition
simlib.h:900
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::Activate
void Activate(Entity *e)
activate entity e
Definition
simlib.h:436
simlib3::Time
const double & Time
model time (is NOT the block)
Definition
run.cc:48
simlib3::StartTime
const double & StartTime
time of simulation start
Definition
run.cc:47
simlib3::Passivate
void Passivate(Entity *e)
passivate entity e
Definition
simlib.h:437
simlib3::Phase
const SIMLIB_Phase_t & Phase
Definition
run.cc:58
simlib3::INITIALIZATION
@ INITIALIZATION
Definition
internal.h:78
simlib3::SIMULATION
@ SIMULATION
Definition
internal.h:79
simlib3::SIMLIB_IMPLEMENTATION
SIMLIB_IMPLEMENTATION
Definition
algloop.cc:34
simlib3::EndTime
const double & EndTime
time of simulation end
Definition
run.cc:50
simlib3::SetName
void SetName(SimObject &o, const std::string &name)
assign name to object
Definition
name.cc:42
simlib3::Print
int Print(const char *fmt,...)
for Output methods, can be redirected
Definition
print.cc:92
simlib.h
Main SIMLIB/C++ interface.
Generated on
for SIMLIB/C++ by
1.18.0