Some algorithm optimizations

This commit is contained in:
Francois 2024-05-04 20:37:38 +02:00
parent b3e1631c93
commit 458d31f2c4
5 changed files with 30 additions and 4 deletions

View file

@ -271,7 +271,7 @@ public final class CSVStreamProvider {
Double max_speed = max_speed_by_type.get(type);
Double two_acc_distance = two_acceleration_distance_by_type.get(type);
return Math.max(0, distance - two_acc_distance) / max_speed
+ Math.pow(Math.min(distance, two_acc_distance) / max_speed, 2);
+ 2 * Math.sqrt(Math.min(distance, two_acc_distance) * two_acc_distance)/max_speed;
}
private void fillTransports(int bif) {

View file

@ -87,7 +87,7 @@ public class Connection{
public double getCost(double currentTime) {
if(this.schedules.size() == 0) {
if(this.lineName.equals("WALK")) {
if(this.lineName.equals("WALK") || this.lineName.equals("")) {
return this.time;
}
return this.time + 900;

View file

@ -27,7 +27,12 @@ public class Finder {
graph.addNode(fromNode);
graph.addNode(toNode);
return findPath(fromNode, toNode, startTime);
List<Path> result = findPath(fromNode, toNode, startTime);
graph.removeNode(fromNode);
graph.removeNode(toNode);
return result;
}
/**

View file

@ -1,5 +1,6 @@
package fr.u_paris.gla.project.itinerary;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@ -43,6 +44,20 @@ public class Graph {
}
public void removeNode(Stop s) {
for(Stop stop : nodes) {
if(getConnections(stop) == null) {
continue;
}
ArrayList<Connection> toRemove = new ArrayList<>();
for(Connection c : getConnections(stop)) {
if(c.getStop() == s) {
toRemove.add(c);
}
}
for(Connection c : toRemove) {
getConnections(stop).remove(c);
}
}
nodes.remove(s);
connections.remove(s);
}

View file

@ -1,5 +1,7 @@
package fr.u_paris.gla.project.itinerary;
import fr.u_paris.gla.project.utils.GPS;
import java.util.HashSet;
import java.util.Set;
@ -20,6 +22,9 @@ public class Stop {
private double f;
//Maximal speed in m/s
private final double MAX_SPEED = 14.;
public Stop(String line, String name, double latitude, double longitude) {
lines = new HashSet<>();
lines.add(line);
@ -40,7 +45,8 @@ public class Stop {
}
public double getHeuristicCost(Stop goalNode) {
return 0;
double distance = GPS.distance(this.latitude, this.longitude, goalNode.latitude, goalNode.longitude);
return distance/MAX_SPEED;
}
public Set<Stop> getNeighbors() {