This project aims to extend the GraphHopper routing engine to support dynamic constraints. The main use case is to route vehicles through a road network, including blocked areas and optionally considering the traffic data to weight the map edges.
It uses a typical time trend in order to get the traffic density of each edge, and uses these values to calculate the best path.
This also supports the specification of areas to avoid during navigation, called blocked areas.
The project is a Maven project. In order to install the dependencies you can use the following command:
mvn clean installIt is possible to compile and package the project with the following command:
mvn packageThis will create a .war file in the target folder.
The code is described by the following class diagram:
The main class is the Servlet.java class.
It is a Jersey servlet that can be deployed in a servlet container (e.g. Tomcat).
The servlet uses the following classes:
DynamicGraphHopper: it extends theGraphHopperclass to support dynamic constraints. It uses theDynamicOSMReaderclass to read the OSM file and create a mapping between the OSM way IDs and the GraphHopper's Edge IDs. This class has a Factory method (createWeightingFactory()) to create the WeightingFactory to use to create the Weighting for each edge, for example aFastestWeightingWithTraffic. It also reads the historical traffic data from some JSON filesDynamicOSMReader: it extends theOSMReaderclass in order to take note of the mapping between the OSM way IDs and the GraphHopper's Edge IDsFastestWeightingWithTraffic: it extends theFastestWeightingclass to support the traffic data. It calculates the time needed to traverse an edge considering the traffic data, following the Greenshield's model
The DynamicGraphHopper class has a setBlockArea() method that can be used to block certain areas, and uses the
default BlockAreaWeighting class to block the areas, that wraps the chosen Weighting (e.g. create
a FastestWeightingWithTraffic and wrap it with a BlockAreaWeighting).
The servlet only has the /route endpoint that accepts HTTP GET requests.
The request can have the following parameters:
vehicle: the vehicle profile to use (e.g.vehicle=car). The possible values are the ones supported by GraphHopper- Default:
car
- Default:
waypoints: a list of waypoints separated by;(e.g.waypoints=lat1,lon1;lat2,lon2;lat3,lon3), wherelatandlonare the latitude and longitude of the waypoint. The first waypoint is the start point, the last waypoint is the end point, and the others are the intermediate pointsavoid_area: areas to avoid during navigation. It should be specified as a JSON, and it should be a * FeatureCollection* that can contain different shapes:Polygon,Circle,BBox,Point.- Default: empty
startDateTime: the start date and time of the route. It should be specified as a string in the formatyyyy-MM-dd'T'HH:mm:ss- Default: current date and time
weighting: the weighting to use for the route calculation. The possible values are the ones supported by GraphHopper, with the adding offastest_with_traffic.- Default:
fastest
- Default:
The response is a JSON with a list of instructions to follow to reach the destination. The instructions are the same as the ones returned by GraphHopper, and contain the following fields:
text: description of the instructionstreet_name: the name of the streettime: the time neededdistance: the distance to coversigninterval- ... other extra info
