SIMLIB/C++  3.07
output2.cc
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 //! \file output2.cc Output subsystem implementation
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 // Output methods for all discrete classes
11 //#error Split into parts!!!!
12 //
13 
14 ////////////////////////////////////////////////////////////////////////////
15 // interface
16 //
17 
18 #include "simlib.h"
19 #include "internal.h"
20 
21 #include <cstdio> // sprintf()
22 
23 
24 ////////////////////////////////////////////////////////////////////////////
25 // implementation
26 //
27 
28 namespace simlib3 {
29 
31 
32 ////////////////////////////////////////////////////////////////////////////
33 // Facility::Output
34 //
35 void Facility::Output() const
36 {
37  char s[100];
38  Print("+----------------------------------------------------------+\n");
39  Print("| FACILITY %-47s |\n",Name().c_str());
40  Print("+----------------------------------------------------------+\n");
41  sprintf(s," Status = %s ", (Busy()) ? "BUSY" : "not BUSY");
42  Print("| %-56s |\n",s);
43  if (tstat.Number()>0)
44  {
45  sprintf(s," Time interval = %g - %g ",tstat.StartTime(), (double)Time);
46  Print( "| %-56s |\n", s);
47  Print( "| Number of requests = %-28ld |\n", tstat.Number());
48  if (Time>tstat.StartTime())
49  Print("| Average utilization = %-27g |\n", tstat.MeanValue());
50  }
51  Print("+----------------------------------------------------------+\n");
52 
53  if (OwnQueue())
54  {
55  if (Q1->StatN.Number()>0) // used
56  {
57  Print(" Input queue '%s.Q1'\n", Name().c_str());
58  Q1->Output();
59  }
60  }
61  else
62  Print(" External input queue '%s'\n",Q1->Name().c_str());
63 
64  if (Q2->StatN.Number()>0) // used
65  {
66  Print(" Interrupted services queue '%s.Q2'\n", Name().c_str());
67  Q2->Output();
68  }
69 
70  Print("\n");
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////
74 // Histogram::Output
75 //
76 void Histogram::Output() const
77 {
78  Print("+----------------------------------------------------------+\n");
79  Print("| HISTOGRAM %-46s |\n",Name().c_str());
80  //Print("+----------------------------------------------------------+\n");
81  stat.Output();
82  long sum = 0;
83  unsigned i;
84  for (i=0; i<=count+1; i++)
85  sum += dptr[i];
86  if (sum==0) return;
87  //Print("+------------+------------+----------+----------+----------+\n");
88  Print("| from | to | n | rel | sum |\n");
89  Print("+------------+------------+----------+----------+----------+\n");
90  double from = low;
91  long s = dptr[0];
92  for (i=1; i<=count; i++)
93  {
94  unsigned x = dptr[i];
95  s += x;
96  double to = from+step;
97  Print("| %10.3f | %10.3f | %8u | %8.6f | %8.6f |\n",
98  from, to, x, (double)x/sum, (double)s/sum);
99  from = to;
100  }
101  Print("+------------+------------+----------+----------+----------+\n");
102  Print("\n");
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////
106 // Process::Output
107 //
108 void Process::Output() const
109 {
110  Print(" PROCESS %-38s %10s \n", Name().c_str(), isCurrent()?"Current":" ");
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////
114 // Queue::Output
115 //
116 void Queue::Output() const
117 {
118  Print("+----------------------------------------------------------+\n");
119  Print("| QUEUE %-39s %10s |\n", Name().c_str(), StatN.Number()?"":"not used");
120  if (StatN.Number() > 0)
121  {
122  Print("+----------------------------------------------------------+\n");
123  char s[100]; // FIXME: "100 bytes should be enough"
124  sprintf(s," Time interval = %g - %g ",StatN.StartTime(), (double)Time);
125  Print( "| %-56s |\n", s);
126  Print( "| Incoming %-26ld |\n", StatN.Number());
127  Print( "| Outcoming %-26ld |\n", StatDT.Number());
128  Print( "| Current length = %-26lu |\n", size());
129  Print( "| Maximal length = %-25g |\n", StatN.Max());
130  double dt = double(Time) - StatN.StartTime();
131  if(dt>0)
132  {
133  double mv = StatN.MeanValue();
134  Print( "| Average length = %-25g |\n",mv);
135  }
136  if (StatDT.Number()>0)
137  {
138  Print( "| Minimal time = %-25g |\n", StatDT.Min());
139  Print( "| Maximal time = %-25g |\n", StatDT.Max());
140  double mv = StatDT.MeanValue();
141  Print( "| Average time = %-25g |\n", mv);
142  if (StatDT.Number()>99)
143  Print("| Standard deviation = %-25g |\n",
144  StatDT.StdDev());
145  }
146  }
147  Print("+----------------------------------------------------------+\n");
148 #ifdef XXX_PRINT_QUEUE_
149  // only for debug
150  {
151  Print("Queue contents:\n");
152  unsigned u;
153  iterator p;
154  for(p=begin(), u=1; p!=end(); ++p, u++) {
155  Print(" [%u]:\t",u);
156  (*p)->Output();
157  }
158  Print("End of queue.\n");
159  }
160 #endif
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////
164 // Stat::Output
165 //
166 void Stat::Output() const
167 {
168  Print("+----------------------------------------------------------+\n");
169  Print("| STATISTIC %-46s |\n",Name().c_str());
170  Print("+----------------------------------------------------------+\n");
171  if (n==0)
172  Print("| no record |\n");
173  else
174  {
175  Print( "| Min = %-15g Max = %-15g |\n", min, max);
176  Print( "| Number of records = %-26ld |\n", n);
177  Print( "| Average value = %-25g |\n", MeanValue());
178  if (n>99)
179  Print("| Standard deviation = %-25g |\n", StdDev());
180  }
181  Print("+----------------------------------------------------------+\n");
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////
185 // Store::Output
186 //
187 void Store::Output() const
188 {
189  char s[100];
190  Print("+----------------------------------------------------------+\n");
191  Print("| STORE %-50s |\n",Name().c_str());
192  Print("+----------------------------------------------------------+\n");
193  sprintf(s," Capacity = %lu (%lu used, %lu free) ",
194  Capacity(), used, Free());
195  Print("| %-56s |\n",s);
196  if (tstat.n>0)
197  {
198  sprintf(s," Time interval = %g - %g ",tstat.StartTime(), (double)Time);
199  Print( "| %-56s |\n", s);
200  Print( "| Number of Enter operations = %-24ld |\n", tstat.Number());
201  Print( "| Minimal used capacity = %-30g |\n", tstat.Min());
202  Print( "| Maximal used capacity = %-30g |\n", tstat.Max());
203  if (Time>tstat.StartTime())
204  Print("| Average used capacity = %-30g |\n", tstat.MeanValue());
205  }
206  Print("+----------------------------------------------------------+\n");
207  if (OwnQueue())
208  {
209  if (Q->StatN.Number()>0) // byla pouzita
210  {
211  Print(" Input queue '%s.Q'\n", Name().c_str());
212  Q->Output();
213  }
214  }
215  else
216  Print(" External input queue '%s'\n",Q->Name().c_str());
217  Print("\n");
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////
221 // TStat::Output
222 //
223 void TStat::Output() const
224 {
225  Print("+----------------------------------------------------------+\n");
226  Print("| STATISTIC %-46s |\n", Name().c_str());
227  Print("+----------------------------------------------------------+\n");
228  if (n==0)
229  Print("| no record |\n");
230  else
231  {
232  char s[100];
233  Print( "| Min = %-15g Max = %-15g |\n", min, max);
234  sprintf(s," Time = %g - %g ", t0, (double)Time);
235  Print( "| %-56s |\n", s);
236  Print( "| Number of records = %-26ld |\n", n);
237  if (Time>t0)
238  Print("| Average value = %-25g |\n", MeanValue());
239  }
240  Print("+----------------------------------------------------------+\n");
241 }
242 
243 }
244 // end of output2.cc
245 
Queue * Q1
Input queue.
Definition: simlib.h:757
virtual void Output() const override
print object to default output
Definition: output2.cc:108
unsigned long n
Definition: simlib.h:601
double Min() const
Definition: simlib.h:613
virtual void Output() const override
print statistics
Definition: output2.cc:116
bool OwnQueue() const
test for default queue
Definition: facility.cc:282
TStat StatN
Definition: simlib.h:691
bool Busy() const
in service
Definition: simlib.h:770
virtual void Output() const override
print statistics
Definition: output2.cc:187
double StartTime() const
Definition: simlib.h:617
int Print(const char *fmt,...)
for Output methods, can be redirected
Definition: print.cc:92
double Max() const
Definition: simlib.h:614
Implementation of class CalendarList interface is static - using global functions in SQS namespace...
Definition: algloop.cc:32
double max(double a, double b)
Definition: internal.h:286
const double & Time
model time (is NOT the block)
Definition: run.cc:48
unsigned long Number() const
Definition: simlib.h:612
double min(double a, double b)
Definition: internal.h:285
virtual void Output() const override
print to default output
Definition: output2.cc:76
Internal header file for SIMLIB/C++.
double MeanValue() const
Definition: tstat.cc:96
Main SIMLIB/C++ interface.
virtual std::string Name() const
get object name
Definition: object.cc:134
SIMLIB_IMPLEMENTATION
Definition: algloop.cc:34
virtual void Output() const override
print statistics
Definition: output2.cc:35
Queue * Q2
Interrupted requests queue.
Definition: simlib.h:758
virtual void Output() const override
print statistics
Definition: output2.cc:166
virtual void Output() const override
print object to default output
Definition: output2.cc:223
TStat tstat
usage statistics
Definition: simlib.h:759