diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Finder.java b/src/main/java/fr/u_paris/gla/project/itinerary/Finder.java index 49c08d0..bef9d63 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Finder.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Finder.java @@ -15,12 +15,11 @@ public class Finder { * @param startNode * @param goalNode */ - public List findPath(Stop startNode, Stop goalNode) { - double startTime = 43200; //12h + public List findPath(Stop startNode, Stop goalNode, double startTime) { PriorityQueue openSet = new PriorityQueue<>(Comparator.comparingDouble(GraphNode::getF)); HashSet closedSet = new HashSet<>(); - HashMap cameFrom = new HashMap<>(); + HashMap cameFrom = new HashMap<>(); HashMap gScore = new HashMap<>(); HashMap fScore = new HashMap<>(); @@ -63,7 +62,7 @@ public class Finder { } // This path is the best until now. Record it! - cameFrom.put(neighbor, current); + cameFrom.put(neighbor, new Path(current, connection, currentTime)); gScore.put(neighbor, tentativeGScore); fScore.put(neighbor, tentativeGScore + neighbor.getHeuristicCost(goalNode)); @@ -87,13 +86,15 @@ public class Finder { * @param current * @return path */ - private List reconstructPath(HashMap cameFrom, Stop current) { - List totalPath = new ArrayList<>(); - totalPath.add(current); + private List reconstructPath(HashMap cameFrom, Stop current) { + List totalPath = new ArrayList<>(); + totalPath.add(cameFrom.get(current)); while (cameFrom.containsKey(current)) { - current = cameFrom.get(current); - totalPath.add(0, current); // Add to the beginning of the list to maintain order + current = cameFrom.get(current).getCurrentStop(); + if(cameFrom.get(current) != null) { + totalPath.add(0, cameFrom.get(current)); // Add to the beginning of the list to maintain order + } } return totalPath; diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java b/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java index f2ebe85..d272b77 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java @@ -165,10 +165,10 @@ public class ItineraryCalculator { } } - for(Connection n : neighborhood) { + for(Connection n : directions) { if(n.getStop() == next_stop) { n.addSchedule(time); - time += n.getTime(); + time += n.getTime() + STOP_TIME; addScheduleRec(next_stop, current, line, bifurcations, time, stopsHashSet, connections, processed); return; } @@ -191,7 +191,7 @@ public class ItineraryCalculator { String name = input[2]; String[] timeString = input[3].split(":"); - int time = Integer.parseInt(timeString[0]) * 3600 + Integer.parseInt(timeString[1])*60 + STOP_TIME; + int time = Integer.parseInt(timeString[0]) * 3600 + Integer.parseInt(timeString[1])*60; ArrayList stops = stopsHashSet.get(name); @@ -209,7 +209,7 @@ public class ItineraryCalculator { LOGGER.severe("Invalid command line. Target file names are in the main file for now."); return; } - IDFMNetworkExtractor.builFiles(); + //IDFMNetworkExtractor.builFiles(); try { HashSet nodes = new HashSet<>(); @@ -244,9 +244,9 @@ public class ItineraryCalculator { //System.out.println(graph.getConnections(porteivry)); Finder finder = new Finder(graph); - List res = finder.findPath(porteivry, chatelet); - for (Stop element : res) { - System.out.println(element); + List res = finder.findPath(porteivry, chatelet, 43200); + for (Path element : res) { + System.out.println(element.getCurrentStop()); } } catch (IOException e) { diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Path.java b/src/main/java/fr/u_paris/gla/project/itinerary/Path.java index a492b99..d68096e 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Path.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Path.java @@ -1,18 +1,50 @@ package fr.u_paris.gla.project.itinerary; -public class Path { - private T current; +public class Path { + private Stop current; - private T previous; + private Stop next; - private double currentScore; + private double startTime; - private final double targetScore; + private double travelTime; - public Path(T current, T previous, double currentScore, double targetScore) { + private double distance; + + private String line; + + private Connection connection; + + public Path(Stop current, Connection connection, double startTime) { this.current = current; - this.previous = previous; - this.currentScore = currentScore; - this.targetScore = targetScore; + this.connection = connection; + this.next = connection.getStop(); + this.startTime = startTime; + this.travelTime = connection.getTime(); + this.line = connection.getLineName(); + } + + public Connection getConnection(){ + return this.connection; + } + + public Stop getCurrentStop() { + return this.current; + } + + public Stop getNextStop() { + return next; + } + + public double getStartTime() { + return this.startTime; + } + + public double travelTime() { + return this.travelTime; + } + + public String getLine() { + return this.line; } }