Coverage Report - net.sourceforge.combean.graph.alg.partition.SCCByDoubleDFSImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
SCCByDoubleDFSImpl
88%
21/24
30%
3/10
1,25
 
 1  
 /*
 2  
     This file is part of Combean.
 3  
 
 4  
     Combean is free software; you can redistribute it and/or modify
 5  
     it under the terms of the GNU General Public License as published by
 6  
     the Free Software Foundation; either version 2 of the License, or
 7  
     (at your option) any later version.
 8  
 
 9  
     Combean is distributed in the hope that it will be useful,
 10  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  
     GNU General Public License for more details.
 13  
 
 14  
     You should have received a copy of the GNU General Public License
 15  
     along with Combean; if not, write to the Free Software
 16  
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17  
 */
 18  
 /*
 19  
  * Created on 24.03.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.graph.alg.partition;
 23  
 
 24  
 import java.util.Iterator;
 25  
 
 26  
 import net.sourceforge.combean.graph.alg.traversal.DFSFinishedNodeOnStackVisitor;
 27  
 import net.sourceforge.combean.graph.alg.traversal.RecursiveDFSImpl;
 28  
 import net.sourceforge.combean.graph.containers.StackAsNodeStack;
 29  
 import net.sourceforge.combean.graph.decorators.OrderedNodesGraph;
 30  
 import net.sourceforge.combean.graph.iterators.IteratorAsNodeIterator;
 31  
 import net.sourceforge.combean.interfaces.graph.alg.traverse.DepthFirstSearch;
 32  
 import net.sourceforge.combean.interfaces.graph.prop.GlobalNodesGraphProp;
 33  
 import net.sourceforge.combean.interfaces.graph.prop.NeighborhoodGraphProp;
 34  
 
 35  
 /**
 36  
  * This class implements the search for strongly connected components
 37  
  * using two DFS traversals, one in the original and one in the transposed graph.
 38  
  * 
 39  
  * @see "Introduction to Algorithms [CLR96], p. 488ff." 
 40  
  * 
 41  
  * @author schickin
 42  
  *
 43  
  */
 44  3
 public class SCCByDoubleDFSImpl extends AbstractSCCImpl {
 45  
     
 46  
     // the graph to work with
 47  12
     private NeighborhoodGraphProp graph = null;
 48  12
     private GlobalNodesGraphProp globalNodes = null;
 49  
     
 50  
     // the DFS helper algorithm
 51  12
     private DepthFirstSearch dfs = null;
 52  
 
 53  
     /**
 54  
      * constructor
 55  
      */
 56  
     public SCCByDoubleDFSImpl() {
 57  12
         super();
 58  
         // access graph in order to satisfy the compiler
 59  12
         assert this.globalNodes != null;
 60  12
         assert this.graph != null;
 61  12
     }
 62  
 
 63  
     /* (non-Javadoc)
 64  
      * @see net.sourceforge.combean.interfaces.graph.alg.GraphAlgorithm#run()
 65  
      */
 66  
     public void run() {
 67  12
         if (this.dfs == null) {
 68  12
             this.dfs = new RecursiveDFSImpl();
 69  
         }
 70  12
         this.dfs.setGraph(getGraph());
 71  12
         StackAsNodeStack stack = new StackAsNodeStack();
 72  12
         DFSFinishedNodeOnStackVisitor finishedNodeVis =
 73  
             new DFSFinishedNodeOnStackVisitor(stack);
 74  12
         this.dfs.setDFSVisitor(finishedNodeVis);
 75  12
         this.dfs.run();
 76  12
         Iterator itStack = stack.getStack().iterator();
 77  12
         OrderedNodesGraph orderedG =
 78  
             new OrderedNodesGraph(this.globalNodes,
 79  
                     new IteratorAsNodeIterator(itStack));
 80  12
         this.dfs.setGraph(orderedG);
 81  12
         this.dfs.setVisitor(new PartitionsTraversalVisitor(this.getVisitor()));
 82  12
         this.dfs.run();
 83  12
     }
 84  
 
 85  
     /**
 86  
      * @return Returns the dfs algorithm.
 87  
      */
 88  
     public final DepthFirstSearch getDfs() {
 89  0
         return this.dfs;
 90  
     }
 91  
     
 92  
     /**
 93  
      * Set the DFS helper algorithm. If left unset RecursiveDFSImpl will be used
 94  
      * @see net.sourceforge.combean.graph.alg.traversal.RecursiveDFSImpl
 95  
      * 
 96  
      * @param dfs The dfs algorithm to set.
 97  
      */
 98  
     public final void setDfs(DepthFirstSearch dfs) {
 99  0
         this.dfs = dfs;
 100  0
     }
 101  
 }