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 goalNode
*/
public List<Stop> findPath(Stop startNode, Stop goalNode) {
double startTime = 43200; //12h
public List<Path> findPath(Stop startNode, Stop goalNode, double startTime) {
PriorityQueue<Stop> openSet = new PriorityQueue<>(Comparator.comparingDouble(GraphNode::getF));
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> 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<Stop> reconstructPath(HashMap<Stop, Stop> cameFrom, Stop current) {
List<Stop> totalPath = new ArrayList<>();
totalPath.add(current);
private List<Path> reconstructPath(HashMap<Stop, Path> cameFrom, Stop current) {
List<Path> 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;

View file

@ -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<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.");
return;
}
IDFMNetworkExtractor.builFiles();
//IDFMNetworkExtractor.builFiles();
try {
HashSet<Stop> nodes = new HashSet<>();
@ -244,9 +244,9 @@ public class ItineraryCalculator {
//System.out.println(graph.getConnections(porteivry));
Finder finder = new Finder(graph);
List<Stop> res = finder.findPath(porteivry, chatelet);
for (Stop element : res) {
System.out.println(element);
List<Path> res = finder.findPath(porteivry, chatelet, 43200);
for (Path element : res) {
System.out.println(element.getCurrentStop());
}
} catch (IOException e) {

View file

@ -1,18 +1,50 @@
package fr.u_paris.gla.project.itinerary;
public class Path <T extends GraphNode> {
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;
}
}