Corrections de bugs
This commit is contained in:
parent
0df767c9b5
commit
821c8f0098
5 changed files with 51 additions and 25 deletions
|
@ -38,6 +38,10 @@ public class Finder {
|
||||||
|
|
||||||
closedSet.add(current);
|
closedSet.add(current);
|
||||||
|
|
||||||
|
if(graph.getConnections(current) == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (Connection connection : graph.getConnections(current) ) {
|
for (Connection connection : graph.getConnections(current) ) {
|
||||||
Stop neighbor = connection.getStop();
|
Stop neighbor = connection.getStop();
|
||||||
if (closedSet.contains(neighbor)) {
|
if (closedSet.contains(neighbor)) {
|
||||||
|
@ -56,6 +60,7 @@ public class Finder {
|
||||||
cameFrom.put(neighbor, current);
|
cameFrom.put(neighbor, current);
|
||||||
gScore.put(neighbor, tentativeGScore);
|
gScore.put(neighbor, tentativeGScore);
|
||||||
fScore.put(neighbor, tentativeGScore + neighbor.getHeuristicCost(goalNode));
|
fScore.put(neighbor, tentativeGScore + neighbor.getHeuristicCost(goalNode));
|
||||||
|
neighbor.setF(fScore.get(neighbor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,4 +10,5 @@ public interface GraphNode {
|
||||||
Set<Stop> getNeighbors();
|
Set<Stop> getNeighbors();
|
||||||
double getCost(Stop neighbor);
|
double getCost(Stop neighbor);
|
||||||
double getF();
|
double getF();
|
||||||
|
void setF(double value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package fr.u_paris.gla.project.itinerary;
|
||||||
|
|
||||||
import fr.u_paris.gla.project.idfm.*;
|
import fr.u_paris.gla.project.idfm.*;
|
||||||
import fr.u_paris.gla.project.utils.CSVTools;
|
import fr.u_paris.gla.project.utils.CSVTools;
|
||||||
|
import fr.u_paris.gla.project.utils.GPS;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -35,6 +36,8 @@ public class Main{
|
||||||
|
|
||||||
private static final int IDFM_TRACE_DISTANCE_INDEX = 7;
|
private static final int IDFM_TRACE_DISTANCE_INDEX = 7;
|
||||||
|
|
||||||
|
private static final double MARGE_ERREUR = 1.;
|
||||||
|
|
||||||
// Parser helper values
|
// Parser helper values
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,24 +51,31 @@ 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 Stop getOrCreateStop(HashSet<Stop> nodes, HashMap<String, Stop> tmp, String name, String gps, String lineId) {
|
private static Stop getOrCreateStop(HashSet<Stop> nodes, HashMap<String, ArrayList<Stop>> tmp, String name, String gps, String lineId) {
|
||||||
Stop stop = tmp.get(gps);
|
ArrayList<Stop> stopList = tmp.get(name);
|
||||||
if (stop == null) {
|
if (stopList != null) {
|
||||||
double[] coords = getCoords(gps);
|
for(Stop stop : stopList) {
|
||||||
Stop newStop = new Stop(lineId, name, coords[0], coords[1]);
|
double[] coords = getCoords(gps);
|
||||||
nodes.add(newStop);
|
double dist = GPS.distance(coords[0], coords[1], stop.getLatitude(), stop.getLongitude());
|
||||||
tmp.put(gps, newStop);
|
if(dist < MARGE_ERREUR) {
|
||||||
return newStop;
|
stop.addLine(lineId);
|
||||||
}
|
return stop;
|
||||||
else {
|
}
|
||||||
stop.addLine(lineId);
|
}
|
||||||
return stop;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double[] coords = getCoords(gps);
|
||||||
|
Stop newStop = new Stop(lineId, name, coords[0], coords[1]);
|
||||||
|
nodes.add(newStop);
|
||||||
|
stopList = stopList == null ? new ArrayList<>() : stopList;
|
||||||
|
stopList.add(newStop);
|
||||||
|
tmp.put(name, stopList);
|
||||||
|
return newStop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int lineNB = 0;
|
public static int lineNB = 0;
|
||||||
|
|
||||||
private static void addLine(String[] line, HashSet<Stop> nodes, HashMap<String, Stop> tmp, HashMap<Stop, Set<Connection>> 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 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 toStop = getOrCreateStop(nodes, tmp, line[IDFM_TRACE_TO_INDEX], line[IDFM_TRACE_TO_GPS_INDEX], line[IDFM_TRACE_ID_INDEX]);
|
||||||
|
|
||||||
|
@ -91,21 +101,22 @@ public class Main{
|
||||||
try {
|
try {
|
||||||
HashSet<Stop> nodes = new HashSet<>();
|
HashSet<Stop> nodes = new HashSet<>();
|
||||||
HashMap<Stop, Set<Connection>> connections = new HashMap<>();
|
HashMap<Stop, Set<Connection>> connections = new HashMap<>();
|
||||||
HashMap<String, Stop> tmp = new HashMap<>();
|
HashMap<String, ArrayList<Stop>> tmp = new HashMap<>();
|
||||||
CSVTools.readCSVFromFile(TRACE_FILE_NAME,
|
CSVTools.readCSVFromFile(TRACE_FILE_NAME,
|
||||||
(String[] line) -> addLine(line, nodes, tmp, connections));
|
(String[] line) -> addLine(line, nodes, tmp, connections));
|
||||||
|
|
||||||
Stop porteivry = tmp.get("48.821352988336876, 2.369294978223312");
|
|
||||||
Stop repu = tmp.get("48.867687468165165, 2.3640990472225725");
|
Stop porteivry = tmp.get("Porte d'Ivry").get(0);
|
||||||
|
Stop repu = tmp.get("République").get(0);
|
||||||
|
|
||||||
Graph graph = new Graph(nodes, connections);
|
Graph graph = new Graph(nodes, connections);
|
||||||
int cpt = 0;
|
int cpt = 0;
|
||||||
for (Map.Entry<Stop, Set<Connection>> entry : graph.getConnections().entrySet()) {
|
for (Map.Entry<Stop, Set<Connection>> entry : graph.getConnections().entrySet()) {
|
||||||
if (entry.getValue() == null) cpt +=1;
|
if (entry.getValue() == null) cpt +=1;
|
||||||
}
|
}
|
||||||
Stop garenord = tmp.get("48.88143149182458, 2.357767843520973");
|
Stop garenord = tmp.get("Gare du Nord").get(0);
|
||||||
|
|
||||||
Stop chatelet = tmp.get("48.856953460785334, 2.3481609912345776");
|
Stop chatelet = tmp.get("Châtelet").get(0);
|
||||||
//System.out.println(graph.getConnections(garenord));
|
//System.out.println(graph.getConnections(garenord));
|
||||||
//System.out.println(cpt);
|
//System.out.println(cpt);
|
||||||
//System.out.println(graph.getConnections(porteivry));
|
//System.out.println(graph.getConnections(porteivry));
|
||||||
|
|
|
@ -16,6 +16,8 @@ public class Stop implements GraphNode {
|
||||||
|
|
||||||
private final double longitude;
|
private final double longitude;
|
||||||
|
|
||||||
|
private double f;
|
||||||
|
|
||||||
public Stop(String line, String name, double latitude, double longitude) {
|
public Stop(String line, String name, double latitude, double longitude) {
|
||||||
lines = new HashSet<>();
|
lines = new HashSet<>();
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
|
@ -23,6 +25,7 @@ public class Stop implements GraphNode {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
|
this.f = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,8 +50,8 @@ public class Stop implements GraphNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set getNeighbors() {
|
public Set<Stop> getNeighbors() {
|
||||||
return lines;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,7 +61,11 @@ public class Stop implements GraphNode {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getF() {
|
public double getF() {
|
||||||
return 0;
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setF(double value) {
|
||||||
|
this.f = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
|
|
|
@ -30,14 +30,16 @@ public final class GPS {
|
||||||
* @param longitude1 the longitude of the first position
|
* @param longitude1 the longitude of the first position
|
||||||
* @param latitude2 the latitude of the second position
|
* @param latitude2 the latitude of the second position
|
||||||
* @param longitude2 the longitude of the second position
|
* @param longitude2 the longitude of the second position
|
||||||
* @return the flying distance */
|
* @return the flying distance in km*/
|
||||||
public static double distance(double latitude1, double longitude1, double latitude2,
|
public static double distance(double latitude1, double longitude1, double latitude2,
|
||||||
double longitude2) {
|
double longitude2) {
|
||||||
double deltaLatitude = degreeToRadian(latitude2 - latitude1);
|
latitude1 = degreeToRadian(latitude1);
|
||||||
|
latitude2 = degreeToRadian(latitude2);
|
||||||
|
double deltaLatitude = latitude2 - latitude1;
|
||||||
double deltaLongitude = degreeToRadian(longitude2 - longitude1);
|
double deltaLongitude = degreeToRadian(longitude2 - longitude1);
|
||||||
double a = Math.pow(Math.sin(deltaLatitude / 2), 2)
|
double a = Math.pow(Math.sin(deltaLatitude / 2), 2)
|
||||||
+ Math.pow(Math.sin(deltaLongitude), 2) * Math.cos(latitude1)
|
+ Math.pow(Math.sin(deltaLongitude / 2), 2) * Math.cos(latitude1)
|
||||||
* Math.cos(latitude2);
|
* Math.cos(latitude2);
|
||||||
return EARTH_RADIUS * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
return 2 * EARTH_RADIUS * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue