13 static final double HOUR = 3600.0;
36 double nCallsExpected;
47 Tally statArrivals =
new Tally(
"Number of arrivals per day");
48 Tally statWaits =
new Tally(
"Average waiting time per customer");
49 Tally statWaitsDay =
new Tally(
"Waiting times within a day");
50 Tally statGoodQoS =
new Tally(
"Proportion of waiting times < s");
51 Tally statAbandon =
new Tally(
"Proportion of calls lost");
54 double arrivTime, servTime, patienceTime;
57 static public void main(String[] args)
throws IOException {
58 new CallEv(args.length == 1 ? args[0] :
"CallEv.dat");
61 public CallEv(String fileName)
throws IOException {
63 for (
int i = 1; i <= numDays; i++)
65 System.out.println(
"\n Num. calls expected = " + nCallsExpected +
"\n");
70 System.out.println(statArrivals.
report(0.9, 3));
71 System.out.println(statWaits.
report(0.9, 3));
72 System.out.println(statGoodQoS.
report(0.9, 3));
73 System.out.println(statAbandon.
report(0.9, 3));
76 class NextPeriod
extends Event {
79 public NextPeriod(
int period) {
85 nAgents = numAgents[j];
86 arrRate = busyness * lambda[j] / HOUR;
91 nextArrival.reschedule((nextArrival.time() -
Sim.
time()) * lambda[j - 1] / lambda[j]);
93 new NextPeriod(j + 1).schedule(1.0 * HOUR);
104 call.servTime = genServ.nextDouble();
105 if (nBusy < nAgents) {
108 statWaitsDay.add(0.0);
111 call.patienceTime = generPatience();
113 waitList.addLast(call);
125 public void checkQueue() {
127 while ((waitList.size() > 0) && (nBusy < nAgents)) {
128 Call call = waitList.removeFirst();
129 double wait =
Sim.
time() - call.arrivTime;
130 if (call.patienceTime < wait) {
132 wait = call.patienceTime;
135 new CallCompletion().schedule(call.servTime);
139 statWaitsDay.add(wait);
143 public double generPatience() {
145 double u = streamPatience.nextDouble();
149 return ExponentialDist.inverseF(nu, (1.0 - u) / (1.0 - p));
152 public void readData(String fileName)
throws IOException {
154 Locale loc = Locale.getDefault();
155 Locale.setDefault(Locale.US);
156 BufferedReader input =
new BufferedReader(
new FileReader(fileName));
157 Scanner scan =
new Scanner(input);
158 numDays = scan.nextInt();
160 openingTime = scan.nextDouble();
162 numPeriods = scan.nextInt();
164 numAgents =
new int[numPeriods];
165 lambda =
new double[numPeriods];
166 nCallsExpected = 0.0;
167 for (
int j = 0; j < numPeriods; j++) {
168 numAgents[j] = scan.nextInt();
169 lambda[j] = scan.nextDouble();
170 nCallsExpected += lambda[j];
173 alpha0 = scan.nextDouble();
175 p = scan.nextDouble();
177 nu = scan.nextDouble();
179 alpha = scan.nextDouble();
181 beta = scan.nextDouble();
183 s = scan.nextDouble();
185 Locale.setDefault(loc);
188 genServ =
new GammaAcceptanceRejectionGen(
189 new MRG32k3a(), alpha, beta);
192 public void simulOneDay() {
199 busyness = GammaDist.inverseF(alpha0, alpha0, 8, streamW.nextDouble());
203 statArrivals.add((
double) nArrivals);
204 statAbandon.add((
double) nAbandon / nCallsExpected);
205 statGoodQoS.add((
double) nGoodQoS / nCallsExpected);
206 statWaits.add(statWaitsDay.sum() / nCallsExpected);