Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. package lotnisko;
  2.  
  3. import dissimlab.monitors.MonitoredVar;
  4. import dissimlab.simcore.BasicSimObj;
  5. import dissimlab.simcore.SimContext;
  6. import dissimlab.simcore.SimControlException;
  7. import dissimlab.random.SimGenerator;
  8. import dissimlab.simcore.SimManager;
  9.  
  10. public class Lotnisko extends BasicSimObj {
  11. int inTheAir; // liczba samolotów w powietrzu
  12. int onTheGround; // liczba samolotów czekających na lotnisku
  13. boolean runwayFree; // dostępność pasa lądowania
  14. int arrivalInterval; // okres pomiedzy kolejnymi przylotami
  15. int arrivalTime; // czas następnego przylotu
  16. int landingTime; // czas zakończenia lądowania
  17. int landingDuration; // czas trwania lądowania
  18. int departureInterval; // okres pomiędzy odlotami
  19. int departureTime; // czas następnego odlotu
  20. int i=0;
  21. int x=0;
  22. int petla=0;
  23. int petla2;
  24.  
  25.  
  26. int tablica;
  27. int Samoloty[] = new int [50];
  28. boolean Priorytet[] = new boolean [50];
  29. boolean Widoczny[] = new boolean [50];
  30. SimGenerator simgenerator = new SimGenerator();
  31. SimStep krokSymulacyjny;
  32. MonitoredVar mvOnTheGround, mvInTheAir, mvRunwayFree;
  33.  
  34. public Lotnisko(int arrivalInterval, int landingDuration, int departureInterval, int period, SimManager simMgr)
  35. throws SimControlException {
  36. this.inTheAir = 0;
  37. this.onTheGround = 0;
  38. this.runwayFree = true;
  39. this.arrivalTime = 1;
  40. this.landingTime = 0;
  41. this.departureTime = 0;
  42. this.arrivalInterval = arrivalInterval;
  43. this.landingDuration = landingDuration;
  44. this.departureInterval = departureInterval;
  45. krokSymulacyjny = new SimStep(this, period);
  46. mvOnTheGround = new MonitoredVar(simMgr);
  47. mvInTheAir = new MonitoredVar(simMgr);
  48. mvRunwayFree = new MonitoredVar(simMgr);
  49. mvRunwayFree.setValue(1);
  50. mvInTheAir.setValue(0);
  51. mvOnTheGround.setValue(0);
  52.  
  53.  
  54. }
  55.  
  56. public void arrival() {
  57.  
  58. if (simTime() == arrivalTime) {
  59. this.i++;//cyfra samolotu
  60. Samoloty[this.x]=this.i; //tablica z cyframi samolotów
  61.  
  62. Priorytet[this.x]= simgenerator.probability(0.5); //ten sam numer szufladki dla dwoch tablic tutaj priorytety
  63. Widoczny[this.x]=true;
  64.  
  65. arrivalTime += arrivalTime;
  66.  
  67. inTheAir++;
  68. mvInTheAir.setValue(inTheAir);
  69. System.out.println(
  70. simTime() + " - Przybył samolot " + Samoloty[this.x] +" z priorytetem: "+ Priorytet[this.x]+ ". Nad lotniskiem aktualnie jest: " + inTheAir + " samolot(ów)");
  71. this.x++;//plusujemy szufladke danego samolotu
  72. if (runwayFree) {
  73. runwayFree = false;
  74. mvRunwayFree.setValue(0);
  75. landingTime = (int) simTime() + landingDuration;
  76. System.out.println(simTime() + " - Zaplanowano lądowanie");
  77. }
  78. }
  79. }
  80.  
  81. public void landing() {
  82. if (simTime() == landingTime)
  83. if (inTheAir > 0) {
  84.  
  85. inTheAir--;
  86. mvInTheAir.setValue(inTheAir);
  87. onTheGround++;
  88. mvOnTheGround.setValue(onTheGround);
  89.  
  90. label:
  91. while(petla<=this.x){
  92. if (Priorytet[petla]&&Widoczny[petla]) {
  93. this.tablica=petla;
  94. Widoczny[petla]=false;
  95. break;
  96. }else if(petla == this.x && !Priorytet[petla]) {
  97. while (petla2 < this.x) {
  98. if (!Priorytet[petla2] && Widoczny[petla2]) {
  99. this.tablica = petla2;
  100. Widoczny[petla2] = false;
  101. break label;
  102. }else{
  103. petla2++;
  104. }
  105. }
  106. }
  107. else{
  108. petla++;
  109. }
  110. }
  111.  
  112. System.out.println(simTime() + " - Wylądował samolot " + Samoloty[this.tablica] + " z priorytetem " + Priorytet[this.tablica] + ". Na płycie altualnie jest: " + onTheGround
  113. + " a w powietrzu " + inTheAir + " samolot(ów)");
  114. if (onTheGround==1)
  115. departureTime = (int) simTime() + departureInterval;
  116. if (inTheAir > 0) {
  117. landingTime = (int) simTime() + landingDuration;
  118. System.out.println(simTime() + " - Zaplanowano lądowanie");
  119. } else {
  120. runwayFree = true;
  121. mvRunwayFree.setValue(1);
  122. System.out.println(simTime() + " - Zwolniono pas lądowania");
  123. }
  124. }
  125. }
  126.  
  127. public void departure() {
  128. if (simTime() == departureTime)
  129. if (onTheGround > 0) {
  130. onTheGround--;
  131. mvOnTheGround.setValue(onTheGround);
  132. System.out.println(
  133. simTime() + " - Odleciał samolot. Na płycie altualnie jest: " + onTheGround + " samolot(ów)");
  134. if (onTheGround>0)
  135. departureTime = (int) simTime() + departureInterval;
  136. }
  137. }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement