Add a way to find a path from a location
This commit is contained in:
parent
29e95072f3
commit
d44b8496e1
7 changed files with 49 additions and 27 deletions
2
pom.xml
2
pom.xml
|
@ -62,7 +62,7 @@
|
|||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
|
||||
<mainClass>fr.u_paris.gla.project.App</mainClass>
|
||||
<mainClass>fr.u_paris.gla.project.itinerary.Parse</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
/**
|
||||
* Code of an extractor for the data from IDF mobilite.
|
||||
*
|
||||
|
|
|
@ -1,23 +1,43 @@
|
|||
package fr.u_paris.gla.project.itinerary;
|
||||
|
||||
import fr.u_paris.gla.project.utils.GPS;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class Finder {
|
||||
|
||||
private Graph graph;
|
||||
|
||||
public Finder(Graph graph) {
|
||||
this.graph = graph;
|
||||
}
|
||||
|
||||
public List<Path> findPath(double from_x, double from_y, double to_x, double to_y, double startTime) {
|
||||
Stop fromNode = new Stop("", "tmp_from", from_x, from_y);
|
||||
Stop toNode = new Stop("", "tmp_to", to_x, to_y);
|
||||
|
||||
for (Stop node : graph.getNodes()) {
|
||||
double from_dst = GPS.distance(from_x, from_y, node.getLatitude(), node.getLongitude());
|
||||
double to_dst = GPS.distance(to_x, to_y, node.getLatitude(), node.getLongitude());
|
||||
Connection from_c = new Connection(node, "", from_dst, (int) ((from_dst * 1000) / Parse.WALK_SPEED));
|
||||
Connection to_c = new Connection(toNode, "", to_dst, (int) ((to_dst * 1000) / Parse.WALK_SPEED));
|
||||
graph.addConnection(fromNode, from_c);
|
||||
graph.addConnection(node, to_c);
|
||||
}
|
||||
graph.addNode(fromNode);
|
||||
graph.addNode(toNode);
|
||||
|
||||
List<Path> res = findPath(fromNode, toNode, startTime);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* return a path from startNode to goalNode using A* algorithm
|
||||
* @param startNode
|
||||
* @param goalNode
|
||||
*/
|
||||
public List<Path> findPath(Stop startNode, Stop goalNode, double startTime) {
|
||||
|
||||
PriorityQueue<Stop> openSet = new PriorityQueue<>(Comparator.comparingDouble(GraphNode::getF));
|
||||
PriorityQueue<Stop> openSet = new PriorityQueue<>(Comparator.comparingDouble(Stop::getF));
|
||||
HashSet<Stop> closedSet = new HashSet<>();
|
||||
HashMap<Stop, Path> cameFrom = new HashMap<>();
|
||||
HashMap<Stop, Double> gScore = new HashMap<>();
|
||||
|
@ -111,6 +131,5 @@ public class Finder {
|
|||
node.setF(newF);
|
||||
openSet.add(node);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package fr.u_paris.gla.project.itinerary;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -25,4 +25,25 @@ public class Graph{
|
|||
public Map<Stop, Set<Connection>> getConnections() {
|
||||
return connections;
|
||||
}
|
||||
|
||||
public void addNode(Stop s) {
|
||||
nodes.add(s);
|
||||
}
|
||||
|
||||
public void addConnection(Stop stop, Connection con) {
|
||||
Set<Connection> currentConnections = connections.get(stop);
|
||||
if (currentConnections == null) {
|
||||
HashSet<Connection> set = new HashSet<>();
|
||||
set.add(con);
|
||||
connections.put(stop, set);
|
||||
}
|
||||
else {
|
||||
currentConnections.add(con);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeNode(Stop s) {
|
||||
nodes.remove(s);
|
||||
connections.remove(s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package fr.u_paris.gla.project.itinerary;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface GraphNode {
|
||||
int getId();
|
||||
double getHeuristicCost(Stop goalNode);
|
||||
|
||||
Set<Stop> getNeighbors();
|
||||
double getCost(Stop neighbor);
|
||||
double getF();
|
||||
void setF(double value);
|
||||
}
|
|
@ -42,7 +42,7 @@ public class Parse {
|
|||
private static final int STOP_TIME = 30;
|
||||
|
||||
//Walking speed in m/s
|
||||
private static final double WALK_SPEED = 1.;
|
||||
public static final double WALK_SPEED = 1.;
|
||||
|
||||
private HashSet<Stop> nodes = new HashSet<>();
|
||||
private HashMap<Stop, Set<Connection>> connections = new HashMap<>();
|
||||
|
|
|
@ -3,7 +3,7 @@ package fr.u_paris.gla.project.itinerary;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Stop implements GraphNode {
|
||||
public class Stop {
|
||||
// The total number of stops
|
||||
private static int counter = 0;
|
||||
|
||||
|
@ -41,27 +41,22 @@ public class Stop implements GraphNode {
|
|||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeuristicCost(Stop goalNode) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Stop> getNeighbors() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCost(Stop neighbor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getF() {
|
||||
return f;
|
||||
}
|
||||
|
|
Reference in a new issue