edu.upc.dama.dex.algorithms
Class TraversalBFS

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

public class TraversalBFS
extends Traversal

This class can be used to traverse the graph using the breadth-first search algorithm (BFS).

Concretely, it consists in traversing the graph by starting at a source node and exploring its neighbors and, for each neighbor, the algorithm explores its neighbors, and so on.

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 TraversalBFS.next() is called. The execution stops when the last node is reached or when the user decides not to continue calling the TraversalBFS.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
TraversalBFS(Graph graph, long source)
          Creates a new instance of Traversal.
 
Method Summary
 void close()
          Closes the instance.
 long getCurrentDepth()
          Returns the depth of the current node, that is, the node returned in the last call to the method TraversalBFS.next() while traversing the graph.
 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

TraversalBFS

public TraversalBFS(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

getCurrentDepth

public long getCurrentDepth()
Returns the depth of the current node, that is, the node returned in the last call to the method TraversalBFS.next() while traversing the graph.

Returns:
The depth of the current node.

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.