JavaDoc for the graph creation

This commit is contained in:
Lucas 2024-04-08 14:19:44 +02:00
parent 5bac5787df
commit 92382857d2
5 changed files with 25 additions and 13 deletions

View file

@ -62,7 +62,7 @@
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
<mainClass>fr.u_paris.gla.project.itinerary.Main</mainClass>
<mainClass>fr.u_paris.gla.project.itinerary.ItineraryCalculator</mainClass>
</manifest>
</archive>
</configuration>

View file

@ -1,8 +1,10 @@
package fr.u_paris.gla.project.itinerary;
public class Connection{
// Destination of the connection between the two stops
private final Stop stop;
// The line used for this connection
private final String lineName;
private final double distance;

View file

@ -22,7 +22,6 @@ public class Graph{
return nodes;
}
public Map<Stop, Set<Connection>> getConnections() {
return connections;
}

View file

@ -9,7 +9,7 @@ import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main{
public class ItineraryCalculator {
private static final Logger LOGGER = Logger
.getLogger(IDFMNetworkExtractor.class.getName());
@ -36,9 +36,8 @@ public class Main{
private static final int IDFM_TRACE_DISTANCE_INDEX = 7;
private static final double MARGE_ERREUR = 1.;
private static final double ERROR_MARGIN = 1.;
// Parser helper values
/**
* Returns the coordinates from a String to a double array:
@ -51,13 +50,23 @@ public class Main{
return new double[] {Double.parseDouble(stringCoords[0]), Double.parseDouble(stringCoords[1])};
}
/**
* Searchs for a stop with the same name and GPS coordinates in the graph, and creates it if non existant
* @param nodes a graph of the stops
* @param tmp list of the created stops
* @param name the name of the stop
* @param gps the coordinate of the stop
* @param lineId the line the stop is on
* @return the Stop object
*/
private static Stop getOrCreateStop(HashSet<Stop> nodes, HashMap<String, ArrayList<Stop>> tmp, String name, String gps, String lineId) {
ArrayList<Stop> stopList = tmp.get(name);
// First we search by name, and then compare the coordinates since multiple stations can have the same name. A margin of error is necessary since stops can have multiple GPS coordinates
if (stopList != null) {
for(Stop stop : stopList) {
double[] coords = getCoords(gps);
double dist = GPS.distance(coords[0], coords[1], stop.getLatitude(), stop.getLongitude());
if(dist < MARGE_ERREUR) {
if(dist < ERROR_MARGIN) {
stop.addLine(lineId);
return stop;
}
@ -73,8 +82,13 @@ public class Main{
return newStop;
}
public static int lineNB = 0;
/**
* Adds into the graph the connection between two stops, parsed from a CSV line
* @param line the current line we want to parse
* @param nodes the graph of stops
* @param tmp list of the created stops
* @param connections
*/
private static void addLine(String[] line, HashSet<Stop> nodes, HashMap<String, ArrayList<Stop>> tmp, HashMap<Stop, Set<Connection>> connections) {
Stop fromStop = getOrCreateStop(nodes, tmp, line[IDFM_TRACE_FROM_INDEX], line[IDFM_TRACE_FROM_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]);
Stop toStop = getOrCreateStop(nodes, tmp, line[IDFM_TRACE_TO_INDEX], line[IDFM_TRACE_TO_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]);
@ -87,11 +101,6 @@ public class Main{
connections.computeIfAbsent(fromStop, k -> new HashSet<>()).add(connection);
}
public static void find(Graph graph){
}
public static void main(String[] args){
if (args.length != 0) {
LOGGER.severe("Invalid command line. Target file names are in the main file for now.");

View file

@ -4,10 +4,12 @@ import java.util.HashSet;
import java.util.Set;
public class Stop implements GraphNode {
// The total number of stops
private static int counter = 0;
private final int id;
// The set of all the lines the stop is on
private final Set<String> lines;
private final String name;