diff --git a/Winda/src/winda/logic/AlgorytmGoraDol.java b/Winda/src/winda/logic/AlgorytmGoraDol.java index 5ea965a..a37495e 100644 --- a/Winda/src/winda/logic/AlgorytmGoraDol.java +++ b/Winda/src/winda/logic/AlgorytmGoraDol.java @@ -1,8 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - package winda.logic; import java.util.ArrayList; @@ -12,6 +7,9 @@ import sun.misc.Sort; /** * Algortym poruszania się windą przy wsiadaniu pasażerów * jadących tylko w kierunku w którym porusza się winda. + * + * Napisane nie testowane + * * @author Przemo */ public class AlgorytmGoraDol implements IAlgorytm { @@ -23,6 +21,12 @@ public class AlgorytmGoraDol implements IAlgorytm { public AlgorytmGoraDol(){ this.start_floor = 0; + this.floor_count = 0; + } + + public AlgorytmGoraDol(int floor_count){ + this.start_floor = 0; + this.floor_count = floor_count; } public AlgorytmGoraDol(int floor_count, int start_floor){ @@ -50,13 +54,14 @@ public class AlgorytmGoraDol implements IAlgorytm { Sort.quicksort(array.toArray(), null); } - private void goUp(){ + private void goUp(int to){ int i =0; ArrayList tmp = new ArrayList(); while(this.pasazerowie[i].GetStart() sortDown(ArrayList array){ + Sort.quicksort(array.toArray(), null); + ArrayList tmp = new ArrayList(); + for(int i= (array.size()-1);i>=0;i--) + tmp.add(array.get(i)); + return tmp; + } + + private void goDown(int to){ + int i =0; + ArrayList tmp = new ArrayList(); + while(this.pasazerowie[i].GetStart()this.pasazerowie[i].GetStop()&& + this.pasazerowie[i].GetStart()>to){ + if(tmp.contains(this.pasazerowie[i].GetStart())) + tmp.add(this.pasazerowie[i].GetStart()); + if(tmp.contains(this.pasazerowie[i].GetStop())) + tmp.add(this.pasazerowie[i].GetStop()); + } + tmp = this.sortDown(tmp); + this.floors.addAll(tmp); + } public int[] setCourse(){ this.floors = new ArrayList(); @@ -73,6 +103,20 @@ public class AlgorytmGoraDol implements IAlgorytm { PasazerSort sort = new PasazerSort(pasazerowie); sort.sortByStart(); this.acctual_floor = this.start_floor; + + /* Jeżeli winda jest poniżej połowy */ + if((this.floor_count/2)>this.acctual_floor){ + this.goDown(0); + this.goUp(this.floor_count); + this.goDown(this.start_floor); + } + else{ + this.goUp(0); + this.goDown(this.floor_count); + this.goUp(this.start_floor); + } + + int []ret = new int[floors.size()]; for(int i=0;i Trasa(List pasazerowie) { throw new UnsupportedOperationException("Not supported yet."); } + }