M Winda/src/winda/logic/AlgorytmGoraDol.java Poprawiona wersja algorytmu
This commit is contained in:
parent
1c4a2c25f0
commit
b71315453d
1 changed files with 53 additions and 8 deletions
|
@ -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<Integer> tmp = new ArrayList<Integer>();
|
||||
while(this.pasazerowie[i].GetStart()<this.acctual_floor)
|
||||
i++;
|
||||
while(i<this.pasazerowie.length)
|
||||
if(this.pasazerowie[i].GetStart()<this.pasazerowie[i].GetStop()){
|
||||
if( 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()))
|
||||
|
@ -66,6 +71,31 @@ public class AlgorytmGoraDol implements IAlgorytm {
|
|||
this.floors.addAll(tmp);
|
||||
}
|
||||
|
||||
private ArrayList<Integer> sortDown(ArrayList<Integer> array){
|
||||
Sort.quicksort(array.toArray(), null);
|
||||
ArrayList<Integer> 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<Integer> tmp = new ArrayList<Integer>();
|
||||
while(this.pasazerowie[i].GetStart()<this.acctual_floor)
|
||||
i++;
|
||||
while(i<this.pasazerowie.length)
|
||||
if( 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<Integer>();
|
||||
floors.add(this.start_floor);
|
||||
|
@ -74,6 +104,20 @@ public class AlgorytmGoraDol implements IAlgorytm {
|
|||
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<floors.size();i++)
|
||||
ret[i] = floors.get(i).intValue();
|
||||
|
@ -86,10 +130,11 @@ public class AlgorytmGoraDol implements IAlgorytm {
|
|||
}
|
||||
|
||||
public void SetMaxPietro(int maxPietro) {
|
||||
this.setFloorCount(maxPietro);
|
||||
this.setFloorCount(floor_count);
|
||||
}
|
||||
|
||||
public List<Pietro> Trasa(List<Pasazer> pasazerowie) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue