11public class CallCenter {
12 static final double HOUR = 3600.0;
34 double nCallsExpected;
37 LinkedList<Call> waitList =
new LinkedList<Call>();
45 Tally statArrivals = allTal[0] =
new Tally(
"Number of arrivals per day");
46 Tally statWaits = allTal[1] =
new Tally(
"Average waiting time per customer");
47 Tally statGoodQoS = allTal[2] =
new Tally(
"Proportion of waiting times < s");
48 Tally statAbandon = allTal[3] =
new Tally(
"Proportion of calls lost");
49 Tally statService = allTal[4] =
new Tally(
"Service times");
50 Tally statWaitsDay =
new Tally(
"Waiting times within a day");
52 public CallCenter(String fileName)
throws IOException {
60 public void readData(String dataFile)
throws IOException {
61 Locale loc = Locale.getDefault();
62 Locale.setDefault(Locale.US);
63 BufferedReader input =
new BufferedReader(
new FileReader(dataFile));
64 Scanner scan =
new Scanner(input);
65 openingTime = scan.nextDouble();
67 numPeriods = scan.nextInt();
69 numAgents =
new int[numPeriods];
70 lambda =
new double[numPeriods];
72 for (
int j = 0; j < numPeriods; j++) {
73 numAgents[j] = scan.nextInt();
74 lambda[j] = scan.nextDouble();
75 nCallsExpected += lambda[j];
78 alpha0 = scan.nextDouble();
80 p = scan.nextDouble();
82 nu = scan.nextDouble();
84 alpha = scan.nextDouble();
86 beta = scan.nextDouble();
88 s = scan.nextDouble();
90 Locale.setDefault(loc);
95 double arrivalTime, serviceTime, patienceTime;
98 serviceTime = genServ.nextDouble();
99 statService.add(serviceTime);
101 if (nBusy < nAgents) {
104 statWaitsDay.add(0.0);
107 patienceTime = generPatience();
109 waitList.addLast(
this);
113 public void endWait() {
114 double wait =
Sim.
time() - arrivalTime;
115 if (patienceTime < wait) {
124 statWaitsDay.add(wait);
132 public NextPeriod(
int period) {
137 if (j < numPeriods) {
138 nAgents = numAgents[j];
139 arrRate = busyness * lambda[j] / HOUR;
144 nextArrival.reschedule((nextArrival.time() -
Sim.
time()) * lambda[j - 1] / lambda[j]);
146 new NextPeriod(j + 1).schedule(1.0 * HOUR);
148 nextArrival.cancel();
170 public void checkQueue() {
171 while ((waitList.size() > 0) && (nBusy < nAgents))
172 (waitList.removeFirst()).endWait();
176 public double generPatience() {
184 public void simulateOneDay(
double busyness) {
191 this.busyness = busyness;
197 statArrivals.add((
double) nArrivals);
198 statWaits.add(statWaitsDay.sum() / nCallsExpected);
199 statGoodQoS.add((
double) nGoodQoS / nCallsExpected);
200 statAbandon.add((
double) nAbandon / nCallsExpected);
203 public void simulateOneDay() {
204 simulateOneDay(GammaDist.inverseF(alpha0, alpha0, 8, streamB.nextDouble()));
207 static public void main(String[] args)
throws IOException {
208 CallCenter cc =
new CallCenter(args.length == 1 ? args[0] :
"src/main/docs/examples/tutorial/CallCenter.dat");
209 for (
int i = 0; i < 10000; i++)
211 System.out.println(
"\nNumber of calls expected per day = " + cc.nCallsExpected +
"\n");
212 for (
int i = 0; i < cc.allTal.length; i++) {
213 cc.allTal[i].setConfidenceIntervalStudent();
214 cc.allTal[i].setConfidenceLevel(0.90);
216 System.out.println(Tally.report(
"CallCenter:", cc.allTal));