Renvoie de Path pour le finder.

This commit is contained in:
Francois 2024-04-28 13:55:50 +02:00
parent a8357ef564
commit 5fbc584fab
3 changed files with 58 additions and 25 deletions

View file

@ -15,12 +15,11 @@ public class Finder {
* @param startNode * @param startNode
* @param goalNode * @param goalNode
*/ */
public List<Stop> findPath(Stop startNode, Stop goalNode) { public List<Path> findPath(Stop startNode, Stop goalNode, double startTime) {
double startTime = 43200; //12h
PriorityQueue<Stop> openSet = new PriorityQueue<>(Comparator.comparingDouble(GraphNode::getF)); PriorityQueue<Stop> openSet = new PriorityQueue<>(Comparator.comparingDouble(GraphNode::getF));
HashSet<Stop> closedSet = new HashSet<>(); HashSet<Stop> closedSet = new HashSet<>();
HashMap<Stop, Stop> cameFrom = new HashMap<>(); HashMap<Stop, Path> cameFrom = new HashMap<>();
HashMap<Stop, Double> gScore = new HashMap<>(); HashMap<Stop, Double> gScore = new HashMap<>();
HashMap<Stop, Double> fScore = new HashMap<>(); HashMap<Stop, Double> fScore = new HashMap<>();
@ -63,7 +62,7 @@ public class Finder {
} }
// This path is the best until now. Record it! // 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); gScore.put(neighbor, tentativeGScore);
fScore.put(neighbor, tentativeGScore + neighbor.getHeuristicCost(goalNode)); fScore.put(neighbor, tentativeGScore + neighbor.getHeuristicCost(goalNode));
@ -87,13 +86,15 @@ public class Finder {
* @param current * @param current
* @return path * @return path
*/ */
private List<Stop> reconstructPath(HashMap<Stop, Stop> cameFrom, Stop current) { private List<Path> reconstructPath(HashMap<Stop, Path> cameFrom, Stop current) {
List<Stop> totalPath = new ArrayList<>(); List<Path> totalPath = new ArrayList<>();
totalPath.add(current); totalPath.add(cameFrom.get(current));
while (cameFrom.containsKey(current)) { while (cameFrom.containsKey(current)) {
current = cameFrom.get(current); current = cameFrom.get(current).getCurrentStop();
totalPath.add(0, current); // Add to the beginning of the list to maintain order if(cameFrom.get(current) != null) {
totalPath.add(0, cameFrom.get(current)); // Add to the beginning of the list to maintain order
}
} }
return totalPath; return totalPath;

View file

@ -165,10 +165,10 @@ public class ItineraryCalculator {
} }
} }
for(Connection n : neighborhood) { for(Connection n : directions) {
if(n.getStop() == next_stop) { if(n.getStop() == next_stop) {
n.addSchedule(time); n.addSchedule(time);
time += n.getTime(); time += n.getTime() + STOP_TIME;
addScheduleRec(next_stop, current, line, bifurcations, time, stopsHashSet, connections, processed); addScheduleRec(next_stop, current, line, bifurcations, time, stopsHashSet, connections, processed);
return; return;
} }
@ -191,7 +191,7 @@ public class ItineraryCalculator {
String name = input[2]; String name = input[2];
String[] timeString = input[3].split(":"); 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<Stop> stops = stopsHashSet.get(name); ArrayList<Stop> 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."); LOGGER.severe("Invalid command line. Target file names are in the main file for now.");
return; return;
} }
IDFMNetworkExtractor.builFiles(); //IDFMNetworkExtractor.builFiles();
try { try {
HashSet<Stop> nodes = new HashSet<>(); HashSet<Stop> nodes = new HashSet<>();
@ -244,9 +244,9 @@ public class ItineraryCalculator {
//System.out.println(graph.getConnections(porteivry)); //System.out.println(graph.getConnections(porteivry));
Finder finder = new Finder(graph); Finder finder = new Finder(graph);
List<Stop> res = finder.findPath(porteivry, chatelet); List<Path> res = finder.findPath(porteivry, chatelet, 43200);
for (Stop element : res) { for (Path element : res) {
System.out.println(element); System.out.println(element.getCurrentStop());
} }
} catch (IOException e) { } catch (IOException e) {

View file

@ -1,18 +1,50 @@
package fr.u_paris.gla.project.itinerary; package fr.u_paris.gla.project.itinerary;
public class Path <T extends GraphNode> { public class Path {
private T current; 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.current = current;
this.previous = previous; this.connection = connection;
this.currentScore = currentScore; this.next = connection.getStop();
this.targetScore = targetScore; 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;
} }
} }