Skip to content
Snippets Groups Projects
Commit 0bb55692 authored by Pedro Pablo Cardona Arroyave's avatar Pedro Pablo Cardona Arroyave
Browse files

Dijkstra with out arrayList

parent b6ce66c3
Branches
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -19,6 +19,7 @@ public class Task9 { ...@@ -19,6 +19,7 @@ public class Task9 {
assert g != null; assert g != null;
g.loadEdges("kanter.txt"); g.loadEdges("kanter.txt");
int startNumber = 0; int startNumber = 0;
Dijkstra.getShortestPath(g,startNumber,3);
/*List<Edge> edges = Dijkstra.getShortestPath(g,startNumber,3); /*List<Edge> edges = Dijkstra.getShortestPath(g,startNumber,3);
Node node = g.getNode(startNumber); Node node = g.getNode(startNumber);
System.out.println(node.getLatitude() + "," + node.getLongitude()); System.out.println(node.getLatitude() + "," + node.getLongitude());
...@@ -232,7 +233,7 @@ class Graph{ ...@@ -232,7 +233,7 @@ class Graph{
class Dijkstra{ class Dijkstra{
public static List<Edge> getShortestPath(Graph graph, int startNumber, int destinationNumber){ public static int getShortestPath(Graph graph, int startNumber, int destinationNumber){
PriorityQueue<Edge> priorityQueue = new PriorityQueue<>(); PriorityQueue<Edge> priorityQueue = new PriorityQueue<>();
int[] pathWeight = new int[graph.getAdjacencyListSize()]; int[] pathWeight = new int[graph.getAdjacencyListSize()];
Arrays.fill(pathWeight, Integer.MAX_VALUE); Arrays.fill(pathWeight, Integer.MAX_VALUE);
...@@ -246,12 +247,12 @@ class Dijkstra{ ...@@ -246,12 +247,12 @@ class Dijkstra{
int currentSum = pathWeight[nextEdge.start()] + nextEdge.drivingTime(); int currentSum = pathWeight[nextEdge.start()] + nextEdge.drivingTime();
if(currentSum<pathWeight[nextNode]){ if(currentSum<pathWeight[nextNode]){
pathWeight[nextNode] = currentSum; pathWeight[nextNode] = currentSum;
pathToNodes[nextNode] = new ArrayList<>(pathToNodes[nextEdge.start()]); //pathToNodes[nextNode] = new ArrayList<>(pathToNodes[nextEdge.start()]);
pathToNodes[nextNode].add(nextEdge); //pathToNodes[nextNode].add(nextEdge);
priorityQueue.addAll(graph.getAllEdgesFromNode(nextNode)); //priorityQueue.addAll(graph.getAllEdgesFromNode(nextNode));
} }
} }
return pathToNodes[destinationNumber]; return pathWeight[destinationNumber];//pathToNodes[destinationNumber];
} }
/*public static ListOfPlaces getListOfPlaces(Graph graph, int startNumber,int numberOfPlaces, short type){ /*public static ListOfPlaces getListOfPlaces(Graph graph, int startNumber,int numberOfPlaces, short type){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment