Class GraphAStar<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>

    public class GraphAStar<T>
    extends java.lang.Object
    implements java.lang.Iterable<T>
    The graph represents an undirected graph.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2015 Created on Dec 31, 2015
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<T,​com.carrotsearch.hppc.ObjectDoubleScatterMap<NodeData<T>>> graph  
      private java.util.Map<T,​com.carrotsearch.hppc.ObjectDoubleMap<T>> heuristicMap  
      private java.util.Map<T,​NodeData<T>> nodeIdNodeData  
    • Constructor Summary

      Constructors 
      Constructor Description
      GraphAStar​(java.util.Map<T,​com.carrotsearch.hppc.ObjectDoubleMap<T>> heuristicMap)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEdge​(T nodeIdFirst, T nodeIdSecond, double length)
      Adds an edge from source node to destination node.
      void addEdgeInternal​(T nodeIdFirst, T nodeIdSecond, double length)
      Adds an edge from source node to destination node.
      void addNode​(T nodeId, boolean isTargetNode)
      Adds a new node to the graph.
      void addNodeInternal​(T nodeId)
      Adds a new node to the graph.
      boolean containsNode​(T nodeId)
      Check if the nodeid is already present in the data.
      com.carrotsearch.hppc.ObjectDoubleMap<NodeData<T>> edgesFrom​(T nodeId)
      Returns immutable view of the edges
      NodeData<T> getNodeData​(T nodeId)
      The nodedata corresponding to the current nodeId.
      java.util.Iterator<T> iterator()
      Returns an iterator that can traverse the nodes of the graph
      int size()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • graph

        private java.util.Map<T,​com.carrotsearch.hppc.ObjectDoubleScatterMap<NodeData<T>>> graph
      • heuristicMap

        private final java.util.Map<T,​com.carrotsearch.hppc.ObjectDoubleMap<T>> heuristicMap
      • nodeIdNodeData

        private java.util.Map<T,​NodeData<T>> nodeIdNodeData
    • Constructor Detail

      • GraphAStar

        public GraphAStar​(java.util.Map<T,​com.carrotsearch.hppc.ObjectDoubleMap<T>> heuristicMap)
    • Method Detail

      • addNode

        public void addNode​(T nodeId,
                            boolean isTargetNode)
        Adds a new node to the graph. Internally it creates the nodeData and populates the heuristic map concerning input node into node data.
        Parameters:
        nodeId - the node to be added
        isTargetNode - flag indicatin the the node is a target node. Only target nodes are contained in the heuristic.
      • addNodeInternal

        public void addNodeInternal​(T nodeId)
        Adds a new node to the graph. This is used internally in the initial creation where all nodes are added but only the target nodes have heuristic. Internally it creates the nodeData and populates the heuristic map concerning input node into node data.
        Parameters:
        nodeId - the node to be added
      • addEdge

        public void addEdge​(T nodeIdFirst,
                            T nodeIdSecond,
                            double length)
        Adds an edge from source node to destination node. There can only be a single edge from source to node. Adding additional edge would overwrite the value
        Parameters:
        nodeIdFirst - the first node to be in the edge
        nodeIdSecond - the second node to be second node in the edge
        length - the length of the edge.
      • addEdgeInternal

        public void addEdgeInternal​(T nodeIdFirst,
                                    T nodeIdSecond,
                                    double length)
        Adds an edge from source node to destination node. This method is used for the initial creation of the graph where only the heuristic for the target node exists. There can only be a single edge from source to node. Adding additional edge would overwrite the value
        Parameters:
        nodeIdFirst - the first node to be in the edge
        nodeIdSecond - the second node to be second node in the edge
        length - the length of the edge.
      • edgesFrom

        public com.carrotsearch.hppc.ObjectDoubleMap<NodeData<T>> edgesFrom​(T nodeId)
        Returns immutable view of the edges
        Parameters:
        nodeId - the nodeId whose outgoing edge needs to be returned
        Returns:
        An immutable view of edges leaving that node
      • getNodeData

        public NodeData<T> getNodeData​(T nodeId)
        The nodedata corresponding to the current nodeId.
        Parameters:
        nodeId - the nodeId to be returned
        Returns:
        the nodeData from the
      • containsNode

        public boolean containsNode​(T nodeId)
        Check if the nodeid is already present in the data.
        Parameters:
        nodeId - to be looked up.
        Returns:
        true if the node is contained in the graph.
      • iterator

        public java.util.Iterator<T> iterator()
        Returns an iterator that can traverse the nodes of the graph
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Returns:
        an Iterator.
      • size

        public int size()