Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA (This problem is due at midnight. I've provided all of the info that I have. Please help, thank you.) Objectives Develop an algorithm to

JAVA

(This problem is due at midnight. I've provided all of the info that I have. Please help, thank you.)

Objectives

  • Develop an algorithm to find shipment installation sequence for a transportation company
  • Prepare a suitable data structure for the given problem

Scenario

Next Day Cargo Company promise their customers that any cargo given to any of their branches until 5 pm will be delivered (nationally) the next day. To achieve this goal, they operate as follows;

  • They collect cargo during the daytime (until 5 pm)

  • They send all cargo to distribution hubs in the evening

  • When the cargo reached to the distribution centers, they group cargo with respect to delivery address; which is the corresponding distribution centers for corresponding addresses (Figure 2.1)

image text in transcribed

Figure 2.1: Cargo Collection Operations

  • Throughout the night, cargo trucks transport the cargo between the distribution centers

  • In the early hours of the morning, each distribution center groups and delivers the cargo for corresponding cargo branches (Figure 2.2)

image text in transcribed

Figure 2.2: Cargo Distribution Operations During the Night

  • Each cargo branch groups the cargo and loads to delivery trucks or vans in the morning and deliver the cargo during the daytime (Figure 2.3)

image text in transcribed

Figure 2.3: Cargo Distribution Operations During the Daytime

While they are doing these operations, they have to load trucks/vans many times. These loadings of cargo to trucks has a proper sequence to follow, which is prioritized by the weight of each cargo. Having heavy cargo first loaded has the following advantages;

  1. Low center of gravity for each vehicle; causing more stable vehicle while driving,

  2. Heavy cargo items more likely to be durable, and light cargo can be carried easily on top of them. The reverse of this situation, light cargo on the bottom and heavy cargo on top can cause several damages to the light cargo on the bottom.

Next Day Cargo company is a nationwide company with at least one distribution center for each city and branch for almost every district. They have such a big distribution network, a small failure or delay will have a domino effect on this network and distribution operations.

Next Day Cargo Company needs an integrated application with their system that sorts the cargo with respect to their weight and distributes the weight evenly (if possible) between the given vehicles.

Note that each vehicle has a weight limit, and cannot exceed it. But each vehicle can be used more than once during these operations. And do not forget, they want a fast solution because waiting a long time for the algorithm to complete reports will risk their motto, which is Next Day Cargo.

They require a report which will be used as a work order for workers and truck drivers as it shows the order of load for each vehicle. The report/order will have the following four columns:

Number (which will be the loading sequence), Barcode Number, Weight, Postal Code.

Our team has worked on API architecture and concluded in the solution given in Figure 2.4. In this API there are two main steps, which are explained as follows;

  1. Sort the shipments: We are planning to use merge sort algorithm. Sorting must be from heaviest to lightest.

  2. Distribute the sorted shipments to vehicles: To distribute shipments to available vehicles there are some restriction/request as follows;

    • There is a list of available vehicles, in which a vehicle can be used more than once if needed.

    • Total weight of assigned shipments to a vehicle cannot exceed its weight capacity.

    • Order of assignments must be from heaviest to lightest which will be used as a loading order.

image text in transcribed

Figure 2.4: Method Details

For the distribution of cargo to vehicles the following steps are considered;

Take each cargo in the given order,

Take a vehicle and calculate the total weight of the taken cargo assigned to the taken vehicle,

If the capacity of the vehicle is not exceed, assign the cargo to the vehicle,

If not, select another vehicle until a suitable vehicle is found.

Vehicle and Shipment classes are completed in the API.LoadsOfVehicle and Sort classes need implementations.

In order to sort the shipments by weight, you will need to implement the sortShipmentsByWeight method in the Sort.java file. To implement the sortShipmentsByWeight you will need to implement the following two methods mergeSortShipmentsByWeight and merge method.

mergeSortShipmentsByWeight will take three arguments, an array of shipments, a start index and an end index. This method should recursively call itself until the shipment has been sorted.

The merge method should merge two halves of the sorted shipment.

REQUIRED TASKS:

1. Develop the sortShipmentsByWeight() method in the Sort.java file to sort cargo from heaviest to lightest.

The shipments now need to be distributed evenly among the vehicles. Each vehicle can do multiple transfers and can be used more than once if needed, but the weight limit of each vehicle cannot be exceeded.

The first method to implement is distributeShipmentsToVehicles which will return the maximum weight per load for each vehicle. Once the maximum capacity per vehicle has been calculated, the shipments need to be loaded onto the vehicle using the loadTheVehicles method.

2. Develop the distributeShipmentsToVehicles method to evenly distribute weight between transportation vehicles but do not exceed the weight limit of each vehicle. (Each vehicle can do multiple transfers/can be used more than once if needed)

3. Implement the loadTheVehicles method to load the shipments into the vehicles, the total capacity of the vehicles must be greater than the total weight of the shipment.

4. Implement the getLoadReport method in the LoadsOfVehicle.java file to generate a report.

GIVEN CODE:

public class Sort {

/** * @param shipments * @param vehicles * @return */ public static LoadsOfVehicle[] getLoadingArray(Shipment[] shipments, Vehicle[] vehicles) { return null; }

/** * @param shipmentsToSort */ public static void sortShipmentsByWeight(Shipment[] shipmentsToSort) { } /** * @param shipmentsToSort * @param start * @param end */ private static void mergeSortShipmentsByWeight(Shipment[] shipmentsToSort, int start, int end) { }

/** * @param array * @param start * @param middle * @param end */ private static void merge(Shipment[] array, int start, int middle, int end) { }

/** * @param sortedShipments * @param vehicles * @return */ public static LoadsOfVehicle[] distributeShipmentsToVehicles( Shipment[] sortedShipments, Vehicle[] vehicles) { //calculate total weight of shipments

//calculate total weight capacity of vehicles

//if capacity of vehicles is not enough add more turns for vehicles

//define return array with extra vehicle turns

//use modulus to add vehicles more than once if needed

//distribute weight to vehicles

return null; }

/** * @param vehicleListToLoad * @param sortedShipments */ public static void loadTheVehicles(LoadsOfVehicle[] vehicleListToLoad, Shipment[] sortedShipments) { //while there is more cargo to load //distribute weight over vehicles //calculate total weight if current weight is loaded //there is a cargo to load and vehicle has the capacity //load cargo to vehicle //If no more cargo to load break while loop }

public static void main(String[] args) { /* * This main method is a stub. * It does nothing. * Feel free to write your own code to test your implementation. * In this case, we have nothing actionable in here, just this comment block, so the JVM should rapidly lose interest and move on to the rest of your code. */ } }

Additional Code

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Brahch Branch Branch Branch BARBAI Distribution Center LA BARBARA Distribution Center Branch Branch Branch Branch LABARBARA Distribution Center BABAARS Distribution Center Branch Get Loading Array Sort Shipments by Weight Merge Sort wrt Weight Merge Distribute Shipments To Vehicles - - - Sort Shipments > Merge Sort - - Merge Sort - - > Merge Sorted - - Merge Sorted Merge - - Sorted Shipments Merged - - - Distribute the Cargo to Vehicles Distributed Cargo List - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Sort.java * SampleReport.txt x Vehicle.java LoadsOfVehicle.ja... X Shipment.java x +. public double getVehicleCapacity() { return vehicle.getWeightCapacity(); public String getVehiclePlate() { return vehicle.getPlate(); public String getVehicleDriver() { return vehicle.getDriver Name(); /**This methods generates report for the vehicle and the * the shipments in it wrt weight (from heaviest to lightest) * @return generated report O CON UN CON UN COW NO public String getLoadReport() { return null; /**This method takes vehicles and their loadings as input and * generates report for each vehicle * @param LoadsOfVehicles vehicle and loadings array * @return a report for each vehicle showing loading sequence public static String[] getReports(LoadsOfVehicle[] loadsOfVehicles) { return null; Sort.java x SampleReport.txt * Vehicle.java * LoadsofVehicle.ja... * Shipment.java 1 public class Shipment { private double weight; private long barcodeNumber; private int fromPostal Code; private int toPostal Code; public Shipment (double weight, long barcodeNumber, int fromPostal Code, int to Postal Code) { super(); this weight = weight; this.barcodeNumber = barcodeNumber; this. fromPostal Code = fromPostal Code; this.toPostal Code = toPostal Code; public int getFromPostal Code() { return fromPostal Code; public double getWeight() { return weight; public long getBarcodeNumber() { return barcodeNumber; public int getToPostalCode() { return to Postal Code; } 30 Igorithms and Fundamental Data Structures Sort.java * SampleReport.txt Vehicle.java * LoadsOfVehicle.ja... * Shipment.java * + public class Vehicle { private double weightCapacity: private String plate; private String driver Name; public Vehicle (double weightCapacity, String plate, String driver Name) { super(); this.weightCapacity = weightCapacity; this.plate = plate; this.driver Name = driver Name; 10 11 12 public double getWeightCapacity() { return weightCapacity: 16 17 18 19 public String getPlate() { return plate; 20 21 public String getDriver Name() { return driver Name; 22 23 24 25 26 27 28 29} public void setDriverName(String driver Name) { this.driver Name = driver Name; } Sort.java X SampleReport.txt Vehicle.java * LoadsOfVehicle.ja... X Shipment.java + Vehicle Plate : KZ66 ZYT - Weight Limit : 10.00 Driver John Locke Loading Sequence ------ - --------- ---- Ni Ni D Barcode Number Weight Delivery Address Postal Code ------ 2147253625 2.000 34547 2147043627 0.750 34543 ------ --- 2.750 ------- Vehicle Plate : SBG 984 Weight Limit: 20.00 Driver : Down Brown Loading Sequence Barcode Number Weight Delivery Address Postal Code ------ 2147013624 20.000 34546 ------ - 20.000 ------ Vehicle Plate : EKI6 LLO Weight Limit : 50.00 Driver Adam Smith Loading Sequence Barcode Number Weight Delivery Address Postal Code - --- wi w Ni 2147313623 2147013628 2147014626 15.000 1.250 0.500 34543 34543 34542 16.750 Brahch Branch Branch Branch BARBAI Distribution Center LA BARBARA Distribution Center Branch Branch Branch Branch LABARBARA Distribution Center BABAARS Distribution Center Branch Get Loading Array Sort Shipments by Weight Merge Sort wrt Weight Merge Distribute Shipments To Vehicles - - - Sort Shipments > Merge Sort - - Merge Sort - - > Merge Sorted - - Merge Sorted Merge - - Sorted Shipments Merged - - - Distribute the Cargo to Vehicles Distributed Cargo List - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Sort.java * SampleReport.txt x Vehicle.java LoadsOfVehicle.ja... X Shipment.java x +. public double getVehicleCapacity() { return vehicle.getWeightCapacity(); public String getVehiclePlate() { return vehicle.getPlate(); public String getVehicleDriver() { return vehicle.getDriver Name(); /**This methods generates report for the vehicle and the * the shipments in it wrt weight (from heaviest to lightest) * @return generated report O CON UN CON UN COW NO public String getLoadReport() { return null; /**This method takes vehicles and their loadings as input and * generates report for each vehicle * @param LoadsOfVehicles vehicle and loadings array * @return a report for each vehicle showing loading sequence public static String[] getReports(LoadsOfVehicle[] loadsOfVehicles) { return null; Sort.java x SampleReport.txt * Vehicle.java * LoadsofVehicle.ja... * Shipment.java 1 public class Shipment { private double weight; private long barcodeNumber; private int fromPostal Code; private int toPostal Code; public Shipment (double weight, long barcodeNumber, int fromPostal Code, int to Postal Code) { super(); this weight = weight; this.barcodeNumber = barcodeNumber; this. fromPostal Code = fromPostal Code; this.toPostal Code = toPostal Code; public int getFromPostal Code() { return fromPostal Code; public double getWeight() { return weight; public long getBarcodeNumber() { return barcodeNumber; public int getToPostalCode() { return to Postal Code; } 30 Igorithms and Fundamental Data Structures Sort.java * SampleReport.txt Vehicle.java * LoadsOfVehicle.ja... * Shipment.java * + public class Vehicle { private double weightCapacity: private String plate; private String driver Name; public Vehicle (double weightCapacity, String plate, String driver Name) { super(); this.weightCapacity = weightCapacity; this.plate = plate; this.driver Name = driver Name; 10 11 12 public double getWeightCapacity() { return weightCapacity: 16 17 18 19 public String getPlate() { return plate; 20 21 public String getDriver Name() { return driver Name; 22 23 24 25 26 27 28 29} public void setDriverName(String driver Name) { this.driver Name = driver Name; } Sort.java X SampleReport.txt Vehicle.java * LoadsOfVehicle.ja... X Shipment.java + Vehicle Plate : KZ66 ZYT - Weight Limit : 10.00 Driver John Locke Loading Sequence ------ - --------- ---- Ni Ni D Barcode Number Weight Delivery Address Postal Code ------ 2147253625 2.000 34547 2147043627 0.750 34543 ------ --- 2.750 ------- Vehicle Plate : SBG 984 Weight Limit: 20.00 Driver : Down Brown Loading Sequence Barcode Number Weight Delivery Address Postal Code ------ 2147013624 20.000 34546 ------ - 20.000 ------ Vehicle Plate : EKI6 LLO Weight Limit : 50.00 Driver Adam Smith Loading Sequence Barcode Number Weight Delivery Address Postal Code - --- wi w Ni 2147313623 2147013628 2147014626 15.000 1.250 0.500 34543 34543 34542 16.750

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

Know the components of a position description

Answered: 1 week ago

Question

Explain the value of a true open-door policy

Answered: 1 week ago