diff --git a/src/Graph.java b/src/Graph.java index d223d93..ee985c2 100644 --- a/src/Graph.java +++ b/src/Graph.java @@ -20,7 +20,7 @@ public class Graph { CityManager.addCity(city); } Map result = - graph.calculateShortestPath(cities.getFirst(), cities.get(3), "price"); + graph.calculateShortestPath(cities.getFirst(), cities.get(3), "hops"); System.out.println( cities.getLast().getName() + " = " + result.get(cities.get(3).getLocation())); } @@ -55,10 +55,13 @@ public class Graph { Location neighborLocation = neighborCity.getLocation(); double newCost = 0.0; + double currentCost = distances.get(current.getLocation()); if (type.equals("price")) { newCost = distances.get(current.getLocation()) + dep.getPrice(); } else if (type.equals("time")) { newCost = distances.get(current.getLocation()) + dep.getDuration(); + } else if (type.equals("hops")) { + newCost = currentCost + 1; } if (newCost < distances.get(neighborLocation)) {