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 void
addRandomTurnCosts
(Graph graph, long seed, BooleanEncodedValue accessEnc, DecimalEncodedValue turnCostEnc, int maxTurnCost, TurnCostStorage turnCostStorage) asSet
(int... values) static void
buildRandomGraph
(Graph graph, Random random, int numNodes, double meanDegree, boolean allowZeroDistance, DecimalEncodedValue speedEnc, Double speed, double pBothDir, double pRandomDistanceOffset) static long
calcMillisWithTurnMillis
(Weighting weighting, EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) 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.static void
checkDAVersion
(String name, int expectedVersion, int version) comparePaths
(Path refPath, Path path, int source, int target, long seed) static int
count
(RoutingCHEdgeIterator iter) static int
count
(EdgeIterator iter) Counts reachable edges.static int
count
(EdgeIterator iterator, int adj) static BBox
createBBox
(EdgeIteratorState edgeState) static JsonFeature
createCircle
(String id, double centerLat, double centerLon, double radius) static int
createEdgeKey
(int edgeId, boolean reverse) Creates an edge key, i.e.createRandomSnaps
(BBox bbox, LocationIndex locationIndex, Random rnd, int numPoints, boolean acceptTower, EdgeFilter filter) static JsonFeature
createRectangle
(String id, double minLat, double minLon, double maxLat, double maxLon) static int
getAdjNode
(Graph g, int edge, int adjNode) static double
getDistance
(int from, int to, NodeAccess nodeAccess) static EdgeIteratorState
static int
getEdgeFromEdgeKey
(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 Snap
getRandomSnap
(LocationIndex locationIndex, Random rnd, BBox bbox, EdgeFilter filter) static CustomModel
loadCustomModelFromJar
(String name) static void
printGraphForUnitTest
(Graph g, DecimalEncodedValue speedEnc) static void
printGraphForUnitTest
(Graph g, DecimalEncodedValue speedEnc, BBox bBox) static double
randomDoubleInRange
(Random rnd, double min, double max) static List<CustomArea>
Reads the country borders from the countries.geojson resource filestatic int
reverseEdgeKey
(int edgeKey) Returns the edgeKey of the opposite directionstatic void
runConcurrently
(Stream<Runnable> runnables, int threads) static EdgeIteratorState
setSpeed
(double averageSpeed, boolean fwd, boolean bwd, BooleanEncodedValue accessEnc, DecimalEncodedValue avSpeedEnc, EdgeIteratorState edge) static void
setSpeed
(double fwdSpeed, double bwdSpeed, BooleanEncodedValue accessEnc, DecimalEncodedValue speedEnc, EdgeIteratorState... edges) static void
setSpeed
(double fwdSpeed, double bwdSpeed, BooleanEncodedValue accessEnc, DecimalEncodedValue speedEnc, Collection<EdgeIteratorState> edges) static void
updateDistancesFor
(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
-