unm.cs351.f11.tdrl.p1
Interface SearchState<T>


public interface SearchState<T>

Representation for a point in a search, such as a breadth-first or depth- first search. This is used to record where each node of a graph is encountered in a general search, what the predecessor of that node is (with respect to the search), and how many edges that node is from the start node of the search (i.e., how deep it is). This information can be used to, say, reconstruct a path (by tracing the predecessor links) or to terminate a search at a particular search depth (by examining the depth field).

Note that the predecessor links will form a tree whose root is the start of the search, and whose arcs all point "upward" (toward the root). In this way, you can start at a leaf and traverse upward to the root by following predecessor arcs. However, this also means that, because of Java's garbage collection mechanisms, the entire tree can be maintained in memory if all of the leaves are pointed to. If you only maintain a pointer to the root, however, there will be no way to access the leaves (or any point in the tree below the root), so all of that stuff may be garbage collected.

Concrete instances of this interface SHOULD be immutable. Instances of this interface MUST NOT make a copy of the node data (e.g., by invoking copy-constructors or via the Object.clone() method). They must only keep a reference to the nodes.

Version:
1.0
Author:
terran

Method Summary
 int getDepth()
          Get the depth of this node within the search.
 T getNode()
          Get the graph node associated with this search state.
 SearchState<T> getPredecessor()
          Gets a reference to the predecessor search state to this state.
 

Method Detail

getNode

T getNode()
Get the graph node associated with this search state. Must be non-null.

Returns:
Graph node.

getPredecessor

SearchState<T> getPredecessor()
Gets a reference to the predecessor search state to this state. If the current search state is s, then the predecessor of s is the search state p from which s was generated. That is, during the search, when examining node p.getNode() in the graph, we generate all neighbors of p.getNode() (via Graph.neighborSet(Object)); each of those neighbors becomes the node of a new SearchState object, s.getNode(). All of those successor search states, then, have p as their predecessors.

Note that the start node of a search is the root of the predecessor tree, and has no predecessor itself. This method uses null to indicate this special case.

Returns:
Predecessor SearchState of the current state, or null if the current state is the start of the search.

getDepth

int getDepth()
Get the depth of this node within the search. The depth is defined to be:
 root.depth=0
 x.depth=(x.getPredecessor().depth())+1
 
That is, the search starts at depth 0; every time a new search state is generated, its depth is incremented by one from the node that generated it. So the root is at depth 0, all neighbors of the root are at depth 1, their neighbors are at depth 2, etc. Thus, the depth is also the number of edge hops that the current node is from the start node of the search.

Note that depth MUST be non-negative.

Returns:
Depth of the current search state.