-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiftSystem.java
2055 lines (1791 loc) · 84.1 KB
/
LiftSystem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment;
import com.opencsv.CSVReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Random;
/**
*
* @author Hard-
*/
public class LiftSystem {
//for getting statistics from data
static int noOfButtonPressed = 0, countIntervalPassngerArrival = 0, countTotalPassngerArrival = 0, countTotalStoppedEvent = 0, totalInterArrivalTime = 0,
beginTime = 0, departureTime = 0, countU = 0, countStopped = 0, countTotalStoppedTime = 0;
static int[] noOfFirstPassngerArrival = new int[200];
static int[] noOfIntervalPassngerArrival = new int[200];
static int[] noOfPassngerArrival = new int[200];
static int[] noOfAllUpDelayed = new int[200];
static int[] AllUpDecision = new int[200];
static int[] noOfLiftStopped = new int[200];
static int[] noOfCountIntervalPassngerArrival = new int[200];
static int[] waitingTime = new int[200];
static int[] noOfPassengerDelayed = new int[200];
static double[] speedDirect = new double[200];
static double[] speedStopped = new double[200];
static int[] allArrivalTime = new int[1000];
static int[] allArrivalNumber = new int[1000];
static int[] allStoppedTime = new int[1000];
static int[][] liftsFloorRecords = new int[200][3];
static char[][] liftsStateRecords = new char[200][3];
static int[] departureLiftRecords = new int[200];
static int[] departureFloorRecords = new int[200];
static List<ArrayList<LiftState>> liftStateList = new ArrayList<>();
static int lastPassngerArrivalTime, TotalTimeTravelled, supposeTotalTimeTravelled, averageStoppedTimePerEvent, totalStoppedTime;
static double[][] speedDirectCategory = new double[200][4];
static double[][] speedStoppedCategory = new double[200][4];
static int[] totalNextTripInterval = new int[200];
static int[] totalInterArrivalAllUp = new int[200];
//for creating empirical distribution
static double cdf;
static double[] interArrivalPdfArr, interArrivalCdfArr, noOfPassngerPdfArr, noOfPassngerCdfArr,
intervalPassengerArrivalPdfArr, intervalPassengerArrivalCdfArr, liftFloorPdfArr, liftFloorCdfArr,
liftStatePdfArr, liftStateCdfArr, allLiftUpPdfArr, allLiftUpCdfArr, allLiftUpDecisionPdfArr, allLiftUpDecisionCdfArr,
allLiftUpDelayedPdfArr, allLiftUpDelayedCdfArr, noOfLiftStoppedPdfArr, noOfLiftStoppedCdfArr, liftStoppedTimePdfArr,
liftStoppedTimeCdfArr, nextTripInvertalPdfArr, nextTripInvertalCdfArr, interArrivalAllUpPdfArr, interArrivalAllUpCdfArr;
static int[] intervals;
static int[] x1, x2, x3, x4, x5, x6, x7, x8, x9;
static int[] averageTimePerFloor;
static int[] averageTimePerFloorStopped;
static double[] randomVariate;
//for uniformity and independen test
static double[] randomNumberTest;
static int numOfIntervals;
private static double significanceLevel, upperD, lowerD, D, criticalValue;
private static boolean h0Accepted;
private static int i,l,N,M;
private static double sumR,rho,sigma,lowerSignificanceValue,upperSignificanceValue,Z;
//simulation;
public static final int Q_LIMIT = 1000;
static char[] possibleLiftState = {'U', 'D', 'I', 'G'};
public static int liftCapacity = 13;
static int startTime, endTime;
static LiftState[] lift;
static Random random;
static int arrivalCount;
static int noOfStoppedEvent;
static int noOfInvertalArrival;
private static List<Event> eventList;
private static String[] nextRecord;
private static Event e;
private static DateFormat sdf;
private static final String FILE_PATH = "src/assignment/modellingdata.csv";
private static int zCurrent, z0, a, c, m, numOfRandomNum, zC;
static int z0Passenger;
static ArrayList<Event> list;
//calculate point estiamte for output analysis
static int[] sumLiftTrips,sumNumPassngers,sumWaitTime,sumPassengerDelayed,sumInterArrival;
static double[] sumAvgWaitTime,sumProbabilityDelayed,sumProbabilityPassengerDelayed,sumAvgInterArrival,sumActualWaiting;
static int numOfInterval,noOfRuns,numOfRuns;
static double sampleMean, sampleVariance, confidenceLevel, sum, difference,confidenceInterval;
public static class LiftState {
private int liftNo;
private int floor;
private char state;
LiftState() {
this(0, 0, '\u0000');
}
LiftState(int liftNo, int floor, char state) {
this.liftNo = liftNo;
this.floor = floor;
this.state = state;
}
public int getLiftNo() {
return liftNo;
}
public String displayLiftNo() {
return "L" + liftNo;
}
public void setLiftNo(int liftNo) {
this.liftNo = liftNo;
}
public int getFloor() {
return floor;
}
public String displayFloor() {
return Integer.toString(floor);
}
public void setFloor(int floor) {
this.floor = floor;
}
public char getState() {
return state;
}
public void setState(char state) {
this.state = state;
}
@Override
public int hashCode() {
int hash = 5;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final LiftState other = (LiftState) obj;
if (!Objects.equals(this.floor, other.floor)) {
return false;
} else if (this.state != other.state) {
return false;
}
return true;
}
@Override
public String toString() {
return "L" + liftNo + "(" + this.displayFloor() + "," + state + ")";
}
public void display() {
System.out.print("LiftState{Lift No:L" + liftNo + "floor:" + this.displayFloor() + ", state:" + state + "}");
}
}
public static class Event implements Comparable<Event> {
private String time;
private String event;
private String details;
private String details2;
public Event() {
this("", "", "");
}
public Event(String time, String event, String details) {
this.time = time;
this.event = event;
this.details = details;
}
public static Comparator<Event> getEventComparator() {
return EventComparator;
}
public static void setEventComparator(Comparator<Event> EventComparator) {
Event.EventComparator = EventComparator;
}
public String getTime() {
return time;
}
public int getTimeInInteger() {
return Integer.parseInt(time);
}
public void setTime(String time) {
this.time = time;
}
public String getEvent() {
return event;
}
public void setEvent(String event) {
this.event = event;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getDetails2() {
return details2;
}
public void setDetails2(String details2) {
this.details2 = details2;
}
@Override
public int compareTo(Event compareEvent) {
return this.time.compareTo(compareEvent.getTime());
}
public static Comparator<Event> EventComparator
= new Comparator<Event>() {
@Override
public int compare(Event event1, Event event2) {
return event1.time.compareTo(event2.getTime());
}
};
public String[] csvWriter() {
String[] writeline = new String[4];
writeline[0] = this.time;
writeline[1] = this.event;
writeline[2] = this.details;
return writeline;
}
public void display() {
System.out.println("(" + time + ", " + event + ", " + details + ")"); //event notices
}
}
public static class State {
static int numOfPassengersInQueue, numOfPassngersDelayed, clock;
}
public static void main(String[] args) throws IOException {
System.out.println("Main started");
readDataFile();
processData();
initialize();
for (int i = 0; i < numOfRandomNum; i++) {
randomNumberTest[i] = (double) zCurrent / m;
//System.out.print("="+i+"+"+zCurrent+","+randomNumberTest[i]);
zCurrent = generateNextRandomNumbersLCG();
}
//Random Number Uniformity and Independence Test
//h0Accepted = kolmogorovSmirnovTest();
//uniformityTestResult();
//testForAutocorrelation();
noOfRuns = 1;
//Output Analysis
sumLiftTrips = new int[noOfRuns];
sumNumPassngers = new int[noOfRuns];
sumWaitTime = new int[noOfRuns];
sumPassengerDelayed = new int[noOfRuns];
sumInterArrival = new int[noOfRuns];
sumAvgWaitTime = new double[noOfRuns];
sumProbabilityDelayed = new double[noOfRuns];
sumProbabilityPassengerDelayed = new double[noOfRuns];
sumAvgInterArrival = new double[noOfRuns];
sumActualWaiting = new double[noOfRuns];
numOfRuns = noOfRuns;
while (numOfRuns > 0) {
System.out.println("===============Runs: " + (11 - numOfRuns) + "===============");
initialize();
zCurrent = zC;
simulate();
report();
numOfRuns--;
}
System.out.println("\nOutput Analysis\n===================\nConfidence Level: "+confidenceLevel +" Number of Runs: "+noOfRuns);
System.out.println("Confidence Interval: "+confidenceLevel);
System.out.println("Number of Lift Trips");
calculatePointEstimate(sumLiftTrips);
System.out.println("Number of Passengers");
calculatePointEstimate(sumNumPassngers);
System.out.println("Waiting Time");
calculatePointEstimate(sumWaitTime);
System.out.println("Number of Passengers Delayed");
calculatePointEstimate(sumPassengerDelayed);
System.out.println("Passenger Interarrival Time");
calculatePointEstimate(sumInterArrival);
System.out.println("\nAverage Waiting Time for a lift trip");
calculatePointEstimate(sumAvgWaitTime);
System.out.println("\nProbability that a round of passenger delayed");
calculatePointEstimate(sumProbabilityDelayed);
System.out.println("\nProbability that a passenger delayed for the next lift trip");
calculatePointEstimate(sumProbabilityPassengerDelayed);
System.out.println("\nAverage time between arrival");
calculatePointEstimate(sumAvgInterArrival);
System.out.println("\nAverage waiting time for the passenger who waits");
calculatePointEstimate(sumActualWaiting);
report2();
}
public static void readDataFile() throws IOException {
try (
Reader reader = Files.newBufferedReader(Paths.get(FILE_PATH));
CSVReader csvReader = new CSVReader(reader);) {
// Reading Records One by One in a String array
eventList = new ArrayList<>();
sdf = new SimpleDateFormat("HH:mm:ss");
while ((nextRecord = csvReader.readNext()) != null) {
e = new Event();
String[] h1 = nextRecord[0].split(":");
int hour = Integer.parseInt(h1[0]);
int minute = Integer.parseInt(h1[1]);
int second = Integer.parseInt(h1[2]);
int clockSecond = second + (60 * minute) + (3600 * hour);
e.setTime(Integer.toString(clockSecond));
e.setEvent(nextRecord[1]);
e.setDetails(nextRecord[2]);
e.setDetails2(nextRecord[3]);
eventList.add(e);
}
/*
for (Event event : eventList) {
System.out.print(event.getTime());
System.out.print("|" + event.getEvent());
System.out.print("|" + event.getDetails());
if (event.getDetails2() != null) {
System.out.print("|" + event.getDetails2() + "\r\n");
} else {
System.out.print("\r\n");
}
}
*/
}
}
public static void initialize() {
list = new ArrayList<>();
startTime = 0;
endTime = 21600;
random = new Random();// create random value with specified seed
z0Passenger = 1;
//Event endevent = new Event("21600", "END", "Simulation Ended");
//list.add(endevent);
//Event firstEvent = new Event("0","Passenger Arrival","1");
//list.add(firstEvent);
State.clock = 0;
State.numOfPassengersInQueue = 0;
State.numOfPassngersDelayed = 0;
arrivalCount = 0;
z0 = 7;
zCurrent = z0;
a = 5;
c = 3;
m = 8192;
numOfRandomNum = 600;
numOfIntervals = 10;
randomNumberTest = new double[numOfRandomNum];
significanceLevel = 0.05;
i = 3;
l = 5;
N = 30;
M = (int)Math.round(((double)(N-i)/l)-1);
sumR = 0.0;
rho = 0.0;
sigma = 0.0;
upperSignificanceValue = 1.96;
lowerSignificanceValue = -1.96;
Z = 0.0;
sum = 0.0;
difference = 0.0;
numOfInterval = 10;
confidenceLevel = 1-((1-(90.0/100.0))/2);//0.05
}
public static void simulate() {
int cCount = 0;
int currentPointer = 0;
while (State.clock < endTime) {
passengerArrival(startTime);
for (int i = currentPointer; i < list.size(); i++) {
cCount++;
Event currentEvent = list.get(i);
State.clock = currentEvent.getTimeInInteger();
System.out.println("\n---"+cCount + "-------------------------------------------------\n Clock " + State.clock);
currentEvent.display();
currentPointer = i + 1;
}
startTime = randomNextTripTime();
}
zC = zCurrent;
}
public static void passengerArrival(int randomInterarrivalTime) {
State.clock += randomInterarrivalTime;
int currentPassengerNumber = randomPassengerNumber();
list.add(new Event(Integer.toString(State.clock), "Passenger Arrival", Integer.toString(currentPassengerNumber)));
State.numOfPassengersInQueue += currentPassengerNumber;
arrivalCount++;
if (State.clock > 21600) {
return;
}
if (arrivalCount == 1) {
buttonPressed();
} else {
if (State.numOfPassengersInQueue > Q_LIMIT) {
/* The queue has overflowed, so stop the simulation. */
System.out.printf("\nOverflow of queue at");
System.out.printf(" time %d", State.clock);
System.exit(2);
}
}
}
public static void buttonPressed() {
int countU = 0, countD = 0, countI = 0;
lift = new LiftState[4];
StringBuilder allLiftsStates = new StringBuilder();
for (int i = 1; i < 4; i++) {
lift[i] = new LiftState(i, randomLiftFloor(), randomLiftState());
if (lift[i].getState() == 'G') {
lift[i].setFloor(0);
}
allLiftsStates.append(lift[i].toString());
}
list.add(new Event(Integer.toString(State.clock), "Button Pressed", allLiftsStates.toString()));
//Current Lift Assignment Mechanism
//Assign which lift to go to ground floor
int minFloor = 0;
for (int i = 1; i < 4; i++) {
if (lift[i].getState() == 'G') {
//if there is lift at ground floor then directly assign and depart
liftDeparture(lift[i].getLiftNo(), State.clock);
break;
}
if (lift[i].getState() == 'D') {
//initialize the minfloor with the floor of the first lift which is going down
minFloor = lift[i].getFloor();
break;
}
}
//find which lift is currently going down and is at the lowest floor
for (int i = 1; i < 4; i++) {
if (lift[i].getState() == 'D' && lift[i].getFloor() < minFloor) {
minFloor = lift[i].getFloor();
}
}
//assign the lift which is currently going down and is at the lowest floor
for (int i = 1; i < 4; i++) {
if (lift[i].getState() == 'D') {
countD++;
if (lift[i].getFloor() == minFloor) {
liftDeparture(lift[i].getLiftNo(), State.clock);
break;
}
} else if (lift[i].getState() == 'U') {
//count how many lift is currently going up
countU++;
}
}
if (countU == 3) {
//delayed after the button pressed because all lifts are going up
State.clock += randomAllLiftUpDelayed();
noOfInvertalArrival = randomInterArrivalAllUp();
for (int i = 0; i < noOfInvertalArrival; i++) {
passengerArrival(randomInterarrival());
}
liftDeparture(lift[randomPickLiftForNextDeparture()].getLiftNo(), State.clock);
} else if (countD == 0) {
for (int i = 1; i < 4; i++) {
//assign the lift which is idle
if (lift[i].getState() == 'I') {
liftDeparture(lift[i].getLiftNo(), State.clock);
break;
}
}
}
/*
//Proposed Lift Assignment Mechanism
int minFloorD = 25, minFloorI = 25;
for (int i = 1; i < 4; i++) {
if (lift[i].getState() == 'G') {
//if there is lift at ground floor then directly assign and depart
liftDeparture(lift[i].getLiftNo(), State.clock);
break;
}
if (lift[i].getState() == 'I') {
//initialize the minfloor with the floor of the first lift which is going down
minFloorI = lift[i].getFloor();
break;
}
if (lift[i].getState() == 'D') {
//initialize the minfloor with the floor of the first lift which is going down
minFloorD = lift[i].getFloor();
break;
}
}
//find which lift is currently idle and is at the lowest floor
for (int i = 1; i < 4; i++) {
if (lift[i].getState() == 'I' && lift[i].getFloor() < minFloorI) {
minFloorI = lift[i].getFloor();
}
}
//find which lift is currently going down and is at the lowest floor
for (int i = 1; i < 4; i++) {
if (lift[i].getState() == 'D' && lift[i].getFloor() < minFloorD) {
minFloorD = lift[i].getFloor();
}
}
if (minFloorI < minFloorD) {
//assign the lift which is idle
for (int i = 1; i < 4; i++) {
if (lift[i].getState() == 'I') {
if (lift[i].getFloor() == minFloorI) {
liftDeparture(lift[i].getLiftNo(), State.clock);
break;
}
}
}
} else {
//assign the lift which is currently going down and is at the lowest floor
for (int i = 1; i < 4; i++) {
if (lift[i].getState() == 'D') {
countD++;
if (lift[i].getFloor() == minFloorD) {
liftDeparture(lift[i].getLiftNo(), State.clock);
break;
}
} else if (lift[i].getState() == 'U') {
//count how many lift is currently going up
countU++;
}
}
if (countU == 3) {
//delayed after the button pressed because all lifts are going up
State.clock += randomAllLiftUpDelayed();
noOfInvertalArrival = randomInterArrivalAllUp();
for (int i = 0; i < noOfInvertalArrival; i++) {
passengerArrival(randomInterarrival());
}
liftDeparture(lift[randomPickLiftForNextDeparture()].getLiftNo(), State.clock);
}
}
*/
}
public static void liftDeparture(int liftNo, int departureTime) {
list.add(new Event(Integer.toString(departureTime), "Lift Departure", lift[liftNo].displayLiftNo() + " , " + lift[liftNo].displayFloor()));
if (lift[liftNo].getState() == 'G') {
enterLift(liftNo);
} else {
schduleIntervalPassengerArrivalAndStoppedEvent(liftNo);
enterLift(liftNo);
}
}
public static void schduleIntervalPassengerArrivalAndStoppedEvent(int liftNo) {
noOfInvertalArrival = randomNoOfIntervalPassngerArrival();
for (int i = 0; i < noOfInvertalArrival; i++) {
passengerArrival(randomInterarrival());
}
noOfStoppedEvent = randomNoOfLiftStopped();
if (noOfStoppedEvent < lift[liftNo].getFloor()) {
for (int i = 0; i < noOfStoppedEvent; i++) {
State.clock += randomStoppedTime();
liftStopped(liftNo, State.clock);
}
}
}
public static void liftStopped(int liftNo, int stoppedTime) {
list.add(new Event(Integer.toString(stoppedTime), "Lift Stopped", lift[liftNo].displayLiftNo()));
}
public static void enterLift(int liftNo) {
if (lift[liftNo].getState() != 'G') {
State.clock += liftTravelTime(lift[liftNo].getFloor());
}
int numOfCurrentDelayed = State.numOfPassengersInQueue - liftCapacity;
if (numOfCurrentDelayed > 0) {
State.numOfPassngersDelayed += numOfCurrentDelayed;
} else {
numOfCurrentDelayed = 0;
}
list.add(new Event(Integer.toString(State.clock), "Enter Lift", lift[liftNo].displayLiftNo() + "," + Integer.toString(numOfCurrentDelayed)));
State.numOfPassengersInQueue = 0;
arrivalCount = 0;
}
public static void report() {
int buttonPressedTime = 0, enterLiftTime, numberOfPassengersArrived = 0, waitingTime, numOfDelayed;
int totalPassengerArrived = 0, totalPassengerDelayed = 0, totalWaitingTime = 0, totalInterArrival = 0, totalPassengerWaited = 0,
totalNumOfTrip = 0, totalNumofInterarrival = 0, totalDelayed = 0;
System.out.printf("\n%15s|%12s|%15s|%15s|%12s|%12s\n", "Clock(seconds)", "Number of Passengers Arrived", "Button Pressed Time", "Enter Lift Time", "Waiting Time", "Number of Passengrs Delayed");
for (int i = 0; i < list.size(); i++) {
switch (list.get(i).getEvent()) {
case "Passenger Arrival":
numberOfPassengersArrived += Integer.parseInt(list.get(i).getDetails());
totalPassengerArrived += numberOfPassengersArrived;
totalInterArrival += list.get(i).getTimeInInteger();
totalNumofInterarrival++;
break;
case "Button Pressed":
buttonPressedTime = list.get(i).getTimeInInteger();
break;
case "Enter Lift":
enterLiftTime = list.get(i).getTimeInInteger();
waitingTime = enterLiftTime - buttonPressedTime;
if (waitingTime != 0) {
totalPassengerWaited += numberOfPassengersArrived;
}
numOfDelayed = Integer.parseInt(list.get(i).getDetails().substring(3, list.get(i).getDetails().length()));
//System.out.printf("%15s|%28d|%19s|%15s|%12d|%12d\n", buttonPressedTime, numberOfPassengersArrived, buttonPressedTime, enterLiftTime, waitingTime, numOfDelayed);
if(numOfDelayed !=0){
totalDelayed++;
}
numberOfPassengersArrived = 0;
totalPassengerDelayed += numOfDelayed;
totalWaitingTime += waitingTime;
totalNumOfTrip++;
break;
}
}
sumLiftTrips[numOfRuns-1] = totalNumOfTrip;
sumNumPassngers[numOfRuns-1] = totalPassengerArrived;
sumWaitTime[numOfRuns-1] = totalWaitingTime;
sumPassengerDelayed[numOfRuns-1] = totalPassengerDelayed;
sumInterArrival[numOfRuns-1] = totalInterArrival;
System.out.printf("\n\nTotal Number of Lift Trips:%15d\nTotal Number of Passengers:%15d \nTotal Waiting Time:%24d seconds \nTotal Numper of Passenger Delayed: %6d\n"
+ "Total Interrarrival: %23d seconds\n" + "Total Number of Interrarrival: %23d \n",
totalNumOfTrip, totalPassengerArrived, totalWaitingTime, totalPassengerDelayed, totalInterArrival, totalNumofInterarrival);
System.out.printf("\n\nAverage waiting time for a lift trip %26.3f seconds\n\n",
(double) totalWaitingTime / totalNumOfTrip);
System.out.printf("Probability that a round of passenger delayed %7.3f\n\n",
(double) totalDelayed / totalNumOfTrip);
System.out.printf("Probability that a passenger delayed for the next lift %7.3f\n\n",
(double) totalPassengerDelayed / totalPassengerArrived);
System.out.printf("Average time between arrival and expected time arrival %9.3f seconds\n\n",
(double) totalInterArrival / totalPassengerArrived);
System.out.printf("Average waiting time for the passenger who waits %16.3f seconds\n\n",
(double) totalWaitingTime / totalPassengerWaited);
//System.out.println("****"+numOfRuns);
sumAvgWaitTime[numOfRuns-1] = (double)Math.round(((double) totalWaitingTime / totalNumOfTrip)*1000)/1000;
sumProbabilityDelayed[numOfRuns-1] = (double)Math.round(((double) totalDelayed / totalNumOfTrip)*1000)/1000;
sumProbabilityPassengerDelayed[numOfRuns-1] = (double)Math.round(((double) totalPassengerDelayed / totalPassengerArrived)*1000)/1000;
sumAvgInterArrival[numOfRuns-1] = (double)Math.round(((double) totalInterArrival / totalPassengerArrived)*1000)/1000;
sumActualWaiting[numOfRuns-1] = (double)Math.round(((double) totalWaitingTime / totalPassengerWaited)*1000)/1000;
}
public static void report2() {
System.out.println("\n===============Existing System===============\n");
int buttonPressedTime = 0, enterLiftTime, numberOfPassengersArrived = 0, waitingTime, numOfDelayed;
int totalPassengerArrived = 0, totalPassengerDelayed = 0, totalWaitingTime = 0, totalInterArrival = 0, totalPassengerWaited = 0,
totalNumOfTrip = 0, totalNumofInterarrival = 0, totalDelayed = 0;
System.out.printf("\n%15s|%12s|%15s|%15s|%12s|%12s\n", "Clock(seconds)", "Number of Passengers Arrived", "Button Pressed Time", "Enter Lift Time", "Waiting Time", "Number of Passengrs Delayed");
for (int i = 0; i < eventList.size(); i++) {
switch (eventList.get(i).getEvent()) {
case "Passenger Arrival":
numberOfPassengersArrived += Integer.parseInt(eventList.get(i).getDetails());
totalPassengerArrived += numberOfPassengersArrived;
totalInterArrival += eventList.get(i).getTimeInInteger();
totalNumofInterarrival++;
break;
case "Button Pressed":
buttonPressedTime = eventList.get(i).getTimeInInteger();
break;
case "Enter Lift":
enterLiftTime = eventList.get(i).getTimeInInteger();
waitingTime = enterLiftTime - buttonPressedTime;
if (waitingTime != 0) {
totalPassengerWaited += numberOfPassengersArrived;
}
numOfDelayed = Integer.parseInt(eventList.get(i).getDetails2());
//System.out.printf("%15s|%28d|%19s|%15s|%12d|%12d\n", buttonPressedTime, numberOfPassengersArrived, buttonPressedTime, enterLiftTime, waitingTime, numOfDelayed);
if(numOfDelayed !=0){
totalDelayed++;
}
numberOfPassengersArrived = 0;
totalPassengerDelayed += numOfDelayed;
totalWaitingTime += waitingTime;
totalNumOfTrip++;
break;
}
}
System.out.printf("\n\nTotal Number of Lift Trips:%15d\nTotal Number of Passengers:%15d \nTotal Waiting Time:%24d seconds \nTotal Numper of Passenger Delayed: %6d\n"
+ "Total Interrarrival: %23d seconds\n" + "Total Number of Interrarrival: %23d \n",
totalNumOfTrip, totalPassengerArrived, totalWaitingTime, totalPassengerDelayed, totalInterArrival, totalNumofInterarrival);
System.out.printf("\n\nAverage waiting time for a lift trip %26.3f seconds\n\n",
(double) totalWaitingTime / totalNumOfTrip);
System.out.printf("Probability that a round of passenger delayed %7.3f\n\n",
(double) totalDelayed / totalNumOfTrip);
System.out.printf("Probability that a passenger delayed for the next lift trip %7.3f\n\n",
(double) totalPassengerDelayed / totalPassengerArrived);
System.out.printf("Average time between arrival %9.3f seconds\n\n",
(double) totalInterArrival / totalPassengerArrived);
System.out.printf("Average waiting time for the passenger who waits %16.3f seconds\n\n",
(double) totalWaitingTime / totalPassengerWaited);
}
public static int randomInterarrival() {
//using Empirical Distribution
zCurrent = generateNextRandomNumbersLCG();
double randomDouble = (double) zCurrent / m;
//System.out.println("Interarrival: "+randomDouble);
if (randomDouble < interArrivalCdfArr[0]) {
return (int) Math.round(1 + (interArrivalPdfArr[0] / x1[0]) * (randomDouble - 0));
} else if (randomDouble < interArrivalCdfArr[1]) {
return (int) Math.round(x1[0] + (interArrivalPdfArr[1] / x1[0]) * (randomDouble - interArrivalCdfArr[0]));
} else if (randomDouble < interArrivalCdfArr[2]) {
return (int) Math.round(x1[1] + (interArrivalPdfArr[2] / x1[0]) * (randomDouble - interArrivalCdfArr[1]));
} else if (randomDouble < interArrivalCdfArr[3]) {
return (int) Math.round(x1[2] + (interArrivalPdfArr[3] / x1[0]) * (randomDouble - interArrivalCdfArr[2]));
} else if (randomDouble <= interArrivalCdfArr[4]) {
return (int) Math.round(x1[3] + (interArrivalPdfArr[4] / x1[0]) * (randomDouble - interArrivalCdfArr[3]));
} else if (randomDouble <= interArrivalCdfArr[5]) {
return (int) Math.round(x1[4] + (interArrivalPdfArr[5] / x1[0]) * (randomDouble - interArrivalCdfArr[4]));
} else if (randomDouble <= interArrivalCdfArr[6]) {
return (int) Math.round(x1[5] + (interArrivalPdfArr[6] / x1[0]) * (randomDouble - interArrivalCdfArr[5]));
} else if (randomDouble <= interArrivalCdfArr[7]) {
return (int) Math.round(x1[6] + (interArrivalPdfArr[7] / x1[0]) * (randomDouble - interArrivalCdfArr[6]));
}
return 0;
}
public static int randomPassengerNumber() {
//using Empirical Distribution
zCurrent = generateNextRandomNumbersLCG();
double randomDouble = (double) zCurrent / m;
if (randomDouble < noOfPassngerCdfArr[0]) {
return (int) Math.round(1 + (noOfPassngerPdfArr[0] / x2[0]) * (randomDouble - 0));
} else if (randomDouble < interArrivalCdfArr[1]) {
return (int) Math.round(x2[0] + (noOfPassngerPdfArr[1] / x2[0]) * (randomDouble - noOfPassngerCdfArr[0]));
} else if (randomDouble < interArrivalCdfArr[2]) {
return (int) Math.round(x2[1] + (noOfPassngerPdfArr[2] / x2[0]) * (randomDouble - noOfPassngerCdfArr[1]));
} else if (randomDouble < interArrivalCdfArr[3]) {
return (int) Math.round(x2[2] + (noOfPassngerPdfArr[3] / x2[0]) * (randomDouble - noOfPassngerCdfArr[2]));
}
return 0;
}
public static int randomNoOfIntervalPassngerArrival() {
//using Empirical Distribution
zCurrent = generateNextRandomNumbersLCG();
double randomDouble = (double) zCurrent / m;
//System.out.println(randomDouble);
if (randomDouble < intervalPassengerArrivalCdfArr[0]) {
return (int) Math.round(0 + (intervalPassengerArrivalPdfArr[0] / x3[0]) * (randomDouble - 0));
} else if (randomDouble < intervalPassengerArrivalCdfArr[1]) {
return (int) Math.round(x3[0] + (intervalPassengerArrivalPdfArr[1] / x3[0]) * (randomDouble - intervalPassengerArrivalCdfArr[0]));
} else if (randomDouble < intervalPassengerArrivalCdfArr[2]) {
return (int) Math.round(x3[1] + (intervalPassengerArrivalPdfArr[2] / x3[0]) * (randomDouble - intervalPassengerArrivalCdfArr[1]));
} else if (randomDouble < intervalPassengerArrivalCdfArr[3]) {
return (int) Math.round(x3[2] + (intervalPassengerArrivalPdfArr[3] / x3[0]) * (randomDouble - intervalPassengerArrivalCdfArr[2]));
} else if (randomDouble <= intervalPassengerArrivalCdfArr[4]) {
return (int) Math.round(x3[3] + (intervalPassengerArrivalPdfArr[4] / x3[0]) * (randomDouble - intervalPassengerArrivalCdfArr[3]));
}
return 0;
}
public static int randomLiftFloor() {
//using Empirical Distribution
zCurrent = generateNextRandomNumbersLCG();
double randomDouble = (double) zCurrent / m;
//System.out.println(randomDouble);
if (randomDouble < liftFloorCdfArr[0]) {
return (int) Math.round(1 + (liftFloorPdfArr[0] / x4[0]) * (randomDouble - 0));
} else if (randomDouble < liftFloorCdfArr[1]) {
return (int) Math.round(x4[0] + (liftFloorPdfArr[1] / x4[0]) * (randomDouble - liftFloorCdfArr[0]));
} else if (randomDouble < liftFloorCdfArr[2]) {
return (int) Math.round(x4[1] + (liftFloorPdfArr[2] / x4[0]) * (randomDouble - liftFloorCdfArr[1]));
} else if (randomDouble <= liftFloorCdfArr[3]) {
return (int) Math.round(x4[2] + (liftFloorPdfArr[3] / x4[0]) * (randomDouble - liftFloorCdfArr[2]));
}
return 0;
}
public static char randomLiftState() {
//using Empirical Distribution
zCurrent = generateNextRandomNumbersLCG();
double randomDouble = (double) zCurrent / m;
//System.out.println(randomDouble);
if (randomDouble < liftStateCdfArr[0]) {
return possibleLiftState[0];
} else if (randomDouble < liftStateCdfArr[1]) {
return possibleLiftState[1];
} else if (randomDouble < liftStateCdfArr[2]) {
return possibleLiftState[2];
} else if (randomDouble <= liftStateCdfArr[3]) {
return possibleLiftState[3];
}
return '\u0000';
}
public static int randomPickLiftForNextDeparture() {
zCurrent = generateNextRandomNumbersLCG();
double randomDouble = (double) zCurrent / m;
//System.out.println(randomDouble);
if (randomDouble < allLiftUpDecisionCdfArr[0]) {
return 1;
} else if (randomDouble < allLiftUpDecisionCdfArr[1]) {
return 2;
} else if (randomDouble <= allLiftUpDecisionCdfArr[2]) {
return 3;
}
return 0;
}
public static int randomAllLiftUpDelayed() {
//using Empirical Distribution
zCurrent = generateNextRandomNumbersLCG();
double randomDouble = (double) zCurrent / m;
//System.out.println(randomDouble);
if (randomDouble < allLiftUpDelayedCdfArr[0]) {
return (int) Math.round(1 + (allLiftUpDelayedPdfArr[0] / x5[0]) * (randomDouble - 0));
} else if (randomDouble < allLiftUpDelayedCdfArr[1]) {
return (int) Math.round(x5[0] + (allLiftUpDelayedPdfArr[1] / x5[0]) * (randomDouble - allLiftUpDelayedCdfArr[0]));
} else if (randomDouble < allLiftUpDelayedCdfArr[2]) {
return (int) Math.round(x5[1] + (allLiftUpDelayedPdfArr[2] / x5[0]) * (randomDouble - allLiftUpDelayedCdfArr[1]));
} else if (randomDouble < allLiftUpDelayedCdfArr[3]) {
return (int) Math.round(x5[2] + (allLiftUpDelayedPdfArr[3] / x5[0]) * (randomDouble - allLiftUpDelayedCdfArr[2]));
} else if (randomDouble <= allLiftUpDelayedCdfArr[4]) {
return (int) Math.round(x5[3] + (allLiftUpDelayedPdfArr[4] / x5[0]) * (randomDouble - allLiftUpDelayedCdfArr[3]));
}
return 0;
}
public static int liftTravelTime(int floorNo) {
if (floorNo < 6) {
return averageTimePerFloor[0] * floorNo;
} else if (floorNo < 12) {
return averageTimePerFloor[1] * floorNo;
} else if (floorNo < 18) {
return averageTimePerFloor[2] * floorNo;
} else if (floorNo < 24) {
return averageTimePerFloor[3] * floorNo;
}
/*
//Proposed Solution
if (floorNo < 6) {
return 5 * floorNo;
} else if (floorNo < 12) {
return 3 * floorNo;
} else if (floorNo < 18) {
return 3 * floorNo;
} else if (floorNo < 24) {
return (int)Math.round(1.5 * floorNo);
}
*/
return 0;
}
public static int randomNoOfLiftStopped() {
//using Empirical Distribution
zCurrent = generateNextRandomNumbersLCG();
double randomDouble = (double) zCurrent / m;
//System.out.println(randomDouble);
if (randomDouble < noOfLiftStoppedCdfArr[0]) {
return x6[0];
} else if (randomDouble < noOfLiftStoppedCdfArr[1]) {
return x6[1];
} else if (randomDouble < noOfLiftStoppedCdfArr[2]) {
return x6[2];
} else if (randomDouble < noOfLiftStoppedCdfArr[3]) {
return x6[3];
} else if (randomDouble < noOfLiftStoppedCdfArr[3]) {
return x6[3];
} else if (randomDouble < noOfLiftStoppedCdfArr[4]) {
return x6[4];
} else if (randomDouble < noOfLiftStoppedCdfArr[5]) {
return x6[5];
} else if (randomDouble < noOfLiftStoppedCdfArr[6]) {
return x6[6];
} else if (randomDouble < noOfLiftStoppedCdfArr[7]) {
return x6[7];
}
return 0;
}
public static int randomStoppedTime() {
//using Empirical Distribution
zCurrent = generateNextRandomNumbersLCG();
double randomDouble = (double) zCurrent / m;
//System.out.println(randomDouble);
if (randomDouble < liftStoppedTimeCdfArr[0]) {
return (int) Math.round(1 + (liftStoppedTimePdfArr[0] / x7[0]) * (randomDouble - 0));
} else if (randomDouble < liftStoppedTimeCdfArr[1]) {
return (int) Math.round(x7[0] + (liftStoppedTimePdfArr[1] / x7[0]) * (randomDouble - liftStoppedTimeCdfArr[0]));
} else if (randomDouble < liftStoppedTimeCdfArr[2]) {
return (int) Math.round(x7[1] + (liftStoppedTimePdfArr[2] / x7[0]) * (randomDouble - liftStoppedTimeCdfArr[1]));
} else if (randomDouble < liftStoppedTimeCdfArr[3]) {
return (int) Math.round(x7[2] + (liftStoppedTimePdfArr[3] / x7[0]) * (randomDouble - liftStoppedTimeCdfArr[2]));
} else if (randomDouble <= liftStoppedTimeCdfArr[4]) {
return (int) Math.round(x7[3] + (liftStoppedTimePdfArr[4] / x7[0]) * (randomDouble - liftStoppedTimeCdfArr[3]));
}