Package com.graphhopper.util
Class GHUtility
java.lang.Object
com.graphhopper.util.GHUtility
A helper class to avoid cluttering the Graph interface with all the common methods. Most of the
methods are useful for unit tests or debugging only.
- Author:
- Peter Karich
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddRandomTurnCosts(Graph graph, long seed, BooleanEncodedValue accessEnc, DecimalEncodedValue turnCostEnc, int maxTurnCost, TurnCostStorage turnCostStorage) asSet(int... values) static voidbuildRandomGraph(Graph graph, Random random, int numNodes, double meanDegree, boolean allowZeroDistance, DecimalEncodedValue speedEnc, Double speed, double pBothDir, double pRandomDistanceOffset) static longcalcMillisWithTurnMillis(Weighting weighting, EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) static doublecalcWeightWithTurnWeight(Weighting weighting, EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) Calculates the weight of a given edge likeWeighting.calcEdgeWeight(com.graphhopper.util.EdgeIteratorState, boolean)and adds the transition cost (the turn weight,Weighting.calcTurnWeight(int, int, int)) associated with transitioning from/to the edge with ID prevOrNextEdgeId.static voidcheckDAVersion(String name, int expectedVersion, int version) comparePaths(Path refPath, Path path, int source, int target, long seed) static intcount(RoutingCHEdgeIterator iter) static intcount(EdgeIterator iter) Counts reachable edges.static intcount(EdgeIterator iterator, int adj) static BBoxcreateBBox(EdgeIteratorState edgeState) static JsonFeaturecreateCircle(String id, double centerLat, double centerLon, double radius) static intcreateEdgeKey(int edgeId, boolean reverse) Creates an edge key, i.e.createRandomSnaps(BBox bbox, LocationIndex locationIndex, Random rnd, int numPoints, boolean acceptTower, EdgeFilter filter) static JsonFeaturecreateRectangle(String id, double minLat, double minLon, double maxLat, double maxLon) static intgetAdjNode(Graph g, int edge, int adjNode) static doublegetDistance(int from, int to, NodeAccess nodeAccess) static EdgeIteratorStatestatic intgetEdgeFromEdgeKey(int edgeKey) getEdgeIds(EdgeIterator iter) getNeighbors(EdgeIterator iter) getProblems(Graph g) This method could throw an exception if problems like index out of bounds etcstatic SnapgetRandomSnap(LocationIndex locationIndex, Random rnd, BBox bbox, EdgeFilter filter) static CustomModelloadCustomModelFromJar(String name) static voidprintGraphForUnitTest(Graph g, DecimalEncodedValue speedEnc) static voidprintGraphForUnitTest(Graph g, DecimalEncodedValue speedEnc, BBox bBox) static doublerandomDoubleInRange(Random rnd, double min, double max) static List<CustomArea>Reads the country borders from the countries.geojson resource filestatic intreverseEdgeKey(int edgeKey) Returns the edgeKey of the opposite directionstatic voidrunConcurrently(Stream<Runnable> runnables, int threads) static EdgeIteratorStatesetSpeed(double averageSpeed, boolean fwd, boolean bwd, BooleanEncodedValue accessEnc, DecimalEncodedValue avSpeedEnc, EdgeIteratorState edge) static voidsetSpeed(double fwdSpeed, double bwdSpeed, BooleanEncodedValue accessEnc, DecimalEncodedValue speedEnc, EdgeIteratorState... edges) static voidsetSpeed(double fwdSpeed, double bwdSpeed, BooleanEncodedValue accessEnc, DecimalEncodedValue speedEnc, Collection<EdgeIteratorState> edges) static voidupdateDistancesFor(Graph g, int node, double lat, double lon)
-
Field Details
-
OSM_WARNING_LOGGER
public static final org.slf4j.Logger OSM_WARNING_LOGGER
-
-
Constructor Details
-
GHUtility
public GHUtility()
-
-
Method Details
-
getProblems
This method could throw an exception if problems like index out of bounds etc -
count
Counts reachable edges. -
count
-
asSet
-
getNeighbors
-
getNeighbors
-
getEdgeIds
-
printGraphForUnitTest
-
printGraphForUnitTest
-
buildRandomGraph
public static void buildRandomGraph(Graph graph, Random random, int numNodes, double meanDegree, boolean allowZeroDistance, DecimalEncodedValue speedEnc, Double speed, double pBothDir, double pRandomDistanceOffset) - Parameters:
speed- if null a random speed will be assigned to every edge
-
getDistance
-
addRandomTurnCosts
public static void addRandomTurnCosts(Graph graph, long seed, BooleanEncodedValue accessEnc, DecimalEncodedValue turnCostEnc, int maxTurnCost, TurnCostStorage turnCostStorage) -
createRandomSnaps
public static List<Snap> createRandomSnaps(BBox bbox, LocationIndex locationIndex, Random rnd, int numPoints, boolean acceptTower, EdgeFilter filter) -
getRandomSnap
public static Snap getRandomSnap(LocationIndex locationIndex, Random rnd, BBox bbox, EdgeFilter filter) -
randomDoubleInRange
-
getAdjNode
-
checkDAVersion
-
getEdge
- Returns:
- the edge between base and adj, or null if there is no such edge
- Throws:
IllegalArgumentException- when there are multiple edges
-
count
- Returns:
- the number of edges with the given adj node
-
createEdgeKey
public static int createEdgeKey(int edgeId, boolean reverse) Creates an edge key, i.e. an integer number that encodes an edge ID and the direction of an edge -
reverseEdgeKey
public static int reverseEdgeKey(int edgeKey) Returns the edgeKey of the opposite direction -
getEdgeFromEdgeKey
public static int getEdgeFromEdgeKey(int edgeKey) - Returns:
- edge ID for edgeKey
-
setSpeed
public static void setSpeed(double fwdSpeed, double bwdSpeed, BooleanEncodedValue accessEnc, DecimalEncodedValue speedEnc, EdgeIteratorState... edges) -
setSpeed
public static void setSpeed(double fwdSpeed, double bwdSpeed, BooleanEncodedValue accessEnc, DecimalEncodedValue speedEnc, Collection<EdgeIteratorState> edges) -
setSpeed
public static EdgeIteratorState setSpeed(double averageSpeed, boolean fwd, boolean bwd, BooleanEncodedValue accessEnc, DecimalEncodedValue avSpeedEnc, EdgeIteratorState edge) -
updateDistancesFor
-
calcWeightWithTurnWeight
public static double calcWeightWithTurnWeight(Weighting weighting, EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) Calculates the weight of a given edge likeWeighting.calcEdgeWeight(com.graphhopper.util.EdgeIteratorState, boolean)and adds the transition cost (the turn weight,Weighting.calcTurnWeight(int, int, int)) associated with transitioning from/to the edge with ID prevOrNextEdgeId.- Parameters:
prevOrNextEdgeId- if reverse is false this has to be the previous edgeId, if true it has to be the next edgeId in the direction from start to end.
-
calcMillisWithTurnMillis
public static long calcMillisWithTurnMillis(Weighting weighting, EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) -
readCountries
Reads the country borders from the countries.geojson resource file -
runConcurrently
-
createBBox
-
createCircle
public static JsonFeature createCircle(String id, double centerLat, double centerLon, double radius) -
createRectangle
public static JsonFeature createRectangle(String id, double minLat, double minLon, double maxLat, double maxLon) -
comparePaths
-
loadCustomModelFromJar
-