Class GraphAStar<T>
- java.lang.Object
-
- ch.sahits.game.openpatrician.engine.sea.model.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
-
-
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 edgesNodeData<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 graphint
size()
-
-
-
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 addedisTargetNode
- 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 edgenodeIdSecond
- the second node to be second node in the edgelength
- 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 edgenodeIdSecond
- the second node to be second node in the edgelength
- 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 interfacejava.lang.Iterable<T>
- Returns:
- an Iterator.
-
size
public int size()
-
-