Merge remote-tracking branch 'origin/idf-mobilite-net-graph' into astar
This commit is contained in:
commit
a9f4d17b97
4 changed files with 19 additions and 53 deletions
|
@ -1,5 +1,6 @@
|
||||||
package fr.u_paris.gla.project.itinerary;
|
package fr.u_paris.gla.project.itinerary;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package fr.u_paris.gla.project.itinerary;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface GraphNode{
|
public interface GraphNode {
|
||||||
int getId();
|
int getId();
|
||||||
double getHeuristicCost(Stop goalNode);
|
double getHeuristicCost(Stop goalNode);
|
||||||
|
|
||||||
|
|
|
@ -48,88 +48,50 @@ public class Main{
|
||||||
return new double[] {Double.parseDouble(stringCoords[0]), Double.parseDouble(stringCoords[1])};
|
return new double[] {Double.parseDouble(stringCoords[0]), Double.parseDouble(stringCoords[1])};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Stop> getStops(HashSet<Stop> nodes, String name, String gps) {
|
private static Stop getOrCreateStop(HashSet<Stop> nodes, HashMap<String, Stop> tmp, String name, String gps, String lineId) {
|
||||||
double []coords = getCoords(gps);
|
Stop stop = tmp.get(gps);
|
||||||
return nodes.stream().filter(
|
if (stop == null) {
|
||||||
stop -> stop.getName().equals(name)
|
|
||||||
&& stop.getLatitude() == coords[0]
|
|
||||||
&& stop.getLongitude() == coords[1]
|
|
||||||
).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
private static Stop getOrCreateStop(HashSet<Stop> nodes, String name, String gps, String lineId) {
|
|
||||||
List<Stop> stops = getStops(nodes, name, gps);
|
|
||||||
if (stops.isEmpty()) {
|
|
||||||
double[] coords = getCoords(gps);
|
double[] coords = getCoords(gps);
|
||||||
Stop newStop = new Stop(lineId, name, coords[0], coords[1]);
|
Stop newStop = new Stop(lineId, name, coords[0], coords[1]);
|
||||||
nodes.add(newStop);
|
nodes.add(newStop);
|
||||||
|
tmp.put(gps, newStop);
|
||||||
return newStop;
|
return newStop;
|
||||||
}
|
}
|
||||||
else if (stops.size() == 1) {
|
|
||||||
stops.get(0).addLine(lineId);
|
|
||||||
return stops.get(0);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
LOGGER.severe("Error in graph creation");
|
stop.addLine(lineId);
|
||||||
return null;
|
return stop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int lineNB = 0;
|
public static int lineNB = 0;
|
||||||
|
|
||||||
private static void addLine(String[] line, HashSet<Stop> nodes, HashMap<Integer, Set<Connection>> connections) {
|
private static void addLine(String[] line, HashSet<Stop> nodes, HashMap<String, Stop> tmp, HashMap<Stop, Set<Connection>> connections) {
|
||||||
// TODO Cas particulier ou une ligne a le même nom
|
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]);
|
||||||
Stop fromStop = getOrCreateStop(nodes, line[IDFM_TRACE_FROM_INDEX], line[IDFM_TRACE_FROM_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]);
|
|
||||||
Stop toStop = getOrCreateStop(nodes, line[IDFM_TRACE_TO_INDEX], line[IDFM_TRACE_TO_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]);
|
|
||||||
|
|
||||||
if (fromStop == null || toStop == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
String[] timeString = line[IDFM_TRACE_TIME_INDEX].split(":");
|
String[] timeString = line[IDFM_TRACE_TIME_INDEX].split(":");
|
||||||
int time = Integer.parseInt(timeString[0]) * 60 + Integer.parseInt(timeString[1]);
|
int time = Integer.parseInt(timeString[0]) * 60 + Integer.parseInt(timeString[1]);
|
||||||
|
|
||||||
Connection connection = new Connection(toStop.getId(), line[IDFM_TRACE_ID_INDEX], Double.parseDouble(line[IDFM_TRACE_DISTANCE_INDEX]), time);
|
Connection connection = new Connection(toStop, line[IDFM_TRACE_ID_INDEX], Double.parseDouble(line[IDFM_TRACE_DISTANCE_INDEX]), time);
|
||||||
|
|
||||||
connections.computeIfAbsent(fromStop.getId(), k -> new HashSet<>()).add(connection);
|
connections.computeIfAbsent(fromStop, k -> new HashSet<>()).add(connection);
|
||||||
|
|
||||||
/*
|
|
||||||
Set<Connection> linesConnections = connections.get(fromStop.getId());
|
|
||||||
|
|
||||||
String[] timeString = line[IDFM_TRACE_TIME_INDEX].split(":");
|
|
||||||
int time = Integer.parseInt(timeString[0]) * 60 + Integer.parseInt(timeString[1]);
|
|
||||||
Connection connection = new Connection(toStop.getId(), line[IDFM_TRACE_ID_INDEX], Double.parseDouble(line[IDFM_TRACE_DISTANCE_INDEX]), time);
|
|
||||||
if (linesConnections == null)
|
|
||||||
connections.put(fromStop.getId(), new HashSet<>(List.of(connection)));
|
|
||||||
else
|
|
||||||
linesConnections.add(connection);
|
|
||||||
|
|
||||||
if (lineNB++ % 1000 == 0) {
|
|
||||||
LOGGER.log(Level.INFO,"Added line " + line[IDFM_TRACE_ID_INDEX] + " from " + line[IDFM_TRACE_FROM_INDEX] + " to " + line[IDFM_TRACE_TO_INDEX] + ", line " + lineNB);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
// TODO ajouter option du nom en argument
|
|
||||||
if (args.length != 0) {
|
if (args.length != 0) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
try {
|
try {
|
||||||
HashSet<Stop> nodes = new HashSet<>();
|
HashSet<Stop> nodes = new HashSet<>();
|
||||||
HashMap<Integer, Set<Connection>> connections = new HashMap<>();
|
HashMap<Stop, Set<Connection>> connections = new HashMap<>();
|
||||||
|
HashMap<String, Stop> tmp = new HashMap<>();
|
||||||
CSVTools.readCSVFromFile(TRACE_FILE_NAME,
|
CSVTools.readCSVFromFile(TRACE_FILE_NAME,
|
||||||
(String[] line) -> addLine(line, nodes, connections));
|
(String[] line) -> addLine(line, nodes, tmp, connections));
|
||||||
Graph<Stop> graph = new Graph<>(nodes, connections);
|
Graph<Stop> graph = new Graph<>(nodes, connections);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Error while reading the line paths", e);
|
LOGGER.log(Level.SEVERE, "Error while reading the line paths", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,11 @@ public class Stop implements GraphNode {
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
private final Set<String> lines;
|
private final Set<String> lines;
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private final double latitude;
|
private final double latitude;
|
||||||
|
|
||||||
private final double longitude;
|
private final double longitude;
|
||||||
|
|
||||||
public Stop(String line, String name, double latitude, double longitude) {
|
public Stop(String line, String name, double latitude, double longitude) {
|
||||||
|
|
Reference in a new issue