Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions

Question

Why is the design of one's first permanent job so important?

Answered: 1 week ago

Question

5. If yes, then why?

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago