Question: My apologies for forgetting to specify what language needs to be used. Please use Java! Thank you. 1. Develop theprintPath(int fromNode, int toNode) method in

My apologies for forgetting to specify what language needs to be used. Please use Java! Thank you.

1. Develop theprintPath(int fromNode, int toNode) method in FloydWarshall class for printing names of the roads on the shortest path form fromNode to toNode.

2. Add the following methods to the FloydWarshall class:

public String[][] getNameOfStreets() { return nameOfStreets; }

public int[][] getAdjacencyMatrix() { return adjacencyMatrix; }

public int[][] getNextToMatrix() { return comeFromMatrix; }

3. Develop the getDeliveryRoute(FloydWarshall graph, ArrayList deliveryList) method in ShortestDeliveryPath class as the main method.

FloydWarshall.java

import java.util.ArrayList; import java.util.List; import java.util.Vector;

public class FloydWarshall { int[][] adjacencyMatrix; // stores shortest distance from i to j /* stores previous node (to go to j) of shortest path from i to j * stores where we to go before from i for reaching j from i */ int[][] comeFromMatrix; String[][] nameOfStreets;

public FloydWarshall(int numberOfNodes) { this.adjacencyMatrix = new int[numberOfNodes][numberOfNodes]; this.comeFromMatrix = new int[numberOfNodes][numberOfNodes]; this.nameOfStreets = new String[numberOfNodes][numberOfNodes]; //Initialize the matrix for (int i = 0; i < adjacencyMatrix.length; i++) { for (int j = 0; j < adjacencyMatrix[i].length; j++) { //if it is itself if (i == j) { this.adjacencyMatrix[i][j] = 0; this.comeFromMatrix[i][j] = i; } else { //if it is not itself this.adjacencyMatrix[i][j] = Integer.MAX_VALUE; this.comeFromMatrix[i][j] = -1; } } } }

// Write your methods here

public void addEdge(int fromNode, int toNode, int length , String streetName) { if (length < adjacencyMatrix[fromNode][toNode]) { adjacencyMatrix[fromNode][toNode] = length; comeFromMatrix[fromNode][toNode] = fromNode; nameOfStreets[fromNode][toNode] = streetName; } }

public Vector path(int fromNode, int toNode) { //define return Vector pathSqeuence = new Vector<>(); //check if there is a path if (comeFromMatrix[fromNode][toNode] == -1) return pathSqeuence; //go backwards until where we start int reachedFromNode = toNode; while (fromNode != reachedFromNode) { //add node to path pathSqeuence.add(0, reachedFromNode); //update reached from node reachedFromNode = comeFromMatrix[fromNode][reachedFromNode]; } pathSqeuence.add(0, fromNode); return pathSqeuence; }

public void run() { //for each intermediate node for (int k = 0; k < adjacencyMatrix.length; k++) { //for each from node for (int i = 0; i < adjacencyMatrix.length; i++) { //if there is no path from i to k skip if (adjacencyMatrix[i][k] >= Integer.MAX_VALUE) continue; //for each to node for (int j = 0; j < adjacencyMatrix.length; j++) { //if there is no path from k to j skip if (adjacencyMatrix[k][j] >= Integer.MAX_VALUE) continue; //if path from i to j is shorter with stopping at k then update path if (adjacencyMatrix[i][k] + adjacencyMatrix[k][j] < adjacencyMatrix[i][j]) { adjacencyMatrix[i][j] = adjacencyMatrix[i][k] + adjacencyMatrix[k][j]; comeFromMatrix[i][j] = comeFromMatrix[k][j]; } } } } } /** * @param fromNode * @param toNode * * @return */ public ArrayList printPath(int fromNode, int toNode) { return null; }

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. */ } }

ShortestDeliveryPath.java

import java.util.ArrayList;

public class ShortestDeliveryPath {

/** * @param graph * @param deliveryList * * @return */ public static ArrayList getDeliveryRoute(FloydWarshall graph, ArrayList deliveryList) { return null; } }

Shipment.java

import java.time.LocalTime;

public class Shipment {

private double weight; private long barcodeNumber; private int fromNode; private int toNode; private LocalTime deliveryTimeDue; public Shipment(double weight, long barcodeNumber, int fromNode, int toNode, LocalTime deliveryTimeDue) { super(); this.weight = weight; this.barcodeNumber = barcodeNumber; this.fromNode = fromNode; this.toNode = toNode; this.deliveryTimeDue = deliveryTimeDue; }

public int getFromNode() { return fromNode; }

public double getWeight() { return weight; }

public long getBarcodeNumber() { return barcodeNumber; }

public int getToNode() { return toNode; }

public LocalTime getDeliveryTimeDue() { return deliveryTimeDue; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!