I'm trying to implement Dijkstra's algorithm using edges/nodes but it runs so slowly when i add edges to the nodes. The overall goal is to use dijkstra's to determine the shortest route from one point on a map to another using javaFX to show the map of rome. The way i'm doing it atm is converting the map to black/white with all pixels acting as nodes, to add the edges im checking if nodes beside or underneath are both white(representing the road on the map) and adding an edge between them if they are.
public static List<Node> createEdgesBetweenNodes(Image image, List<Node> nodes){
for (int i = 0; i < nodes.size();i++) {
//If node is black ignore and continue
//if (nodes.get(i).getName() == "0x000000ff") continue;
//if white, check if node to the right is also white
if ((i+1) % (int) image.getWidth() != 0) {
if (i+1 < nodes.size()) {
if (nodes.get(i + 1).getName().equals("0xffffffff")) {
addLane("Edge_"+i,nodes.get(i),nodes.get(i+1),1);
}
}
}
//Checking node underneath
if (!(i + image.getWidth() >= nodes.size())) {
if (nodes.get((int) (i + image.getWidth())).getName().equals("0xffffffff")) {
addLane("Edge_"+i,nodes.get(i),nodes.get((int) (i+image.getWidth())),1);
}
}
} return nodes;
}
Although it 'works' it takes forever to load and anything over 40/50 pixels between the nodes it just crashes so i'm obviously being very inefficient and need some help!
User contributions licensed under CC BY-SA 3.0