edu.upc.dama.dex.algorithms
Class TraversalDFS

java.lang.Object
  extended by edu.upc.dama.dex.algorithms.Traversal
      extended by edu.upc.dama.dex.algorithms.TraversalDFS
All Implemented Interfaces:
Algorithm, java.util.Iterator

public class TraversalDFS
extends Traversal

This class can be used to traverse the graph using the depth-first search algorithm (DFS). searching a tree, tree structure, or graph. One starts at the root (selecting some node as the root in the graph case) and explores as far as possible along each branch before backtracking.

Concretely, it consists in traversing the graph by starting at a source node and exploring as far (depth) as possible along each branch before backtracking.

It is possible to set some restrictions after constructing a new instance of this class and before running it in order to limit the results. Those restrictions are:

Navigation

There are three kinds of edge navigation:

Once the instance has been created and the parameters has been set, it is possible to start running the graph traversal. In fact, this class is an iterator for traversing the graph in order to provide the user the next node identifier each time the method TraversalDFS.next() is called. The execution stops when the last node is reached or when the user decides not to continue calling the TraversalDFS.next() method.

Please, see edu.upc.dama.dex.algorithms for further information related to how to use this class.

NOTE: It is required to indicate the set of edge types and the set of node types before running this algorithm.

Author:
Sparsity Technologies

Field Summary
 
Fields inherited from interface edu.upc.dama.dex.algorithms.Algorithm
NAVIGATION_BACKWARD, NAVIGATION_FORWARD, NAVIGATION_UNDIRECTED
 
Constructor Summary
TraversalDFS(Graph graph, long source)
          Creates a new instance of Traversal.
 
Method Summary
 void close()
          Closes the instance.
 boolean hasNext()
          Returns whether there are more nodes to traverse in the graph.
 java.lang.Long next()
          Returns the next node and advances the iterator.
 
Methods inherited from class edu.upc.dama.dex.algorithms.Traversal
addAllEdges, addAllNodes, addEdge, addNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Iterator
remove
 

Constructor Detail

TraversalDFS

public TraversalDFS(Graph graph,
                    long source)
Creates a new instance of Traversal. After creating this instance is required to indicate the set of edge types and the set of node types which will be navigated through while traversing the graph.

Parameters:
graph - Graph on which the traversal will be run.
source - The node identifier which identifies the source node at which the algorithm execution will start.
Method Detail

close

public void close()
Description copied from class: Traversal
Closes the instance.

Once executed, the instance becomes invalid.

Specified by:
close in class Traversal

hasNext

public boolean hasNext()
Returns whether there are more nodes to traverse in the graph.

Returns:
Whether there are more nodes to traverse in the graph.

next

public java.lang.Long next()
Returns the next node and advances the iterator.

Returns:
The node identifier of the next node in the iteration.