Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routing): upgrade to GraphHopper 8.0 #363

Merged
merged 22 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
354edb0
feat(routing): upgrade GraphHopper to 8.0, several refactorings
kschrab Oct 31, 2023
e29df56
fix(routing): fixed speed conversion
kschrab Oct 31, 2023
2ca4bee
fix(routing): allow configuring alternative route parameters
kschrab Nov 2, 2023
b587e47
test: reverted accidental commit
kschrab Nov 2, 2023
1d19f29
feat(routing): reactivate cleanup, move weighting instantiation to we…
kschrab Nov 2, 2023
1a16932
fix(routing): resolved compilation error
kschrab Nov 2, 2023
1b00f5d
fix(routing): removed double configuration of alternative route params
kschrab Nov 2, 2023
ce8cc96
fix(routing): resolve spotbugs warnings
kschrab Nov 2, 2023
f242643
refactor(routing): get rid of ExtendedGraphHopper, load grap in Graph…
kschrab Nov 3, 2023
d09edd4
legal: approve third party content
kschrab Nov 3, 2023
f519de7
clean: re-added valuable comment about virtual edges
kschrab Nov 3, 2023
fc608a0
clean: removed unused GraphLoader interface, moved VehicleEncoding to…
kschrab Nov 3, 2023
5714d91
clean: make alternative routing parameters accessible to alter via tr…
kschrab Nov 3, 2023
2a29681
Merge remote-tracking branch 'origin/main' into 716-graphhopper-8
kschrab Jan 29, 2024
4b297ea
fix(routing): revive changes overridden by merge
kschrab Jan 29, 2024
ed25671
fix(mosaic-routing): calcEdgeWeight should return values as seconds
kschrab Jan 31, 2024
e8223d5
fix(mosaic-routing): round max speed before
kschrab Jan 31, 2024
c3819c0
test(mosaic-routing): use 60 km/h as speed for test graph to restore …
kschrab Jan 31, 2024
5a685f4
clean(mosaic-routing): minor cleanup after self-review
kschrab Jan 31, 2024
1fcfaf0
Merge remote-tracking branch 'origin/main' into 716-graphhopper-8
kschrab Mar 20, 2024
7128d75
fix(routing): fixed waytype encoding and addressed further cleanups a…
kschrab Mar 21, 2024
dc8deb0
fix(routing): suppress spotbugs warning
kschrab Mar 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
schwepmo marked this conversation as resolved.
Show resolved Hide resolved


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 @@ -27,10 +27,20 @@ public class CandidateRoute {
private final double length;
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
private final double time;
schwepmo marked this conversation as resolved.
Show resolved Hide resolved

private final double offsetToTarget;

private final double offsetFromSource;
schwepmo marked this conversation as resolved.
Show resolved Hide resolved

public CandidateRoute(List<String> connectionIds, double length, double time) {
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
this(connectionIds, length, time, 0, 0);
}

public CandidateRoute(List<String> connectionIds, double length, double time, double offsetFromSource, double offsetToTarget) {
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
this.connectionIds = connectionIds;
this.length = length;
this.time = time;
this.offsetFromSource = offsetFromSource;
this.offsetToTarget = offsetToTarget;
}

public List<String> getConnectionIds() {
Expand All @@ -44,4 +54,12 @@ public double getLength() {
public double getTime() {
return time;
}

public double getOffsetFromSource() {
return offsetFromSource;
}

public double getOffsetToTarget() {
return offsetToTarget;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public CandidateRoute approximateCostsForCandidateRoute(CandidateRoute route, St
length += con.getLength();
time += con.getLength() / con.getMaxSpeedInMs();
}
return new CandidateRoute(route.getConnectionIds(), length, time);
return new CandidateRoute(route.getConnectionIds(), length, time, 0, Double.POSITIVE_INFINITY);
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
}

private Edge findClosestEdge(GeoPoint location) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Copyright (c) 2020 Fraunhofer FOKUS and others. All rights reserved.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contact: [email protected]
*/

package org.eclipse.mosaic.lib.routing.graphhopper;

import org.eclipse.mosaic.lib.routing.RoutingCostFunction;
import org.eclipse.mosaic.lib.routing.graphhopper.util.GraphhopperToDatabaseMapper;
import org.eclipse.mosaic.lib.routing.graphhopper.util.TurnCostsProvider;

import com.graphhopper.GHRequest;
import com.graphhopper.GHResponse;
import com.graphhopper.GraphHopper;
import com.graphhopper.config.Profile;
import com.graphhopper.routing.WeightingFactory;
import com.graphhopper.routing.ev.Subnetwork;
import com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.weighting.Weighting;
import com.graphhopper.storage.BaseGraph;
import com.graphhopper.storage.RAMDirectory;
import com.graphhopper.util.Helper;
import com.graphhopper.util.PMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
* An extension of GraphHopper which is able to import map data from the MOSAIC scenario database.
* Routing functionality is implemented {@link org.eclipse.mosaic.lib.routing.graphhopper.GraphHopperRouting}.
*/
class ExtendedGraphHopper extends GraphHopper {

static final String WEIGHTING_TURN_COSTS = "weighting.turnCosts";
static final String WEIGHTING_COST_FUNCTION = "weighting.costFunction";
static final String WEIGHTING_GRAPH_MAPPER = "weighting.graphMapper";

private final Logger logger = LoggerFactory.getLogger(getClass());

protected GraphLoader graphLoader;
protected GraphhopperToDatabaseMapper mapper;
protected VehicleEncodingManager encodingManager;

private boolean fullyLoaded = false;

ExtendedGraphHopper(VehicleEncodingManager encoding, GraphLoader graphLoader, GraphhopperToDatabaseMapper mapper) {
this.graphLoader = graphLoader;
this.mapper = mapper;
this.encodingManager = encoding;

setProfiles(encoding.getAllProfiles());
}

@Override
public EncodingManager getEncodingManager() {
return encodingManager.getEncodingManager();
}

@Override
public GraphHopper importOrLoad() {
fullyLoaded = false;

setBaseGraph(new BaseGraph
.Builder(getEncodingManager())
.setDir(new RAMDirectory())
.set3D(false)
.withTurnCosts(getEncodingManager().needsTurnCostsSupport())
.setSegmentSize(-1)
.build()
);

importDB(getGraphHopperLocation());
fullyLoaded = true;
return this;
}

@Override
protected WeightingFactory createWeightingFactory() {
return (profile, hints, b) -> {
final VehicleEncoding vehicleEncoding = encodingManager.getVehicleEncoding(profile.getVehicle());

final TurnCostsProvider turnCostProvider = new TurnCostsProvider(vehicleEncoding, getBaseGraph().getTurnCostStorage());
if (!hints.getBool(WEIGHTING_TURN_COSTS, false)) {
turnCostProvider.disableTurnCosts();
}
final GraphhopperToDatabaseMapper graphMapper = hints.getObject(WEIGHTING_GRAPH_MAPPER, null);
final RoutingCostFunction costFunction = hints.getObject(WEIGHTING_COST_FUNCTION, RoutingCostFunction.Default);
return new GraphHopperWeighting(vehicleEncoding, encodingManager.wayType(), turnCostProvider, graphMapper)
.setRoutingCostFunction(costFunction);
};
}

private void importDB(String ignore) {
if (getBaseGraph() == null) {
throw new IllegalStateException("Load or init graph before import database");
}

if (mapper == null) {
throw new IllegalStateException("A mapper is required for importing database");
}

logger.info("start creating graph from database");

graphLoader.initialize(getBaseGraph(), encodingManager, mapper);
graphLoader.loadGraph();

postProcessing(false);
try {
cleanUp();
} catch (Exception e) {
logger.warn("Could not clean up routing graph, skipping. Routing might not work as expected!", e);
}
getBaseGraph().flush();
}

@Override
public boolean getFullyLoaded() {
return fullyLoaded;
}

@Override
public GHResponse route(GHRequest request) {
throw new UnsupportedOperationException("Routing Logic is implemented in GraphHopperRouting.");
}

/* the following code has been copied and adjusted from original GraphHopper repository.
* This was necessary, since `encodingManager` in `GraphHopper` is private, cannot be set from outside, and is used directly
* in `buildSubnetworkRemovalJobs`. */
@Override
protected void cleanUp() {
PrepareRoutingSubnetworks preparation = new PrepareRoutingSubnetworks(getBaseGraph(), buildSubnetworkRemovalJobs());
preparation.setMinNetworkSize(200);
preparation.setThreads(1);
preparation.doWork();
logger.info("nodes: " + Helper.nf(getBaseGraph().getNodes()) + ", edges: " + Helper.nf(getBaseGraph().getEdges()));
}

private List<PrepareRoutingSubnetworks.PrepareJob> buildSubnetworkRemovalJobs() {
List<PrepareRoutingSubnetworks.PrepareJob> jobs = new ArrayList<>();
for (Profile profile : getProfiles()) {
Weighting weighting = createWeighting(profile, new PMap());
// here we use `getEncodingManager()` instead of `encodingManager`, making this code work
jobs.add(new PrepareRoutingSubnetworks.PrepareJob(getEncodingManager().getBooleanEncodedValue(Subnetwork.key(profile.getName())), weighting));
}
return jobs;
}

}
Loading
Loading