Question: Check my code and see the error preventing it to run successsfully most especially in the pom.xml and update it for me . #Dijkstra.java package

Check my code and see the error preventing it to run successsfully most especially in the pom.xml and update it for me.
#Dijkstra.java
package org.example;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.graph.Node;
import org.graphstream.graph.Edge;
import java.util.Arrays;
public class Dijkstra {
private static final int INFINITY = Integer.MAX_VALUE;
private static final int UNDEFINED =-1;
public static void dijkstra(int[][] graph, int source){
int n = graph.length;
int[] dist = new int[n];
int[] prev = new int[n];
boolean[] visited = new boolean[n];
Arrays.fill(dist, INFINITY);
Arrays.fill(prev, UNDEFINED);
dist[source]=0;
for (int i =0; i < n; i++){
int u =-1;
for (int j =0; j < n; j++){
if (!visited[j] && (u ==-1|| dist[j]< dist[u])){
u = j;
}
}
if (dist[u]== INFINITY) break;
visited[u]= true;
for (int v =0; v < n; v++){
if (graph[u][v]!=0 && dist[u]+ graph[u][v]< dist[v]){
dist[v]= dist[u]+ graph[u][v];
prev[v]= u;
}
}
}
System.out.println(Arrays.toString(dist));
System.out.println(Arrays.toString(prev));
// Create and visualize graph with GraphStream
visualizeGraph(graph, dist, prev, source);
}
private static void visualizeGraph(int[][] graph, int[] dist, int[] prev, int source){
Graph g = new SingleGraph("Dijkstra");
// Add nodes
for (int i =0; i < graph.length; i++){
Node node = g.addNode(String.valueOf(i));
node.setAttribute("ui.label", i +"("+ dist[i]+")");
}
// Add edges
for (int u =0; u < graph.length; u++){
for (int v =0; v < graph[u].length; v++){
if (graph[u][v]!=0){
Edge edge = g.addEdge(u +"-"+ v, String.valueOf(u), String.valueOf(v), true);
edge.setAttribute("ui.label", graph[u][v]);
}
}
}
// Highlight shortest paths
for (int v =0; v < prev.length; v++){
if (prev[v]!= UNDEFINED){
Edge edge = g.getEdge(prev[v]+"-"+ v);
if (edge != null){
edge.setAttribute("ui.style", "fill-color: red;");
}
}
}
try {
g.display();
} catch (Exception e){
// Handle the exception and provide an alternative visualization
System.err.println("Failed to launch the viewer. Exception: "+ e.getMessage());
alternativeVisualizeGraph(graph, dist, prev);
}
}
private static void alternativeVisualizeGraph(int[][] graph, int[] dist, int[] prev){
System.out.println("Graph visualization using text:");
for (int i =0; i < graph.length; i++){
for (int j =0; j < graph[i].length; j++){
if (graph[i][j]!=0){
System.out.println("Edge between "+ i +" and "+ j +" with weight "+ graph[i][j]);
}
}
}
System.out.println("Shortest paths:");
for (int v =0; v < prev.length; v++){
if (prev[v]!= UNDEFINED){
System.out.println("Edge from "+ prev[v]+" to "+ v +" in the shortest path");
}
}
}
public static void main(String[] args){
int[][] graph ={
{0,7,9,0,0,14},
{7,0,10,15,0,0},
{9,10,0,11,0,2},
{0,15,11,0,6,0},
{0,0,0,6,0,9},
{14,0,2,0,9,0}
};
dijkstra(graph,0);
}
}
#Maven pom.xml
4.0.0
org.example
Dijkstra
1.0-SNAPSHOT
22
22
UTF-8
org.graphstream
gs-core
2.0
#Error Message
[0,7,9,20,20,11]
[-1,0,0,2,5,2]
Failed to launch the viewer. Exception: Cannot launch viewer.
Graph visualization using text:
Edge between 0 and 1 with weight 7
Edge between 0 and 2 with weight 9
Edge between 0 and 5 with weight 14
Edge between 1 and 0 with weight 7
Edge between 1 and 2 with weight 10

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 Programming Questions!