I used this example code:
https://github.com/jgrapht/jgrapht/wiki/DirectedGraphDemo to create a digraph. In this example, the Digraph is created with vertices that are Strings
. I need vertices to be points, which I designate with an iD in my code (iDs are going from 0 to 3 so these are int
). So I modified the example to do this:
public class DirectedGraphDemo {
public static void graph(int ... iD) {
// constructs a directed graph with the specified vertices and edges
DirectedGraph<int, DefaultEdge> directedGraph =
new DefaultDirectedGraph<int, DefaultEdge>
(DefaultEdge.class);
directedGraph.addVertex(0);
directedGraph.addVertex(1);
directedGraph.addVertex(2);
directedGraph.addVertex(3);
directedGraph.addEdge(0,1);
directedGraph.addEdge(1,2);
directedGraph.addEdge(2,3);
// computes all the strongly connected components of the directed graph
StrongConnectivityInspector sci =
new StrongConnectivityInspector(directedGraph);
List stronglyConnectedSubgraphs = sci.stronglyConnectedSubgraphs();
// prints the strongly connected components
System.out.println("Strongly connected components:");
for (int i = 0; i < stronglyConnectedSubgraphs.size(); i++) {
System.out.println(stronglyConnectedSubgraphs.get(i));
}
System.out.println();
// Prints the shortest path from vertex 0 to vertex 3. This certainly
// exists for our particular directed graph.
System.out.println("Shortest path from 0 to 3:");
List path =
DijkstraShortestPath.findPathBetween(directedGraph, 0, 3);
System.out.println(path + "\n");
}
}
However, I get the error "unexpected token int" at the line:
DirectedGraph<int, DefaultEdge> directedGraph =
I changed the arguments of the method to int
so why am I getting this error?