SIMLIB/C++ 3.09
Loading...
Searching...
No Matches
examples/multiexp.cc

Queuing system, multiple experiments.

Queuing system, multiple experiments

////////////////////////////////////////////////////////////////////////////
// Model multiexp SIMLIB/C++
//
// More experiments using various parameters
//
#include "simlib.h"
const double ENDTime = 2000; // duration of simulation run
// model objects:
Facility Box("Box");
Histogram Table("Table",0,25,20);
class Zakaznik : public Process { // customer description
double Arrival;
void Behavior() { // --- customer behavior ---
Arrival = Time; // time of arrival
Seize(Box); // try to start service (can wait)
Wait(10); // service
Release(Box); // end the service
Table(Time-Arrival); // record time of waiting and service
}
public:
Zakaznik() { Activate(); }
};
class Generator : public Event { // transaction generator
double dt;
void Behavior() { // --- generator behavior ---
new Zakaznik; // new customer, activation
Activate(Time+Exponential(dt)); // arrival interval
}
public:
Generator(double d) : dt(d) { Activate(); }
};
void Sample() {
if(Time>0) Print(" %g", Table.stat.MeanValue());
}
Sampler s(Sample,500); // periodic sampling of model state
int main() {
SetOutput("multiexp.dat"); // output redirection
Print("# multiexp --- multiple experiments (T=%g) \n", ENDTime);
for(int i=1; i<=20; i++) {
Print("# Experiment#%d \n", i);
Init(0,ENDTime); // init time 0..ENDTime
Box.Clear(); // initialize all objects here
Table.Clear();
double interval = i;
new Generator(interval); // customers generator, activate
Print("%g ", interval);
Run(); // single simulation experiment
Print(" %g\n", Table.stat.MeanValue());
SIMLIB_statistics.Output(); // print run statistics
}
}
void Sample()
Definition: _test_.cc:38
int main()
Definition: _test_.cc:44
void Activate(Entity *e)
activate entity e
Definition: simlib.h:431
void SetOutput(const char *name)
redirects Output(), Print() to file
Definition: print.cc:50
void Run()
run simulation experiment
Definition: run.cc:228
int Print(const char *fmt,...)
for Output methods, can be redirected
Definition: print.cc:92
double Exponential(double mv)
Exponential distribution generator.
Definition: random2.cc:152
void Init(double t0, double t1=SIMLIB_MAXTIME)
Initialize simulator and model time.
Definition: simlib.h:181
const SIMLIB_statistics_t & SIMLIB_statistics
interface to internal run-time statistics structure
Definition: run.cc:78
Main SIMLIB/C++ interface.
void Output() const
print run-time statistics to output
Definition: output1.cc:63