Fix error in line 57 No candidates found for method call node. addAttribute("ui. label", i + " (" + dist[i] + ")")., line 65 No candidates found for method call edge. addAttribute("ui. label", graph[u][v]).and line 75 No candidates found for method call edge. addAttribute("ui. style", "fill-color: red;") in the code below so that it can run succefully, 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 GraphStreamvisualizeGraph(graph, dist, prev, source);}private static void visualizeGraph(int[][] graph, int[] dist, int[] prev, int source) {Graph g = new SingleGraph("Dijkstra");// Add nodesfor (int i = 0; i < graph.length; i++) {Node node = g.addNode(String.valueOf(i));node.addAttribute("ui.label", i + " (" + dist[i] + ")");}// Add edgesfor (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.addAttribute("ui.label", graph[u][v]);}}}// Highlight shortest pathsfor (int v = 0; v < prev.length; v++) {if (prev[v] != UNDEFINED) {Edge edge = g.getEdge(prev[v] + "-" + v);if (edge != null) {edge.addAttribute("ui.style", "fill-color: red;");}}}g.display();}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);}}

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
1st Edition
ISBN:9780357392676
Author:FREUND, Steven
Publisher:FREUND, Steven
Chapter10: Data Analysis With Power Tools And Creating Macros
Section: Chapter Questions
Problem 5EYW
icon
Related questions
Question

Fix error in line 57 No candidates found for method call node. addAttribute("ui. label", i + " (" + dist[i] + ")").,

line 65 No candidates found for method call edge. addAttribute("ui. label", graph[u][v]).and

line 75 No candidates found for method call edge. addAttribute("ui. style", "fill-color: red;") in the code below so that it can run succefully,

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.addAttribute("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.addAttribute("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.addAttribute("ui.style", "fill-color: red;");
}
}
}

g.display();
}

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);
}
}
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Knowledge Booster
Convex Hull
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L