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

method that returns list of places is implemented

parent bf00452e
No related branches found
No related tags found
No related merge requests found
......@@ -182,18 +182,18 @@ class Graph{
System.out.println(sb.toString());
}
/*private void setTypes(int nodeNumber,int typeValue, String name){
private void setTypes(int nodeNumber,int typeValue, String name){
Node node = this.getNode(nodeNumber);
if((typeValue&1) ==1) node.setType("Place name");
if((typeValue&2) == 2) node.setType("Gas station");
if((typeValue&4) == 4) node.setType("Charge station");
if((typeValue&8) == 8) node.setType("Eating place");
if((typeValue&16) == 16) node.setType("Drinking place");
if((typeValue&32) == 32) node.setType("Accommodation");
if((typeValue&1) ==1) node.setType((short) 1);
if((typeValue&2) == 2) node.setType((short) 2);
if((typeValue&4) == 4) node.setType((short) 4);
if((typeValue&8) == 8) node.setType((short) 8);
if((typeValue&16) == 16) node.setType((short) 16);
if((typeValue&32) == 32) node.setType((short) 32);
node.setName(name);
}*/
}
public int getNumberOfNodes(){
return nodes.size();
......@@ -235,6 +235,35 @@ class Dijkstra{
}
return pathToNodes[destinationNumber];
}
public static ListOfPlaces getListOfPlaces(Graph graph, int startNumber,int numberOfPlaces, short type){
PriorityQueue<Edge> priorityQueue = new PriorityQueue<>();
ListOfPlaces listOfPlaces = new ListOfPlaces(numberOfPlaces);
int[] pathWeight = new int[graph.getNumberOfNodes()];
Arrays.fill(pathWeight, Integer.MAX_VALUE);
List<Edge>[] pathToNodes = new List[graph.getNumberOfNodes()];
pathWeight[startNumber] = 0;
Arrays.fill(pathToNodes,new ArrayList<>());
priorityQueue.addAll(graph.getAllEdgesFromNode(startNumber));
while (!priorityQueue.isEmpty()){
Edge nextEdge = priorityQueue.poll();
int nextNode = nextEdge.destination();
int currentSum = pathWeight[nextEdge.start()] + nextEdge.drivingTime();
if(currentSum<pathWeight[nextNode]){
pathWeight[nextNode] = currentSum;
pathToNodes[nextNode] = new ArrayList<>(pathToNodes[nextEdge.start()]);
pathToNodes[nextNode].add(nextEdge);
priorityQueue.addAll(graph.getAllEdgesFromNode(nextNode));
Node node = graph.getNode(nextNode);
if (node.getName() != null){
if(node.isTypeOf(type)){
listOfPlaces.addPlace(node,currentSum);
}
}
}
}
return listOfPlaces;
}
/*public static List<Edge> getShortestPath(Graph graph, int startNumber, int destinationNumber){
PriorityQueue<Edge> priorityQueue = new PriorityQueue<>();
Node startNode = graph.getNode(startNumber);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment