Skip to content

Commit

Permalink
feat(routing): upgrade to GraphHopper 8.0 (#363)
Browse files Browse the repository at this point in the history
* feat(routing): upgrade GraphHopper to 8.0, several refactorings
* fix(routing): fixed speed conversion
* fix(routing): allow configuring alternative route parameters
* test: reverted accidental commit
* feat(routing): reactivate cleanup, move weighting instantiation to weightingFactory
* fix(routing): resolved compilation error
* fix(routing): removed double configuration of alternative route params
* fix(routing): resolve spotbugs warnings
* refactor(routing): get rid of ExtendedGraphHopper, load grap in GraphHopperRouting instead
* legal: approve third party content
* clean: re-added valuable comment about virtual edges
* clean: removed unused GraphLoader interface, moved VehicleEncoding to utils
* clean: make alternative routing parameters accessible to alter via trafficgen
* fix(routing): revive changes overridden by merge
* fix(mosaic-routing): calcEdgeWeight should return values as seconds
* fix(mosaic-routing): round max speed before
 cutting decimal places
* test(mosaic-routing): use 60 km/h as speed for test graph to restore old behaviour
* clean(mosaic-routing): minor cleanup after self-review
* fix(routing): fixed waytype encoding and addressed further cleanups after review
* fix(routing): suppress spotbugs warning
  • Loading branch information
kschrab authored Mar 21, 2024
1 parent 2767799 commit 7bdf6ae
Show file tree
Hide file tree
Showing 43 changed files with 1,433 additions and 2,674 deletions.
70 changes: 39 additions & 31 deletions NOTICE-THIRD-PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ FindBugs-jsr305 (3.0.2)
* Source: https://code.google.com/p/jsr-305/


GraphHopper API (0.13.0)

* License: Apache License, Version 2.0
* Maven artifact: `com.graphhopper:graphhopper-api:0.13.0`
* Project: https://www.graphhopper.com/graphhopper-api
* Source: https://github.com/graphhopper/graphhopper/graphhopper-api


GraphHopper Core (0.13.0)
GraphHopper Core (8.0)

* License: The Apache Software License, Version 2.0
* Maven artifact: `com.graphhopper:graphhopper-core:0.13.0`
* Maven artifact: `com.graphhopper:graphhopper-core:8.0`
* Project: https://www.graphhopper.com/graphhopper-core
* Source: https://github.com/graphhopper/graphhopper/graphhopper-core


GraphHopper Web API (8.0)

* License: Apache License, Version 2.0
* Maven artifact: `com.graphhopper:graphhopper-web-api:8.0`
* Project: https://www.graphhopper.com/graphhopper-web-api
* Source: https://github.com/graphhopper/graphhopper/graphhopper-web-api


Gson (2.10.1)

* License: Apache-2.0
Expand All @@ -133,46 +133,46 @@ HPPC Collections (0.8.1)
* Source: https://github.com/carrotsearch/hppc/hppc


Jackson module: JAXB Annotations (2.9.9)
Jackson-annotations (2.15.0)

* License: The Apache Software License, Version 2.0
* Maven artifact: `com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.9.9`
* Project: https://github.com/FasterXML/jackson-modules-base
* Source: https://github.com/FasterXML/jackson-modules-base/jackson-module-jaxb-annotations


Jackson-annotations (2.9.0)

* License: The Apache Software License, Version 2.0
* Maven artifact: `com.fasterxml.jackson.core:jackson-annotations:2.9.0`
* Project: http://github.com/FasterXML/jackson
* Maven artifact: `com.fasterxml.jackson.core:jackson-annotations:2.15.0`
* Project: https://github.com/FasterXML/jackson
* Source: https://github.com/FasterXML/jackson-annotations


Jackson-core (2.9.9)
Jackson-core (2.15.0)

* License: The Apache Software License, Version 2.0
* Maven artifact: `com.fasterxml.jackson.core:jackson-core:2.9.9`
* Maven artifact: `com.fasterxml.jackson.core:jackson-core:2.15.0`
* Project: https://github.com/FasterXML/jackson-core
* Source: https://github.com/FasterXML/jackson-core


jackson-databind (2.9.9)
jackson-databind (2.15.0)

* License: The Apache Software License, Version 2.0
* Maven artifact: `com.fasterxml.jackson.core:jackson-databind:2.9.9`
* Project: http://github.com/FasterXML/jackson
* Maven artifact: `com.fasterxml.jackson.core:jackson-databind:2.15.0`
* Project: https://github.com/FasterXML/jackson
* Source: https://github.com/FasterXML/jackson-databind


Jackson-dataformat-XML (2.9.9)
Jackson-dataformat-XML (2.15.0)

* License: The Apache Software License, Version 2.0
* Maven artifact: `com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.9`
* Project: http://wiki.fasterxml.com/JacksonExtensionXmlDataBinding
* Maven artifact: `com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.0`
* Project: https://github.com/FasterXML/jackson-dataformat-xml
* Source: https://github.com/FasterXML/jackson-dataformat-xml


Jackson-datatype-jts (2.14)

* License: The Apache Software License, Version 2.0
* Maven artifact: `com.graphhopper.external:jackson-datatype-jts:2.14`
* Project: https://github.com/bedatadriven/jackson-datatype-jts/
* Source: scm:git:https://github.com/bedatadriven/jackson-datatype-jts


Janino (2.7.5)

* License: New BSD License
Expand Down Expand Up @@ -237,6 +237,14 @@ org.leadpony.justify (1.1.0)
* Source: https://github.com/leadpony/justify


org.locationtech.jts:jts-core (1.19.0)

* License: Eclipse Distribution License - v 1.0, Eclipse Public License, Version 2.0
* Maven artifact: `org.locationtech.jts:jts-core:1.19.0`
* Project: https://www.locationtech.org/projects/technology.jts/jts-modules/jts-core
* Source: https://github.com/locationtech/jts/jts-modules/jts-core


Protocol Buffers [Core] (3.8.0)

* License: 3-Clause BSD License
Expand Down Expand Up @@ -269,10 +277,10 @@ Stax2 API (4.2.1)
* Source: https://github.com/FasterXML/stax2-api


Woodstox (5.1.0)
Woodstox (6.5.1)

* License: The Apache License, Version 2.0
* Maven artifact: `com.fasterxml.woodstox:woodstox-core:5.1.0`
* Maven artifact: `com.fasterxml.woodstox:woodstox-core:6.5.1`
* Project: https://github.com/FasterXML/woodstox
* Source: https://github.com/FasterXML/woodstox

Expand Down
4 changes: 3 additions & 1 deletion bundle/src/assembly/mosaic-bundle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@
<!-- [END] XML object binding -->

<!-- [START] GraphHopper dependencies -->
<include>com.graphhopper:graphhopper-api</include>
<include>com.graphhopper:graphhopper-web-api</include>
<include>com.graphhopper:graphhopper-core</include>
<include>com.graphhopper.external:jackson-datatype-jts</include>
<include>com.carrotsearch:hppc</include>
<include>org.locationtech.jts:jts-core</include>
<!-- [END] GraphHopper dependencies -->

<include>com.jcraft:jsch</include>
Expand Down
10 changes: 0 additions & 10 deletions lib/mosaic-routing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@
<dependency>
<groupId>com.graphhopper</groupId>
<artifactId>graphhopper-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>xmlgraphics-commons</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,94 @@
*/
public class CandidateRoute {

/**
* The list of connections forming this route.
*/
private final List<String> connectionIds;

/**
* The length in meters of this route.
*/
private final double length;

/**
* The approximated driving time in seconds on this route.
*/
private final double time;

/**
* The distance in meters from the start node of the first connection in the connectionIds list, to
* the point the source query was issued.
*/
private final double offsetFromSource;

/**
* The distance in meters from the point the target query was issued, until the end node of the
* final connection in the connectionIds list.
*/
private final double offsetToTarget;

/**
* @param connectionIds the list of connection id this route persists of.
* @param length the length in m of this route.
* @param time the approximate travel time in seconds of this route.
*/
public CandidateRoute(List<String> connectionIds, double length, double time) {
this(connectionIds, length, time, 0, 0);
}

/**
*
* @param connectionIds the list of connection id this route persists of.
* @param length the length in m of this route.
* @param time the approximate travel time in seconds of this route.
* @param offsetFromSource the distance in meters from the start node of the first connection in the connectionIds list, to
* the point the source query was issued.
* @param offsetToTarget the distance in meters from the point the target query was issued, until the end node of the
* final connection in the connectionIds list.
*/
public CandidateRoute(List<String> connectionIds, double length, double time, double offsetFromSource, double offsetToTarget) {
this.connectionIds = connectionIds;
this.length = length;
this.time = time;
this.offsetFromSource = offsetFromSource;
this.offsetToTarget = offsetToTarget;
}

/**
* @return the list of connection ids forming this route.
*/
public List<String> getConnectionIds() {
return connectionIds;
}

/**
* @return the length in meters of this route.
*/
public double getLength() {
return length;
}

/**
* @return the approximated driving time in seconds on this route.
*/
public double getTime() {
return time;
}

/**
* @return the distance in meters from the start node of the first connection in the connectionIds list, to
* the point the source query was issued.
*/
public double getOffsetFromSource() {
return offsetFromSource;
}

/**
* @return the distance in meters from the point the target query was issued, until
* the end node of the final connection in the connectionIds list.
*/
public double getOffsetToTarget() {
return offsetToTarget;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public void initialize(final CRouting configuration, final File baseDirectory) t
}

//creates an implementation of IRoutingGraph according to the configuration
this.routing = new GraphHopperRouting()
.loadGraphFromDatabase(scenarioDatabase);
this.routing = new GraphHopperRouting(scenarioDatabase);

this.routeManager = new RouteManager(this.scenarioDatabase);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import org.eclipse.mosaic.lib.routing.EdgeProperties;
import org.eclipse.mosaic.lib.routing.RoutingCostFunction;
import org.eclipse.mosaic.lib.routing.graphhopper.util.GraphhopperToDatabaseMapper;
import org.eclipse.mosaic.lib.routing.graphhopper.util.VehicleEncoding;
import org.eclipse.mosaic.lib.routing.graphhopper.util.WayTypeEncoder;

import com.google.common.collect.Iterables;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.FetchMode;
import org.apache.commons.lang3.Validate;

import java.util.Optional;
Expand All @@ -32,16 +34,18 @@
* Provides properties from the current {@link EdgeIteratorState} or
* its belonging {@link Connection} to be used by an {@link RoutingCostFunction}.
*/
class GraphHopperEdgeProperties implements EdgeProperties {
public class GraphHopperEdgeProperties implements EdgeProperties {

private final FlagEncoder flagEncoder;
private final VehicleEncoding encoding;
private final WayTypeEncoder wayTypeEncoder;
private final GraphhopperToDatabaseMapper graphMapper;

private EdgeIteratorState currentEdgeIterator;
private boolean reverseRequests;

GraphHopperEdgeProperties(FlagEncoder encoder, GraphhopperToDatabaseMapper graphMapper) {
this.flagEncoder = encoder;
GraphHopperEdgeProperties(VehicleEncoding encoding, WayTypeEncoder wayTypeEncoder, GraphhopperToDatabaseMapper graphMapper) {
this.encoding = encoding;
this.wayTypeEncoder = wayTypeEncoder;
this.graphMapper = graphMapper;
}

Expand All @@ -54,9 +58,9 @@ void setCurrentEdgeIterator(EdgeIteratorState currentEdgeIterator, boolean rever
@Override
public double getSpeed() {
Validate.notNull(currentEdgeIterator, "Edge iterator is null");
return (reverseRequests
? currentEdgeIterator.getReverse(flagEncoder.getAverageSpeedEnc())
: currentEdgeIterator.get(flagEncoder.getAverageSpeedEnc())) / 3.6d;
return reverseRequests
? currentEdgeIterator.getReverse(encoding.speed()) / 3.6
: currentEdgeIterator.get(encoding.speed()) / 3.6;
}

@Override
Expand All @@ -69,8 +73,8 @@ public double getLength() {
public Iterable<GeoPoint> getGeometry() {
Validate.notNull(currentEdgeIterator, "Edge iterator is null");
return Iterables.transform(
currentEdgeIterator.fetchWayGeometry(3), // 3 = fetch all pillar nodes inclusive the base and adjacent tower node
ghPoint3D -> GeoPoint.latLon(ghPoint3D.getLat(), ghPoint3D.getLon(), ghPoint3D.getElevation())
currentEdgeIterator.fetchWayGeometry(FetchMode.ALL), // fetches all pillar nodes inclusive the base and adjacent tower node
ghPoint3D -> GeoPoint.latLon(ghPoint3D.getLat(), ghPoint3D.getLon(), ghPoint3D.getEle())
);
}

Expand All @@ -81,7 +85,11 @@ public String getConnectionId() {

@Override
public String getWayType() {
return getConnection().map(con -> con.getWay().getType()).orElse(null);
return WayTypeEncoder.decode(getWayTypeEncoded());
}

public int getWayTypeEncoded() {
return currentEdgeIterator.get(wayTypeEncoder);
}

private Optional<Connection> getConnection() {
Expand Down
Loading

0 comments on commit 7bdf6ae

Please sign in to comment.