The general outline for simulation programs using BPSIM (or SIM) is to first create all the necessary objects and then run the simulation for a certain amount of time or for a certain amount of terminated events. The program to simulate this example process from figure 4 will look as follows.
#include <bpsim/bpsim.h> main() {First, the simulation object and a random number generator are created. Note that it is necessary to create the simulation object before creating any BPSIM or SIM objects, because these objects will possibly need to call the simulation object to register themselves.
simulation* sim = new simulation(); // the simulation object bpgenerator* g = new bpgenerator(1); // random generator with seedThis process is carried out by two employee's who perform the same tasks. Therefor we only have to create one employee, with capacity two. The histogram is used to collect information about the usage of the employee's.
histogram* he = new histogram(0,2,10,WEIGHTED,STATISTICS,"employee usage"); employee* e = new employee(he, 2);The client, of class agent, is created together with a histogram to collect information about the lifetime of the generated data objects. It will generate objects because the generate flag, the first parameter, has been set to OK. The client will generate objects of class data according to a poisson distribution with mean 60 as has been set by means of the duration memberfunction.
Note that only one client is needed, though two clients (boxes) are depicted in figure 4. The client of class agent can both produce the data objects and receive them after they have been handled by the process.
histogram* hc = new histogram(0,40,10,FREQUENCY,GRAPH,"case lifetime"); agent* client = new agent(OK, hc); client -> duration(60.0, g, POISSON);The first datahandler to receive data from the client is the waitqueue, w1. The two histograms collect information about the length of the queue and the waiting times. The waitqueue holds the data that it receives until the first operation, o1, is ready to process it. Whether operation o1 is ready depends on the availability of an employee to execute the operation. When o1 finishes it will pass its data on to waitqueue w2 and pass a copy of the data on to the other department, otherdep. This represents the request for extra information that is needed later on in the process.
histogram* hw1a = new histogram(0,1,10,WEIGHTED,GRAPH,"queue o1 length"); histogram* hw1b = new histogram(0,10,10,FREQUENCY,GRAPH,"queue o1 waiting"); waitqueue* w1 = new waitqueue(hw1a, hw1b); operation* o1 = new operation(e); o1 -> duration(10.0, g, NORMAL, 3.0);The other department is created with its generate flag set to FALSE, which is the default value. That way the -- non-generating -- agent will simply pass the received data from o1 on after a certain amount of time. So, though in the real world the other department will pass some extra information to the process under investigation, the simulation model will simply pass the copy via otherdep to w2.
agent* otherdep = new agent(); otherdep -> duration(120.0, g, NORMAL, 60.0);The next waitqueue, w2, needs to know it has two incoming data flows, so it can hold the original data until the copy has arrived, or the other way round. It will know it has two incoming flows, because two objects will have their successor datahandler set to w2. See below where the process structure is specified.
histogram* hw2a = new histogram(0,1,10,WEIGHTED,GRAPH,"queue o2 length"); histogram* hw2b = new histogram(0,30,10,FREQUENCY,GRAPH,"queue o2 waiting"); waitqueue* w2 = new waitqueue(hw2a, hw2b);Finally, operation 2 and 3, o2 and o3, are created.
operation* o2 = new operation(e); o2 -> duration(20.0, g, NORMAL, 6.0); operation* o3 = new operation(e); o3 -> duration(30.0, g, NORMAL, 10.0);Now the process structure can be specified by means of the next members.
client -> next(w1); w1 -> next(o1); o1 -> next(w2, otherdep); otherdep -> next(w2); w2 -> next(o2); o2 -> next(o3); o3 -> next(client);And the simulation is run for 10.000 generated data objects. After finishing the simulation run, the results are printed to standard output. See for an example the next section.
sim -> run(10000); exit(0); }
Note that to construct this -- simple -- processmodel only the constructors and the member functions duration and next are needed.