Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. /*************
  2. for generating trucks and boxes
  3. **************/
  4. public static ArrayList<Box> generateBoxes(int size)
  5. {
  6. ArrayList<Box> boxes = new ArrayList<Box>();
  7.  
  8. for (int i = 0; i < size; i ++)
  9. {
  10. boxes.add(new Box(generateWidth(), generateHeight(),
  11. generateColour()));
  12. }
  13.  
  14. return boxes;
  15. }
  16.  
  17. public static ArrayList<Truck> generateTrucks(int size)
  18. {
  19. ArrayList<Truck> trucks = new ArrayList<Truck>();
  20.  
  21. for (int i = 0; i < size; i ++)
  22. {
  23. trucks.add(new Truck(LaunchPlatform.getTruckWidth(), LaunchPlatform
  24. .getTruckHeight()));
  25. }
  26.  
  27. return trucks;
  28. }
  29. /*************
  30. end for generating trucks and boxes
  31. **************/
  32.  
  33. /*************
  34. for running algorithms
  35. **************/
  36. // Generate trucks
  37. onlineTrucks = TheGenerator.generateTrucks(numberOfBoxes);
  38. offlineTrucks = new ArrayList<Truck>(onlineTrucks);
  39. Collections.copy(offlineTrucks, onlineTrucks);
  40.  
  41. // Generate boxes
  42. onlineBoxes = TheGenerator.generateBoxes(numberOfBoxes);
  43. offlineBoxes = new ArrayList<Box>(onlineBoxes);
  44. Collections.copy(offlineBoxes, onlineBoxes);
  45.  
  46. // Run online algorithm and save the "solution"
  47. Solution onlineSolution = FirstFitAlgorithms.online(onlineTrucks, onlineBoxes);
  48.  
  49. // Run offline algorithm and save the "solution"
  50. Solution offlineSolution = FirstFitAlgorithms.offline(offlineTrucks, offlineBoxes);
  51.  
  52. // Clear all arraylists (in case user clicks 'run' button more than once)
  53. offlineTrucks.clear();
  54. onlineTrucks.clear();
  55. onlineBoxes.clear();
  56. offlineBoxes.clear();
  57. /*************
  58. end for running algorithms
  59. **************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement