Skip to content

Commit

Permalink
Merge branch 'master' into noisyRoadNearby
Browse files Browse the repository at this point in the history
  • Loading branch information
ratrun committed Sep 22, 2024
2 parents 00a5383 + 4113169 commit f3203cb
Show file tree
Hide file tree
Showing 43 changed files with 606 additions and 122 deletions.
20 changes: 10 additions & 10 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@

GraphHopper licensed under the Apache license, Version 2.0

Copyright 2012 - 2022 GraphHopper GmbH
Copyright 2012 - 2024 GraphHopper GmbH

The core module includes the following additional software:

* slf4j.org - SLF4J distributed under the MIT license.
* com.carrotsearch:hppc (Apache license)
* SparseArray from the Android project (Apache license)
* Snippets regarding mmap, vint/vlong and compression from Lucene (Apache license)
* XMLGraphics-Commons for CGIAR elevation files (Apache License)
* Apache Commons Lang - we copied the implementation of the Levenshtein Distance (Apache License)
* Apache Commons Collections - we copied parts of the BinaryHeap (Apache License)
* Apache Commons Lang - we copied the implementation of the Levenshtein Distance - see com.graphhopper.apache.commons.lang3 (Apache License)
* Apache Commons Collections - we copied parts of the BinaryHeap - see com.graphhopper.apache.commons.collections (Apache License)
* java-string-similarity - we copied the implementation of JaroWinkler (MIT license)
* Jackson (Apache License)
* org.locationtech:jts (EDL), see #1039
* org.locationtech:jts (EDL)
* AngleCalc.atan2 from Jim Shima, 1999 (public domain)
* janino compiler (BSD-3-Clause license)
* protobuf - New BSD license
* OSM-binary - LGPL license
* osm-legal-default-speeds-jvm (BSD-3-Clause license)
* kotlin stdlib (Apache License)
* protobuf - (New BSD license)
* OSM-binary - (LGPL license)
* Osmosis - public domain, see their github under package/copying.txt

reader-gtfs:

* some files from com.conveyal:gtfs-lib (BSD 2-clause license)
* com.google.transit:gtfs-realtime-bindings (Apache license)
* com.google.guava:guava (Apache license)
Expand All @@ -43,8 +44,7 @@ web:

* org.eclipse.jetty:jetty-server (Apache License)
* Dropwizard and dependencies (Apache license)
* no.ecc:java-vector-tile (Apache license)
* some images from mapbox https://www.mapbox.com/maki/, BSD License, see core/files
* classes in no.ecc are a copy of no.ecc.vectortile:java-vector-tile, see #2698 (Apache license)

## Data

Expand Down
1 change: 1 addition & 0 deletions client-hc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<artifactId>graphhopper-web-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!-- use same kotlin stdlib version as we use in core -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public void customModel() throws JsonProcessingException {
"\"type\":\"FeatureCollection\",\"features\":[" +
"{\"id\":\"area_1\",\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[48.019324184801185,11.28021240234375],[48.019324184801185,11.53564453125],[48.11843396091691,11.53564453125],[48.11843396091691,11.28021240234375],[48.019324184801185,11.28021240234375]]]},\"properties\":{}}," +
"{\"id\":\"area_2\",\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[48.15509285476017,11.53289794921875],[48.15509285476017,11.8212890625],[48.281365151571755,11.8212890625],[48.281365151571755,11.53289794921875],[48.15509285476017,11.53289794921875]]]},\"properties\":{}}]}," +
"\"speed\":[{\"if\":\"road_class == MOTORWAY\",\"limit_to\":\"80\"}]," +
"\"priority\":[{\"if\":\"surface == DIRT\",\"multiply_by\":\"0.7\"},{\"if\":\"surface == SAND\",\"multiply_by\":\"0.6\"}]}");
"\"priority\":[{\"if\":\"surface == DIRT\",\"multiply_by\":\"0.7\"},{\"if\":\"surface == SAND\",\"multiply_by\":\"0.6\"}]," +
"\"speed\":[{\"if\":\"road_class == MOTORWAY\",\"limit_to\":\"80\"}]}");
assertEquals(expected, objectMapper.valueToTree(customModelJson));

CustomModel cm = objectMapper.readValue("{\"distance_influence\":null}", CustomModel.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@

package com.graphhopper.api.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.graphhopper.jackson.Jackson;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Envelope;

import static io.dropwizard.testing.FixtureHelpers.fixture;
import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;


public class GHGeocodingResponseRepresentationTest {

@Test
public void testGeocodingRepresentation() throws JsonProcessingException {
public void testGeocodingRepresentation() throws IOException {
ObjectMapper objectMapper = Jackson.newObjectMapper();
GHGeocodingResponse geocodingResponse = objectMapper.readValue(fixture("fixtures/geocoding-response.json"), GHGeocodingResponse.class);
GHGeocodingResponse geocodingResponse = objectMapper.readValue(getClass().getResource("/fixtures/geocoding-response.json"), GHGeocodingResponse.class);
Envelope extent = geocodingResponse.getHits().get(0).getExtent();
// Despite the unusual representation of the bounding box...
assertEquals(10.0598605, extent.getMinX(), 0.0);
Expand Down
3 changes: 2 additions & 1 deletion config-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ graphhopper:
# turn_costs:
# vehicle_types: [motorcar, motor_vehicle]
# u_turn_costs: 60
# for more advanced turn costs, see #2957 or bike_tc.yml
custom_model_files: [car.json]

# You can use the following in-built profiles. After you start GraphHopper it will print which encoded values you'll have to add to graph.encoded_values in this config file.
Expand Down Expand Up @@ -67,7 +68,7 @@ graphhopper:
# It's possible to speed up routing by doing a special graph preparation (Contraction Hierarchies, CH). This requires
# more RAM/disk space for holding the prepared graph but also means less memory usage per request. Using the following
# list you can define for which of the above routing profiles such preparation shall be performed. Note that to support
# profiles with `turn_costs: true` a more elaborate preparation is required (longer preparation time and more memory
# profiles with `turn_costs` a more elaborate preparation is required (longer preparation time and more memory
# usage) and the routing will also be slower than with `turn_costs: false`.
profiles_ch:
- profile: car
Expand Down
13 changes: 8 additions & 5 deletions core/src/main/java/com/graphhopper/GraphHopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -624,16 +624,19 @@ protected List<String> getEVSortIndex(Map<String, Profile> profilesByName) {
protected OSMParsers buildOSMParsers(Map<String, PMap> encodedValuesWithProps,
Map<String, ImportUnit> activeImportUnits,
Map<String, List<String>> restrictionVehicleTypesByProfile,
List<String> ignoredHighways, String dateRangeParserString) {
List<String> ignoredHighways) {
ImportUnitSorter sorter = new ImportUnitSorter(activeImportUnits);
Map<String, ImportUnit> sortedImportUnits = new LinkedHashMap<>();
sorter.sort().forEach(name -> sortedImportUnits.put(name, activeImportUnits.get(name)));
DateRangeParser dateRangeParser = DateRangeParser.createInstance(dateRangeParserString);
List<TagParser> sortedParsers = new ArrayList<>();
sortedImportUnits.forEach((name, importUnit) -> {
BiFunction<EncodedValueLookup, PMap, TagParser> createTagParser = importUnit.getCreateTagParser();
if (createTagParser != null)
sortedParsers.add(createTagParser.apply(encodingManager, encodedValuesWithProps.getOrDefault(name, new PMap().putObject("date_range_parser", dateRangeParser))));
if (createTagParser != null) {
PMap pmap = encodedValuesWithProps.getOrDefault(name, new PMap());
if (!pmap.has("date_range_parser_day"))
pmap.putObject("date_range_parser_day", dateRangeParserString);
sortedParsers.add(createTagParser.apply(encodingManager, pmap));
}
});

OSMParsers osmParsers = new OSMParsers();
Expand Down Expand Up @@ -873,7 +876,7 @@ protected void prepareImport() {
deque.addAll(importUnit.getRequiredImportUnits());
}
encodingManager = buildEncodingManager(encodedValuesWithProps, activeImportUnits, restrictionVehicleTypesByProfile);
osmParsers = buildOSMParsers(encodedValuesWithProps, activeImportUnits, restrictionVehicleTypesByProfile, osmReaderConfig.getIgnoredHighways(), dateRangeParserString);
osmParsers = buildOSMParsers(encodedValuesWithProps, activeImportUnits, restrictionVehicleTypesByProfile, osmReaderConfig.getIgnoredHighways());
}

protected void postImportOSM() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


/**
* This class is a partial Copy of the org.apache.commons.lang3.StringUtils
* This class is a partial copy of the org.apache.commons.lang3.StringUtils
* that can be found here: https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/StringUtils.java
* <p>
* The library can be found here: https://commons.apache.org/proper/commons-lang/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ public NodeResult convertForViaNode(LongArrayList fromWays, int viaNode, LongArr
result.fromEdges.add(e.value);
});
if (result.fromEdges.size() < fromWays.size())
throw new OSMRestrictionException("has from member ways that aren't adjacent to the via member node");
throw new OSMRestrictionException("has from-member ways that aren't adjacent to the via-member node");
else if (result.fromEdges.size() > fromWays.size())
throw new OSMRestrictionException("has from member ways that aren't split at the via member node");
throw new OSMRestrictionException("has from-member ways that aren't split at the via-member node");

for (LongCursor toWay : toWays)
edgesByWay.apply(toWay.value).forEachRemaining(e -> {
if (baseGraph.isAdjacentToNode(e.value, viaNode))
result.toEdges.add(e.value);
});
if (result.toEdges.size() < toWays.size())
throw new OSMRestrictionException("has to member ways that aren't adjacent to the via member node");
throw new OSMRestrictionException("has to-member ways that aren't adjacent to the via-member node");
else if (result.toEdges.size() > toWays.size())
throw new OSMRestrictionException("has to member ways that aren't split at the via member node");
throw new OSMRestrictionException("has to-member ways that aren't split at the via-member node");
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.graphhopper.config.Profile;
import com.graphhopper.routing.ev.BooleanEncodedValue;
import com.graphhopper.routing.ev.DecimalEncodedValue;
import com.graphhopper.routing.ev.Orientation;
import com.graphhopper.routing.ev.TurnRestriction;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.weighting.DefaultTurnCostProvider;
Expand All @@ -31,6 +33,7 @@
import com.graphhopper.util.CustomModel;
import com.graphhopper.util.PMap;
import com.graphhopper.util.Parameters;
import com.graphhopper.util.TurnCostsConfig;

import static com.graphhopper.routing.weighting.TurnCostProvider.NO_TURN_COST_PROVIDER;
import static com.graphhopper.util.Helper.toLowerCase;
Expand Down Expand Up @@ -59,8 +62,12 @@ public Weighting createWeighting(Profile profile, PMap requestHints, boolean dis
BooleanEncodedValue turnRestrictionEnc = encodingManager.getTurnBooleanEncodedValue(TurnRestriction.key(profile.getName()));
if (turnRestrictionEnc == null)
throw new IllegalArgumentException("Cannot find turn restriction encoded value for " + profile.getName());
DecimalEncodedValue oEnc = encodingManager.hasEncodedValue(Orientation.KEY) ? encodingManager.getDecimalEncodedValue(Orientation.KEY) : null;
if (profile.getTurnCostsConfig().hasLeftRightStraightCosts() && oEnc == null)
throw new IllegalArgumentException("Using left_costs,left_sharp_costs,right_costs,right_sharp_costs or straight_costs for turn_costs requires 'orientation' in graph.encoded_values");
int uTurnCosts = hints.getInt(Parameters.Routing.U_TURN_COSTS, profile.getTurnCostsConfig().getUTurnCosts());
turnCostProvider = new DefaultTurnCostProvider(turnRestrictionEnc, graph.getTurnCostStorage(), uTurnCosts);
TurnCostsConfig tcConfig = new TurnCostsConfig(profile.getTurnCostsConfig()).setUTurnCosts(uTurnCosts);
turnCostProvider = new DefaultTurnCostProvider(turnRestrictionEnc, oEnc, graph, tcConfig);
} else {
turnCostProvider = NO_TURN_COST_PROVIDER;
}
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/com/graphhopper/routing/Router.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@

import java.util.*;

import static com.graphhopper.util.TurnCostsConfig.INFINITE_U_TURN_COSTS;
import static com.graphhopper.util.DistanceCalcEarth.DIST_EARTH;
import static com.graphhopper.util.Parameters.Algorithms.ALT_ROUTE;
import static com.graphhopper.util.Parameters.Algorithms.ROUND_TRIP;
import static com.graphhopper.util.Parameters.Routing.*;
import static com.graphhopper.util.TurnCostsConfig.INFINITE_U_TURN_COSTS;

public class Router {
protected final BaseGraph graph;
Expand Down Expand Up @@ -103,6 +103,7 @@ public GHResponse route(GHRequest request) {
checkPointHints(request);
checkCurbsides(request);
checkNoBlockArea(request);
checkCustomModel(request);

Solver solver = createSolver(request);
solver.checkRequest();
Expand Down Expand Up @@ -180,6 +181,11 @@ private void checkNoBlockArea(GHRequest request) {
throw new IllegalArgumentException("The `block_area` parameter is no longer supported. Use a custom model with `areas` instead.");
}

private void checkCustomModel(GHRequest request) {
if (request.getCustomModel() != null && request.getCustomModel().isInternal())
throw new IllegalArgumentException("CustomModel of query cannot be internal");
}

protected Solver createSolver(GHRequest request) {
final boolean disableCH = getDisableCH(request.getHints());
final boolean disableLM = getDisableLM(request.getHints());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ else if (MaxLength.KEY.equals(name))
(lookup, props) -> new OSMMaxLengthParser(
lookup.getDecimalEncodedValue(MaxLength.KEY))
);
else if (Orientation.KEY.equals(name))
return ImportUnit.create(name, props -> Orientation.create(),
(lookup, props) -> new OrientationCalculator(
lookup.getDecimalEncodedValue(Orientation.KEY))
);
else if (Surface.KEY.equals(name))
return ImportUnit.create(name, props -> Surface.create(),
(lookup, props) -> new OSMSurfaceParser(
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/java/com/graphhopper/routing/ev/Orientation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to GraphHopper GmbH under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* GraphHopper GmbH licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.graphhopper.routing.ev;

public class Orientation {
public static final String KEY = "orientation";

// Due to pillar nodes we need 2 values: the orientation at the adjacent node and the reverse
// value for orientation at the base node. Store in degrees.
public static DecimalEncodedValue create() {
return new DecimalEncodedValueImpl(KEY, 5, 0, 360 / 30.0, false, true, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
*/
public class OSMTemporalAccessParser implements TagParser {

private static final Logger logger = LoggerFactory.getLogger(OSMTemporalAccessParser.class);
private final Collection<String> conditionals;
private final Setter restrictionSetter;
private final DateRangeParser parser;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to GraphHopper GmbH under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* GraphHopper GmbH licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.graphhopper.routing.util.parsers;

import com.graphhopper.reader.ReaderWay;
import com.graphhopper.routing.ev.DecimalEncodedValue;
import com.graphhopper.routing.ev.EdgeIntAccess;
import com.graphhopper.storage.IntsRef;
import com.graphhopper.util.PointList;

import static com.graphhopper.util.AngleCalc.ANGLE_CALC;

public class OrientationCalculator implements TagParser {

private final DecimalEncodedValue orientationEnc;

public OrientationCalculator(DecimalEncodedValue orientationEnc) {
this.orientationEnc = orientationEnc;
}

@Override
public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way, IntsRef relationFlags) {
PointList pointList = way.getTag("point_list", null);
if (pointList != null) {
// store orientation in degrees and use the end of the edge
double azimuth = ANGLE_CALC.calcAzimuth(pointList.getLat(pointList.size() - 2), pointList.getLon(pointList.size() - 2),
pointList.getLat(pointList.size() - 1), pointList.getLon(pointList.size() - 1));
orientationEnc.setDecimal(false, edgeId, edgeIntAccess, azimuth);

// same for the opposite direction
double revAzimuth = ANGLE_CALC.calcAzimuth(pointList.getLat(1), pointList.getLon(1),
pointList.getLat(0), pointList.getLon(0));
orientationEnc.setDecimal(true, edgeId, edgeIntAccess, revAzimuth);
}
}
}

Loading

0 comments on commit f3203cb

Please sign in to comment.