Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lotnisko;
- import dissimlab.monitors.MonitoredVar;
- import dissimlab.simcore.BasicSimObj;
- import dissimlab.simcore.SimContext;
- import dissimlab.simcore.SimControlException;
- import dissimlab.random.SimGenerator;
- import dissimlab.simcore.SimManager;
- public class Lotnisko extends BasicSimObj {
- int inTheAir; // liczba samolotów w powietrzu
- int onTheGround; // liczba samolotów czekających na lotnisku
- boolean runwayFree; // dostępność pasa lądowania
- int arrivalInterval; // okres pomiedzy kolejnymi przylotami
- int arrivalTime; // czas następnego przylotu
- int landingTime; // czas zakończenia lądowania
- int landingDuration; // czas trwania lądowania
- int departureInterval; // okres pomiędzy odlotami
- int departureTime; // czas następnego odlotu
- int i=0;
- int x=0;
- int petla=0;
- int petla2;
- int tablica;
- int Samoloty[] = new int [50];
- boolean Priorytet[] = new boolean [50];
- boolean Widoczny[] = new boolean [50];
- SimGenerator simgenerator = new SimGenerator();
- SimStep krokSymulacyjny;
- MonitoredVar mvOnTheGround, mvInTheAir, mvRunwayFree;
- public Lotnisko(int arrivalInterval, int landingDuration, int departureInterval, int period, SimManager simMgr)
- throws SimControlException {
- this.inTheAir = 0;
- this.onTheGround = 0;
- this.runwayFree = true;
- this.arrivalTime = 1;
- this.landingTime = 0;
- this.departureTime = 0;
- this.arrivalInterval = arrivalInterval;
- this.landingDuration = landingDuration;
- this.departureInterval = departureInterval;
- krokSymulacyjny = new SimStep(this, period);
- mvOnTheGround = new MonitoredVar(simMgr);
- mvInTheAir = new MonitoredVar(simMgr);
- mvRunwayFree = new MonitoredVar(simMgr);
- mvRunwayFree.setValue(1);
- mvInTheAir.setValue(0);
- mvOnTheGround.setValue(0);
- }
- public void arrival() {
- if (simTime() == arrivalTime) {
- this.i++;//cyfra samolotu
- Samoloty[this.x]=this.i; //tablica z cyframi samolotów
- Priorytet[this.x]= simgenerator.probability(0.5); //ten sam numer szufladki dla dwoch tablic tutaj priorytety
- Widoczny[this.x]=true;
- arrivalTime += arrivalTime;
- inTheAir++;
- mvInTheAir.setValue(inTheAir);
- System.out.println(
- simTime() + " - Przybył samolot " + Samoloty[this.x] +" z priorytetem: "+ Priorytet[this.x]+ ". Nad lotniskiem aktualnie jest: " + inTheAir + " samolot(ów)");
- this.x++;//plusujemy szufladke danego samolotu
- if (runwayFree) {
- runwayFree = false;
- mvRunwayFree.setValue(0);
- landingTime = (int) simTime() + landingDuration;
- System.out.println(simTime() + " - Zaplanowano lądowanie");
- }
- }
- }
- public void landing() {
- if (simTime() == landingTime)
- if (inTheAir > 0) {
- inTheAir--;
- mvInTheAir.setValue(inTheAir);
- onTheGround++;
- mvOnTheGround.setValue(onTheGround);
- label:
- while(petla<=this.x){
- if (Priorytet[petla]&&Widoczny[petla]) {
- this.tablica=petla;
- Widoczny[petla]=false;
- break;
- }else if(petla == this.x && !Priorytet[petla]) {
- while (petla2 < this.x) {
- if (!Priorytet[petla2] && Widoczny[petla2]) {
- this.tablica = petla2;
- Widoczny[petla2] = false;
- break label;
- }else{
- petla2++;
- }
- }
- }
- else{
- petla++;
- }
- }
- System.out.println(simTime() + " - Wylądował samolot " + Samoloty[this.tablica] + " z priorytetem " + Priorytet[this.tablica] + ". Na płycie altualnie jest: " + onTheGround
- + " a w powietrzu " + inTheAir + " samolot(ów)");
- if (onTheGround==1)
- departureTime = (int) simTime() + departureInterval;
- if (inTheAir > 0) {
- landingTime = (int) simTime() + landingDuration;
- System.out.println(simTime() + " - Zaplanowano lądowanie");
- } else {
- runwayFree = true;
- mvRunwayFree.setValue(1);
- System.out.println(simTime() + " - Zwolniono pas lądowania");
- }
- }
- }
- public void departure() {
- if (simTime() == departureTime)
- if (onTheGround > 0) {
- onTheGround--;
- mvOnTheGround.setValue(onTheGround);
- System.out.println(
- simTime() + " - Odleciał samolot. Na płycie altualnie jest: " + onTheGround + " samolot(ów)");
- if (onTheGround>0)
- departureTime = (int) simTime() + departureInterval;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement