Skip to content
Snippets Groups Projects
Commit 00f533d6 authored by theiled00's avatar theiled00
Browse files

Central config

parent 584ad782
Branches
No related tags found
1 merge request!20Central config
...@@ -6,23 +6,28 @@ services: ...@@ -6,23 +6,28 @@ services:
volumes: volumes:
- road-network:/data/road_network - road-network:/data/road_network
- metrics:/data/metrics - metrics:/data/metrics
- config:/data/configuration
restart: on-failure restart: on-failure
ports: ports:
- 8080:8080 - 8080:8080
metric-builder: metric-builder:
build: ../metric-builder/metricbuilder build: ../metric-builder/metricbuilder
image: metric-builder:latest image: metric-builder:latest
restart: on-failure
volumes: volumes:
- road-network:/data/road_network - road-network:/data/road_network
- metrics:/data/metrics - metrics:/data/metrics
- config:/data/configuration
restart: on-failure restart: on-failure
map-builder: map-builder:
build: ../map-data-parser/mapbuilder build: ../map-data-parser/mapbuilder
image: map-builder:latest image: map-builder:latest
volumes: volumes:
- road-network:/data/road_network - road-network:/data/road_network
- config:/data/configuration
restart: on-failure restart: on-failure
volumes: volumes:
road-network: road-network:
metrics: metrics:
config:
\ No newline at end of file
...@@ -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();
double lat = mapper.getNodeMap().get(startNodeID).getLat();
double lon = mapper.getNodeMap().get(startNodeID).getLon();
coordinateList.add(new Point(lat, lon)); 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;
} }
......
...@@ -22,6 +22,14 @@ public class Config { ...@@ -22,6 +22,14 @@ public class Config {
*/ */
public static String METRICS_INPUT_PATH = "routing-server/src/main/resources/metrics.proto"; public static String METRICS_INPUT_PATH = "routing-server/src/main/resources/metrics.proto";
/**
* Bounding box, default small box inside Cottbus
*/
public static float BOUNDING_BOX_MIN_LAT = 51.765120241998865f;
public static float BOUNDING_BOX_MIN_LON = 14.32669617537409f;
public static float BOUNDING_BOX_MAX_LAT = 51.77116774623326f;
public static float BOUNDING_BOX_MAX_LON = 14.330334220133722f;
public static void load() { public static void load() {
//The config is used for running the application in a Docker container //The config is used for running the application in a Docker container
String configFilePath = "/data/configuration/config.properties"; String configFilePath = "/data/configuration/config.properties";
...@@ -29,8 +37,13 @@ public class Config { ...@@ -29,8 +37,13 @@ public class Config {
try (FileInputStream is = new FileInputStream(configFilePath)){ try (FileInputStream is = new FileInputStream(configFilePath)){
props.load(is); props.load(is);
ROAD_NETWORK_INPUT_PATH = props.getProperty("ROAD_NETWORK_INPUT_PATH", ROAD_NETWORK_INPUT_PATH); ROAD_NETWORK_INPUT_PATH = props.getProperty("ROUTING_SERVICE_ROAD_NETWORK_INPUT_PATH", ROAD_NETWORK_INPUT_PATH);
METRICS_INPUT_PATH = props.getProperty("METRICS_INPUT_PATH", METRICS_INPUT_PATH); METRICS_INPUT_PATH = props.getProperty("ROUTING_SERVICE_METRICS_INPUT_PATH", METRICS_INPUT_PATH);
BOUNDING_BOX_MIN_LAT = Float.parseFloat(props.getProperty("BOUNDING_BOX_MIN_LAT", String.valueOf(BOUNDING_BOX_MIN_LAT)));
BOUNDING_BOX_MIN_LON = Float.parseFloat(props.getProperty("BOUNDING_BOX_MIN_LON", String.valueOf(BOUNDING_BOX_MIN_LON)));
BOUNDING_BOX_MAX_LAT = Float.parseFloat(props.getProperty("BOUNDING_BOX_MAX_LAT", String.valueOf(BOUNDING_BOX_MAX_LAT)));
BOUNDING_BOX_MAX_LON = Float.parseFloat(props.getProperty("BOUNDING_BOX_MAX_LON", String.valueOf(BOUNDING_BOX_MAX_LON)));
System.out.println("Config loaded."); System.out.println("Config loaded.");
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// Either way the Docker image was build wrong or this is not // Either way the Docker image was build wrong or this is not
......
...@@ -22,6 +22,8 @@ import de.fuberlin.navigator.protos.map_builder.RoadNetwork; ...@@ -22,6 +22,8 @@ import de.fuberlin.navigator.protos.map_builder.RoadNetwork;
import de.fuberlin.navigator.protos.map_builder.Segment; import de.fuberlin.navigator.protos.map_builder.Segment;
import de.fuberlin.navigator.routingserver.model.MatchedPoint; import de.fuberlin.navigator.routingserver.model.MatchedPoint;
import static de.fuberlin.navigator.routingserver.utility.Config.*;
public class MapMatcher { public class MapMatcher {
private static final String NOMINATIM_ENDPOINT = "https://nominatim.openstreetmap.org/search?"; private static final String NOMINATIM_ENDPOINT = "https://nominatim.openstreetmap.org/search?";
...@@ -45,7 +47,12 @@ public class MapMatcher { ...@@ -45,7 +47,12 @@ public class MapMatcher {
if (coordinate == null) { if (coordinate == null) {
return AddressMatchingResponse.addressNotFound(); return AddressMatchingResponse.addressNotFound();
} }
//TODO check if address is in our road network
if (coordinate.getLat() < BOUNDING_BOX_MIN_LAT || coordinate.getLat() > BOUNDING_BOX_MAX_LAT
|| coordinate.getLon() < BOUNDING_BOX_MIN_LON || coordinate.getLon() > BOUNDING_BOX_MAX_LON) {
//coordinate is not in our road network
return AddressMatchingResponse.addressNotInRoadNetwork();
}
return AddressMatchingResponse.of(coordinate); return AddressMatchingResponse.of(coordinate);
} }
...@@ -88,29 +95,6 @@ public class MapMatcher { ...@@ -88,29 +95,6 @@ public class MapMatcher {
return new Point(latitude, longitude); return new Point(latitude, longitude);
} }
public static String getAddress(Double lat, Double lon) throws IOException {
String requestUrl = NOMINATIM_ENDPOINT + "q=" + lat + "," + lon + "&" + FORMAT_PARAM;
// Send the request and parse the response
URL url = new URL(requestUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
InputStream responseStream = connection.getInputStream();
String responseString = new String(responseStream.readAllBytes(), StandardCharsets.UTF_8);
// Removing first and last character
// because response is in []
responseString = responseString.substring(1, responseString.length() - 1);
// Extract the address/ display name from the response
JSONObject responseJson = new JSONObject(responseString);
return responseJson.getString("display_name");
}
/* /*
* Function which returns the object or set of objects, * Function which returns the object or set of objects,
* which is the start point * which is the start point
......
# Standard config for Docker # Standard config for Docker
ROAD_NETWORK_INPUT_PATH = /data/road_network/roadnetwork.proto # Bounding box around Central + South Brandenburg (about 1.2GB in size)
METRICS_INPUT_PATH = /data/metrics/metrics.proto BOUNDING_BOX_MIN_LAT = 50.92993593954551
\ No newline at end of file BOUNDING_BOX_MIN_LON = 11.333053381241731
BOUNDING_BOX_MAX_LAT = 52.788831211664586
BOUNDING_BOX_MAX_LON = 14.714574575766516
# Routing service specific
ROUTING_SERVICE_ROAD_NETWORK_INPUT_PATH = /data/road_network/roadnetwork.proto
ROUTING_SERVICE_METRICS_INPUT_PATH = /data/metrics/metrics.proto
# Map builder specific
MAP_BUILDER_ROAD_NETWORK_OUTPUT_PATH = /data/road_network/roadnetwork.proto
# Metric builder specific
METRIC_BUILDER_ROAD_NETWORK_INPUT_PATH = /data/road_network/roadnetwork.proto
METRIC_BUILDER_METRICS_OUTPUT_PATH = /data/metrics/metrics.proto
METRIC_BUILDER_WEATHER_GRID_CELL_DISTANCE = 0.25
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment