Skip to content
Snippets Groups Projects

Central config

Merged theiled00 requested to merge create_central_config_for_bounding_box into main
5 files
+ 85
65
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -6,8 +6,6 @@ import java.util.HashSet;
@@ -6,8 +6,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.List;
import java.util.Random;
import java.util.Random;
import java.util.Set;
import java.util.Set;
import java.util.Map.Entry;
import de.fuberlin.navigator.routingserver.model.*;
import de.fuberlin.navigator.routingserver.model.*;
import org.jgrapht.graph.SimpleDirectedWeightedGraph;
import org.jgrapht.graph.SimpleDirectedWeightedGraph;
import org.jgrapht.GraphPath;
import org.jgrapht.GraphPath;
@@ -49,15 +47,15 @@ public class ApplyShortestPath {
@@ -49,15 +47,15 @@ public class ApplyShortestPath {
// find the shortest path
// find the shortest path
GraphPath<Long, ExtendedEdge> path = getShortestPathInTime(routingRequest);
GraphPath<Long, ExtendedEdge> path = getShortestPathInTime(routingRequest);
List<Point> coordinateList = covertToCoordinates(path.getVertexList());
List<Point> coordinateList = covertToCoordinates(path);
// duration of path in minutes
// duration of path in minutes
int duration = calculateDuration(path);
int duration = calculateDuration(path);
// length of path in meters
// length of path in meters
double length = calculateLength(path);
int length = calculateLength(path);
System.out.println("List of Point: "+Arrays.deepToString(coordinateList.toArray()));
System.out.println("List of Coordinates: "+Arrays.deepToString(coordinateList.toArray()));
System.out.println("duration: " + duration + " min");
System.out.println("duration: " + duration + " min");
System.out.println("length of path: " + length + " meter");
System.out.println("length of path: " + length + " meter");
}
}
@@ -85,9 +83,9 @@ public class ApplyShortestPath {
@@ -85,9 +83,9 @@ public class ApplyShortestPath {
//in minutes
//in minutes
int duration = calculateDuration(path);
int duration = calculateDuration(path);
//in meters
//in meters
int distance = (int) calculateLength(path);
int distance = calculateLength(path);
return RoutingResponse.of(covertToCoordinates(path.getVertexList()), distance, duration, daysAfterToday);
return RoutingResponse.of(covertToCoordinates(path), distance, duration, daysAfterToday);
}
}
private static GraphPath<Long, ExtendedEdge> getShortestPathInTime(RoutingRequest routingRequest){
private static GraphPath<Long, ExtendedEdge> getShortestPathInTime(RoutingRequest routingRequest){
@@ -224,36 +222,18 @@ public class ApplyShortestPath {
@@ -224,36 +222,18 @@ public class ApplyShortestPath {
}
}
}
}
private static long CoordinatesToID(Point Point){
private static int calculateLength(GraphPath<Long, ExtendedEdge> path){
// map Point of start and end point to node ID
double lat = Point.getLat();
double lon = Point.getLon();
double epsilon = 0.0001; // 14m difference
for (Entry<Long, Coordinates> node : mapper.getNodeMap().entrySet()) {
if (Math.abs(lat-node.getValue().getLat()) < epsilon) {
if (Math.abs(lon-node.getValue().getLon()) < epsilon) {
return (long) node.getKey();
}
}
}
System.out.println("No start or end point found!");
return 0;
}
private static double calculateLength(GraphPath<Long, ExtendedEdge> path){
double length = 0;
double length = 0;
for (ExtendedEdge edge : path.getEdgeList()) {
for (ExtendedEdge edge : path.getEdgeList()) {
// filtering out the newly generated edges because length cannot be accessed
// filtering out the newly generated edges because length cannot be accessed
if(roadnetwork.getSegmentsMap().get((long)edge.getId()) == null) continue;
if(roadnetwork.getSegmentsMap().get(edge.getId()) == null) continue;
double edgeLen = roadnetwork.getSegmentsMap().get((long)edge.getId()).getLength();
double edgeLen = roadnetwork.getSegmentsMap().get(edge.getId()).getLength();
length += edgeLen;
length += edgeLen;
}
}
return length;
return (int)length;
}
}
private static int calculateDuration(GraphPath<Long, ExtendedEdge> path){
private static int calculateDuration(GraphPath<Long, ExtendedEdge> path){
@@ -262,15 +242,38 @@ public class ApplyShortestPath {
@@ -262,15 +242,38 @@ public class ApplyShortestPath {
return durationMin;
return durationMin;
}
}
private static List<Point> covertToCoordinates(GraphPath<Long, ExtendedEdge> path){
private static List<Point> covertToCoordinates(List<Long> vertexList){
// convert path into path of Coordinates
// convert path consisting of node ids into path of Coordinates
List<Point> coordinateList = new ArrayList<>();
List<Point> coordinateList = new ArrayList<>();
for (Long nodeId : vertexList) {
double lat = mapper.getNodeMap().get(nodeId).getLat();
// add coordinates of generated start node
double lon = mapper.getNodeMap().get(nodeId).getLon();
Long startNodeID = path.getStartVertex();
coordinateList.add(new Point(lat, lon));
double lat = mapper.getNodeMap().get(startNodeID).getLat();
 
double lon = mapper.getNodeMap().get(startNodeID).getLon();
 
coordinateList.add(new Point(lat, lon));
 
 
// add coordinates of edges
 
int index = 0;
 
for (ExtendedEdge edge : path.getEdgeList()) {
 
// filter out generated first and last edge, which have no geometryList
 
if (index == 0 || index == path.getEdgeList().size()-1) {
 
index ++;
 
continue;
 
}
 
 
Segment segment = roadnetwork.getSegmentsMap().get(edge.getId());
 
List<Coordinates> geometryList= segment.getGeometryList();
 
for(Coordinates coordinates : geometryList){
 
coordinateList.add(new Point(coordinates.getLat(), coordinates.getLon()));
 
}
 
index ++;
}
}
 
 
// add coordinates of generated end node
 
Long endNodeID = path.getEndVertex();
 
lat = mapper.getNodeMap().get(endNodeID).getLat();
 
lon = mapper.getNodeMap().get(endNodeID).getLon();
 
coordinateList.add(new Point(lat, lon));
return coordinateList;
return coordinateList;
}
}
Loading