Class GHUtility

java.lang.Object
com.graphhopper.util.GHUtility

public class GHUtility extends Object
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 Details

    • OSM_WARNING_LOGGER

      public static final org.slf4j.Logger OSM_WARNING_LOGGER
  • Constructor Details

    • GHUtility

      public GHUtility()
  • Method Details

    • getProblems

      public static List<String> getProblems(Graph g)
      This method could throw an exception if problems like index out of bounds etc
    • count

      public static int count(EdgeIterator iter)
      Counts reachable edges.
    • count

      public static int count(RoutingCHEdgeIterator iter)
    • asSet

      public static Set<Integer> asSet(int... values)
    • getNeighbors

      public static Set<Integer> getNeighbors(RoutingCHEdgeIterator iter)
    • getNeighbors

      public static Set<Integer> getNeighbors(EdgeIterator iter)
    • getEdgeIds

      public static List<Integer> getEdgeIds(EdgeIterator iter)
    • printGraphForUnitTest

      public static void printGraphForUnitTest(Graph g, DecimalEncodedValue speedEnc)
    • printGraphForUnitTest

      public static void printGraphForUnitTest(Graph g, DecimalEncodedValue speedEnc, BBox bBox)
    • 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

      public static double getDistance(int from, int to, NodeAccess nodeAccess)
    • 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

      public static double randomDoubleInRange(Random rnd, double min, double max)
    • getAdjNode

      public static int getAdjNode(Graph g, int edge, int adjNode)
    • checkDAVersion

      public static void checkDAVersion(String name, int expectedVersion, int version)
    • getEdge

      public static EdgeIteratorState getEdge(Graph graph, int base, int adj)
      Returns:
      the edge between base and adj, or null if there is no such edge
      Throws:
      IllegalArgumentException - when there are multiple edges
    • count

      public static int count(EdgeIterator iterator, int adj)
      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

      public static void updateDistancesFor(Graph g, int node, double lat, double lon)
    • calcWeightWithTurnWeight

      public static double calcWeightWithTurnWeight(Weighting weighting, EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId)
      Calculates the weight of a given edge like Weighting.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)
      See Also:
    • readCountries

      public static List<CustomArea> readCountries()
      Reads the country borders from the countries.geojson resource file
    • runConcurrently

      public static void runConcurrently(Stream<Runnable> runnables, int threads)
    • createBBox

      public static BBox createBBox(EdgeIteratorState edgeState)
    • 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

      public static List<String> comparePaths(Path refPath, Path path, int source, int target, long seed)
    • loadCustomModelFromJar

      public static CustomModel loadCustomModelFromJar(String name)