SIMLIB/C++ 3.09
Loading...
Searching...
No Matches
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
46namespace simlib3 {
47
49
50////////////////////////////////////////////////////////////////////////////
51// Sample - output event
52//
53void 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//
64Graph *Graph::First = 0;
65
66void Graph::CtrInit(char *name) // common initialization
67{
68 Next = First;
69 First = this;
70 SetName(name);
71}
72
73////////////////////////////////////////////////////////////////////////////
74// constructor
75//
76Graph::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//
86Graph::~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//
102void 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//
116void 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//
131void Graph::StopSampling()
132{
133 Sample();
134 Passivate();
135}
136
137
138////////////////////////////////////////////////////////////////////////////
139// Graph::Initialize
140//
141void Graph::Initialize()
142{
143 Graph *p;
144 for(p=First; p; p=p->Next)
145 p->StartSampling();
146}
147
148
149void _GraphInit()
150{
151 Graph::Initialize();
152}
153
154}
155#endif
156
157////////////////////////////////////////////////////////////////////////////
158// end of GRAPH.CPP
159////////////////////////////////////////////////////////////////////////////
160
void Sample()
Definition: _test_.cc:38
continuous block connection (transparent reference) wrapper for pointer to objects of aContiBlock der...
Definition: simlib.h:895
Internal header file for SIMLIB/C++.
#define Dprintf(f)
Definition: internal.h:100
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition: algloop.cc:32
void Activate(Entity *e)
activate entity e
Definition: simlib.h:431
const double & Time
model time (is NOT the block)
Definition: run.cc:48
const double & StartTime
time of simulation start
Definition: run.cc:47
void Passivate(Entity *e)
passivate entity e
Definition: simlib.h:432
const SIMLIB_Phase_t & Phase
This variable contains the current phase of experiment (used for internal checking)
Definition: run.cc:58
@ INITIALIZATION
Definition: internal.h:78
@ SIMULATION
Definition: internal.h:79
SIMLIB_IMPLEMENTATION
Definition: algloop.cc:34
const double & EndTime
time of simulation end
Definition: run.cc:50
void SetName(SimObject &o, const std::string &name)
assign name to object
Definition: name.cc:42
int Print(const char *fmt,...)
for Output methods, can be redirected
Definition: print.cc:92
Main SIMLIB/C++ interface.