net.sourceforge.combean.graph.alg.traversal
Class AbstractGraphTraversalAlg

Package class diagram package AbstractGraphTraversalAlg
java.lang.Object
  extended by net.sourceforge.combean.graph.alg.AbstractGraphAlg
      extended by net.sourceforge.combean.graph.alg.traversal.AbstractGraphTraversalAlg
All Implemented Interfaces:
GraphAlgorithm, GraphTraversalAlg
Direct Known Subclasses:
BreadthFirstSearchImpl, RecursiveDFSImpl

public abstract class AbstractGraphTraversalAlg
extends AbstractGraphAlg
implements GraphTraversalAlg

Abstract base class for DFS- and BFS-traversal. Holds common datastructures.


Constructor Summary
AbstractGraphTraversalAlg()
          constructor
 
Method Summary
protected  NeighborhoodGraphProp getNeighborhood()
           
protected  EdgeIterator getNeighborIterator(Node v)
           
protected  NodeSet getVisitedNodes()
           
 TraversalVisitor getVisitor()
           
protected  void init()
          Helper method for setting up the internal data structures.
 void run()
          Execute the algorithm.
protected abstract  void runTraversalWithSingleStartNode(Node v)
          Template method.
 void setLocalStartNode(Node startNode)
          If a start node is set, the traversal will start from there and only thos nodes which are reachable from the start node will be explored.
 void setUseOnlyOutgoingEdges(boolean useOnlyOutgoingEdges)
          If this flag is set to true, the underlying graph must have the OutgoingEdgeNeighborhood-property and only outgoing edges will be considered when the neigbors of a node are visited.
 void setVisitedNodes(NodeSet visitedNodes)
          Set the NodeSet where the nodes are stored which have already been visited during the traversal of the graph.
 void setVisitor(TraversalVisitor visitor)
          Set the visitor object which will be called during the traversal.
 
Methods inherited from class net.sourceforge.combean.graph.alg.AbstractGraphAlg
getGraph, setGraph
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.combean.interfaces.graph.alg.GraphAlgorithm
getGraph, setGraph
 

Constructor Detail

AbstractGraphTraversalAlg

public AbstractGraphTraversalAlg()
constructor

Method Detail

setVisitor

public void setVisitor(TraversalVisitor visitor)
Description copied from interface: GraphTraversalAlg
Set the visitor object which will be called during the traversal.

Specified by:
setVisitor in interface GraphTraversalAlg
See Also:
GraphTraversalAlg.setVisitor(net.sourceforge.combean.interfaces.graph.alg.traverse.TraversalVisitor)

getVisitor

public final TraversalVisitor getVisitor()
Specified by:
getVisitor in interface GraphTraversalAlg
Returns:
the visitor
See Also:
GraphTraversalAlg.getVisitor()

setLocalStartNode

public final void setLocalStartNode(Node startNode)
Description copied from interface: GraphTraversalAlg
If a start node is set, the traversal will start from there and only thos nodes which are reachable from the start node will be explored. If the start node is set to null (the default), all components of the graph will be explored.

Specified by:
setLocalStartNode in interface GraphTraversalAlg
See Also:
GraphTraversalAlg.setLocalStartNode(net.sourceforge.combean.interfaces.graph.Node)

setVisitedNodes

public final void setVisitedNodes(NodeSet visitedNodes)
Set the NodeSet where the nodes are stored which have already been visited during the traversal of the graph. The NodeSetAdvisor will be consulted if left unset.

Parameters:
visitedNodes - The visitedNodes to set.

getVisitedNodes

protected final NodeSet getVisitedNodes()
Returns:
Returns the visitedNodes.

setUseOnlyOutgoingEdges

public void setUseOnlyOutgoingEdges(boolean useOnlyOutgoingEdges)
Description copied from interface: GraphTraversalAlg
If this flag is set to true, the underlying graph must have the OutgoingEdgeNeighborhood-property and only outgoing edges will be considered when the neigbors of a node are visited. By default this flag will be set to false and all incident edges will be visited for a given node.

Specified by:
setUseOnlyOutgoingEdges in interface GraphTraversalAlg

getNeighborhood

protected final NeighborhoodGraphProp getNeighborhood()
Returns:
Returns the graph.

init

protected void init()
Helper method for setting up the internal data structures.


runTraversalWithSingleStartNode

protected abstract void runTraversalWithSingleStartNode(Node v)
Template method. Override with the implementation of a traversal of all nodes reachable from v

Parameters:
v - the node where the traversal shall start

getNeighborIterator

protected final EdgeIterator getNeighborIterator(Node v)

run

public void run()
Description copied from interface: GraphAlgorithm
Execute the algorithm.

Specified by:
run in interface GraphAlgorithm
See Also:
GraphAlgorithm.run()