Java Reference
In-Depth Information
time spent once a connection has been established is the service time. By
removing the waiting line, we remove the need to maintain a queue. Thus we
have only one data structure, the priority queue. In Exercise 13.17 you are
asked to incorporate a queue; as many as
L
calls will be queued if all the
operators are busy.
To simplify matters, we do not compute statistics. Instead, we list each
event as it is processed. We also assume that attempts to connect occur at con-
stant intervals; in an accurate simulation, we would model this interarrival
time by a random process. Figure 13.4 shows the output of a simulation.
We list each event
as it happens; gath-
ering statistics is a
simple extension.
The simulation class requires another class to represent events. The
Event
class is shown in Figure 13.5. The data members consist of the customer num-
ber, the time that the event will occur, and an indication of what type of event
(
DIAL_IN
or
HANG_UP
) it is. If this simulation were more complex, with several
types of events, we would make
Event
an abstract base class and derive sub-
classes from it. We do not do that here because that would complicate things
and obscure the basic workings of the simulation algorithm. The
Event
class
contains a constructor and a comparison function used by the priority queue.
The
Event
class grants package visible status to the call bank simulation class so
The
Event
class rep-
resents events. In a
complex simulation,
it would derive all
possible types of
events as sub-
classes. Using inher-
itance for the
Event
class would compli-
cate the code.
1
User 0 dials in at time 0 and connects for 1 minute
2
User 0 hangs up at time 1
3
User 1 dials in at time 1 and connects for 5 minutes
4
User 2 dials in at time 2 and connects for 4 minutes
5
User 3 dials in at time 3 and connects for 11 minutes
6
User 4 dials in at time 4 but gets busy signal
7
User 5 dials in at time 5 but gets busy signal
8
User 6 dials in at time 6 but gets busy signal
9
User 1 hangs up at time 6
10
User 2 hangs up at time 6
11
User 7 dials in at time 7 and connects for 8 minutes
12
User 8 dials in at time 8 and connects for 6 minutes
13
User 9 dials in at time 9 but gets busy signal
14
User 10 dials in at time 10 but gets busy signal
15
User 11 dials in at time 11 but gets busy signal
16
User 12 dials in at time 12 but gets busy signal
17
User 13 dials in at time 13 but gets busy signal
18
User 3 hangs up at time 14
19
User 14 dials in at time 14 and connects for 6 minutes
20
User 8 hangs up at time 14
21
User 15 dials in at time 15 and connects for 3 minutes
22
User 7 hangs up at time 15
23
User 16 dials in at time 16 and connects for 5 minutes
24
User 17 dials in at time 17 but gets busy signal
25
User 15 hangs up at time 18
26
User 18 dials in at time 18 and connects for 7 minutes
figure 13.4
Sample output for the
call bank simulation
involving three phone
lines: A dial-in is
attempted every
minute; the average
connect time is 5
minutes; and the
simulation is run for
18 minutes
Search WWH ::
Custom Search