org.javanetworkanalyzer.alg
Class BFS<V extends VBFS,E extends EdgeSPT>

java.lang.Object
  extended by org.javanetworkanalyzer.alg.GraphSearchAlgorithm<V,E>
      extended by org.javanetworkanalyzer.alg.BFS<V,E>
Type Parameters:
V - The data structure to hold node information during the execution of BFS.
All Implemented Interfaces:
TraversalAlg<V,E>
Direct Known Subclasses:
BFSForCentrality

public class BFS<V extends VBFS,E extends EdgeSPT>
extends GraphSearchAlgorithm<V,E>

Root Breadth First Search (BFS) class.

The calculate(V) method can be overridden in subclasses in order to do graph analysis (e.g., calculating betweenness centrality).

Author:
Adam Gouge

Field Summary
 
Fields inherited from class org.javanetworkanalyzer.alg.GraphSearchAlgorithm
currentStartNode, graph
 
Constructor Summary
BFS(org.jgrapht.Graph<V,E> graph)
          Constructor.
 
Method Summary
 void calculate(V startNode)
          Does a breadth first search from the given start node to all other nodes.
protected  V dequeueStep(LinkedList<V> queue)
          Dequeues a node from the given queue.
protected  void enqueueAndUpdateDistance(V current, V neighbor, LinkedList<V> queue)
          Enqueue neighbor and set neighbor's distance to be one more than current's distance.
protected  void firstTimeFoundStep(V current, V neighbor)
          Work to be done after enqueueAndUpdateDistance(V, V, java.util.LinkedList).
protected  void init(V startNode)
          Performs any initializations to be done at the start of the TraversalAlg.calculate(V) method.
protected  void shortestPathStep(V current, V neighbor, E e)
          Work to be done if this is a shortest path from the start node to neighbor via current.
 
Methods inherited from class org.javanetworkanalyzer.alg.GraphSearchAlgorithm
outdegree, outgoingEdgesOf, outgoingEdgesOf, reconstructTraversalGraph, successorListOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BFS

public BFS(org.jgrapht.Graph<V,E> graph)
Constructor.

Parameters:
graph - The graph.
Method Detail

calculate

public void calculate(V startNode)
Does a breadth first search from the given start node to all other nodes.

Parameters:
startNode - Start node

init

protected void init(V startNode)
Description copied from class: GraphSearchAlgorithm
Performs any initializations to be done at the start of the TraversalAlg.calculate(V) method.

Overrides:
init in class GraphSearchAlgorithm<V extends VBFS,E extends EdgeSPT>
Parameters:
startNode - Start node

dequeueStep

protected V dequeueStep(LinkedList<V> queue)
Dequeues a node from the given queue.

Parameters:
queue - The queue.
Returns:
The newly dequeued node.

enqueueAndUpdateDistance

protected void enqueueAndUpdateDistance(V current,
                                        V neighbor,
                                        LinkedList<V> queue)
Enqueue neighbor and set neighbor's distance to be one more than current's distance.

Parameters:
current - Current node
neighbor - Neighbor node
queue - The queue

firstTimeFoundStep

protected void firstTimeFoundStep(V current,
                                  V neighbor)
Work to be done after enqueueAndUpdateDistance(V, V, java.util.LinkedList).

Parameters:
current - Current node
neighbor - Neighbor node

shortestPathStep

protected void shortestPathStep(V current,
                                V neighbor,
                                E e)
Work to be done if this is a shortest path from the start node to neighbor via current.

Parameters:
current - Current node
neighbor - Neighbor node
e - Edge (current, neighbor)


Copyright © 2014. All Rights Reserved.