Java Reference
In-Depth Information
1
import weiss.util.Random;
2
import java.util.PriorityQueue;
3
4
// CallSim clas interface: run a simulation
5
//
6
// CONSTRUCTION: with three parameters: the number of
7
// operators, the average connect time, and the
8
// interarrival time
9
//
10
// ******************PUBLIC OPERATIONS*********************
11
// void runSim( ) --> Run a simulation
12
13
public class CallSim
14
{
15
public CallSim( int operators, double avgLen, int callIntrvl )
16
{ /* Figure 13.7 */ }
17
18
// Run the simulation.
19
public void runSim( long stoppingTime )
20
{ /* Figure 13.9 */ }
21
22
// Add a call to eventSet at the current time,
23
// and schedule one for delta in the future.
24
private void nextCall( int delta )
25
{ /* Figure 13.8 */ }
26
27
private Random r; // A random source
28
private PriorityQueue<Event> eventSet; // Pending events
29
30
// Basic parameters of the simulation
31
private int availableOperators; // Number of available operators
32
private double avgCallLen; // Length of a call
33
private int freqOfCalls; // Interval between calls
34
35
private static class Event implements Comparable<Event>
36
{ /* Figure 13.5 */ }
37
}
figure 13.6
The
CallSim
class
skeleton
The simulation class consists of only two methods. First,
nextCall
, shown
in Figure 13.8, adds a dial-in request to the event set. It maintains two private
variables: the number of the next user who will attempt to dial in and when
that event will occur. Again, we have made the simplifying assumption that
calls are made at regular intervals. In practice, we would use a random num-
ber generator to model the arrival stream.
The
nextCall
method adds a dial-
in request to the
event set.
Search WWH ::
Custom Search