Advertisement
Tal_Rofe

algo

Jan 14th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. public void insertOrderedCar(Car car, int entryTime, int exitTime){
  2.         boolean fullPark = !this.checkAvailablePark(entryTime, exitTime);
  3.         if(fullPark){
  4.             // Send message to server: insertion command failed
  5.         }
  6.        
  7.         else{
  8.             int[] a = locateOptimalPosition(entryTime, exitTime);
  9.             statusPark[a[0]][a[1]][a[2]] = 'o';
  10.             park[a[0]][a[1]][a[2]].add(car);
  11.         }
  12.     }
  13.    
  14.     public void insertCar(Car car, int entryTime, int exitTime){
  15.         boolean fullPark = !this.checkAvailablePark(entryTime, exitTime);
  16.         if(fullPark){
  17.             // Send message to server: insertion command failed
  18.         }
  19.        
  20.         else{
  21.             int[] a = locateOptimalPosition(entryTime, exitTime);
  22.             ArrayList<Car> list = new ArrayList<Car>();
  23.             ejectInDepth(list, a[0], a[1], a[2]);
  24.             ejectInFloor(list, a[0], a[1], a[2]);
  25.             list.add(car);
  26.             Collections.sort(list);
  27.            
  28.             while (!list.isEmpty()){
  29.                 int t = 0;
  30.                 while (t != a[1] + 1){
  31.                     if (statusPark[a[0]][t][a[2]] != 's' && statusPark[a[0]][t][a[2]] != 'i'){
  32.                         while (list.get(0).getEntryTime() >=
  33.                                 park[a[0]][t][a[2]].get(park[a[0]][t][a[2]].size() - 1).getExitTime()){
  34.                            
  35.                                     park[a[0]][t][a[2]].add(list.get(0));
  36.                                     list.remove(0);
  37.                                    
  38.                                 }
  39.                         if (!isEmptySpotRealTime(a[0], t, a[2]))
  40.                             statusPark[a[0]][t][a[2]] = 'f';
  41.                        
  42.                         if (isEmptyButOrderedRealTime(a[0], t, a[2]))
  43.                             statusPark[a[0]][t][a[2]] = 'o';
  44.                     }
  45.                     t++;
  46.                 }
  47.                
  48.                 t = 0;
  49.                 while (t != a[0] + 1){
  50.                     if (statusPark[t][a[1]][a[2]] != 's' && statusPark[t][a[1]][a[2]] != 'i'){
  51.                         while (list.get(0).getEntryTime() >=
  52.                                 park[t][a[1]][a[2]].get(park[t][a[1]][a[2]].size() - 1).getExitTime()){
  53.                            
  54.                                     park[t][a[1]][a[2]].add(list.get(0));
  55.                                     list.remove(0);
  56.                                    
  57.                                 }
  58.                        
  59.                         if (!isEmptySpotRealTime(t, a[1], a[2]))
  60.                             statusPark[t][a[1]][a[2]] = 'f';
  61.                         if (isEmptyButOrderedRealTime(t, a[1], a[2]))
  62.                             statusPark[a[0]][t][a[2]] = 'o';
  63.                     }
  64.                     t++;
  65.                 }
  66.             }
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement