Class QueryGraph

java.lang.Object
com.graphhopper.routing.querygraph.QueryGraph
All Implemented Interfaces:
Graph

public class QueryGraph extends Object implements Graph
A class which is used to query the underlying graph with real GPS points. It does so by introducing virtual nodes and edges. It is lightweight in order to be created every time a new query comes in, which makes the behaviour thread safe.

Calling any create method creates virtual edges between the tower nodes of the existing graph and new virtual tower nodes. Every virtual node has two adjacent nodes and is connected to each adjacent nodes via 2 virtual edges with opposite base node / adjacent node encoding. However, the edge explorer returned by Graph.createEdgeExplorer() only returns two virtual edges per virtual node (the ones with correct base node).

Author:
Peter Karich
  • Method Details

    • create

      public static QueryGraph create(BaseGraph graph, Snap snap)
    • create

      public static QueryGraph create(BaseGraph graph, Snap fromSnap, Snap toSnap)
    • create

      public static QueryGraph create(BaseGraph graph, List<Snap> snaps)
    • getQueryOverlay

      public com.graphhopper.routing.querygraph.QueryOverlay getQueryOverlay()
    • getBaseGraph

      public BaseGraph getBaseGraph()
      Specified by:
      getBaseGraph in interface Graph
      Returns:
      a graph which behaves like an unprepared graph and e.g. the normal unidirectional Dijkstra or any graph traversal algorithm can be executed.
    • isVirtualEdge

      public boolean isVirtualEdge(int edgeId)
    • isVirtualNode

      public boolean isVirtualNode(int nodeId)
    • unfavorVirtualEdges

      public void unfavorVirtualEdges(com.carrotsearch.hppc.IntArrayList edgeIds)
    • unfavorVirtualEdge

      public void unfavorVirtualEdge(int virtualEdgeId)
      Assigns the 'unfavored' flag to a virtual edge (for both directions)
    • getUnfavoredVirtualEdges

      public Set<EdgeIteratorState> getUnfavoredVirtualEdges()
      Returns all virtual edges that have been unfavored via unfavorVirtualEdge(int) or unfavorVirtualEdges(IntArrayList)
    • clearUnfavoredStatus

      public void clearUnfavoredStatus()
      Removes the 'unfavored' status of all virtual edges.
    • getNodes

      public int getNodes()
      Specified by:
      getNodes in interface Graph
      Returns:
      the number of created locations - via setNode() or edge()
    • getEdges

      public int getEdges()
      Specified by:
      getEdges in interface Graph
      Returns:
      the number of edges in this graph. Equivalent to getAllEdges().length().
    • getNodeAccess

      public NodeAccess getNodeAccess()
      Description copied from interface: Graph
      Creates an object to access node properties.
      Specified by:
      getNodeAccess in interface Graph
    • getBounds

      public BBox getBounds()
      Description copied from interface: Graph
      Returns the implicit bounds of this graph calculated from the lat,lon input of setNode
      Specified by:
      getBounds in interface Graph
    • getEdgeIteratorState

      public EdgeIteratorState getEdgeIteratorState(int origEdgeId, int adjNode)
      Description copied from interface: Graph
      Returns a wrapper over the specified edgeId.
      Specified by:
      getEdgeIteratorState in interface Graph
      adjNode - is the node that will be returned via getAdjNode(). If adjNode is Integer.MIN_VALUE then the edge will be returned in the direction of how it is stored
      Returns:
      a new EdgeIteratorState object or potentially null if adjNode does not match
    • getEdgeIteratorStateForKey

      public EdgeIteratorState getEdgeIteratorStateForKey(int edgeKey)
      Description copied from interface: Graph
      Returns the edge state for the given edge key
      Specified by:
      getEdgeIteratorStateForKey in interface Graph
      See Also:
    • createEdgeExplorer

      public EdgeExplorer createEdgeExplorer(EdgeFilter edgeFilter)
      Description copied from interface: Graph
      Returns an EdgeExplorer which makes it possible to traverse all filtered edges of a specific node. Calling this method might be expensive, so e.g. create an explorer before a for loop!
      Specified by:
      createEdgeExplorer in interface Graph
    • getAllEdges

      public AllEdgesIterator getAllEdges()
      Specified by:
      getAllEdges in interface Graph
      Returns:
      all edges in this graph, where baseNode will be the smaller node.
    • edge

      public EdgeIteratorState edge(int a, int b)
      Description copied from interface: Graph
      Creates an edge between the nodes a and b. To set distance or access use the returned edge and e.g. edgeState.setDistance
      Specified by:
      edge in interface Graph
      Parameters:
      a - the index of the starting (tower) node of the edge
      b - the index of the ending (tower) node of the edge
      Returns:
      the newly created edge
    • getTurnCostStorage

      public TurnCostStorage getTurnCostStorage()
      Specified by:
      getTurnCostStorage in interface Graph
      Returns:
      the TurnCostStorage or null if not supported
    • wrapWeighting

      public Weighting wrapWeighting(Weighting weighting)
      Description copied from interface: Graph
      Wraps the given weighting into a weighting that can be used by this graph
      Specified by:
      wrapWeighting in interface Graph
    • getOtherNode

      public int getOtherNode(int edge, int node)
      Specified by:
      getOtherNode in interface Graph
      Returns:
      the 'opposite' node of a given edge, so if there is an edge 3-2 and node =2 this returns 3
    • isAdjacentToNode

      public boolean isAdjacentToNode(int edge, int node)
      Specified by:
      isAdjacentToNode in interface Graph
      Returns:
      true if the edge with id edge is adjacent to node, false otherwise