DGraphIterativeDFP.cpp

Go to the documentation of this file.
00001 
00016 #include "DGraphIterativeDFP.hpp"
00017 #include <Utils/Util.hpp>
00018 
00019 #include <iostream>
00020 
00021 namespace OA {
00022   namespace DataFlow {
00023 
00024 static bool debug = false;
00025 
00026 //*********************************************************************
00027 // class DGraphIterativeDFP
00028 //*********************************************************************
00029 
00030 DGraphIterativeDFP::DGraphIterativeDFP()
00031 { 
00032     OA_DEBUG_CTRL_MACRO("DEBUG_DGraphIterativeDFP:ALL", debug);
00033     numIter = 0;
00034 }
00035 
00036 
00037 DGraphIterativeDFP::~DGraphIterativeDFP()
00038 {
00039 }
00040 
00041 
00042 //-----------------------------------------------------------------------
00043 // general default solver 
00044 //-----------------------------------------------------------------------
00045 void DGraphIterativeDFP::solve(OA_ptr<DGraph::DGraphInterface> dg, 
00046                                DGraph::DGraphEdgeDirection alongFlow) 
00047 {
00048 
00049   //---------------------------------------------------------------
00050   // initialize dataflow information at each of the nodes and edges
00051   //---------------------------------------------------------------
00052   initialize(dg);
00053 
00054 
00055   //---------------------------------------------------------------
00056   // Kildall style iterative solver: iterate until dataflow 
00057   // information at each node and edge stabilizes
00058   //---------------------------------------------------------------
00059   unsigned int changed;
00060 
00065   OA_ptr<DGraph::NodeInterface> node;
00066 
00067   // get iterator for desired direction
00075   OA_ptr<DGraph::NodesIteratorInterface> nodeIterPtr
00076      = dg->getReversePostDFSIterator(alongFlow);  
00077 
00078   // loop until there are no changes
00079   int iterCnt = 0;
00080   do {
00081     changed = 0;
00082     iterCnt++;
00083     if (debug) {
00084         std::cout << "DGraphIterativeDFP (in loop), iterCnt = " << iterCnt << std::endl;
00085     }
00086     for (; nodeIterPtr->isValid(); ++(*nodeIterPtr)) {
00087       node = nodeIterPtr->current();
00088       if (debug) {
00089         std::cout << "node: Id = " << node->getId();
00090         std::cout << ", num_outgoing = " << node->num_outgoing();
00091         std::cout << ", OA_ptr::dump = ";
00092         node.dump(std::cout);
00093         std::cout << std::endl;
00094       }
00095 
00096       //--------------------------------------------------
00097       // compute dataflow information at node based on
00098       // what is coming into the node along the dataflow
00099       // direction
00100       //--------------------------------------------------
00101       changed |= atDGraphNode(node, alongFlow);
00102 
00103       //--------------------------------------------------
00104       // compute dataflow information going out of the node
00105       // along dataflow direction
00106       //--------------------------------------------------
00107 
00112       OA_ptr<DGraph::EdgesIteratorInterface> edgeIterPtr;
00113       if (alongFlow==DGraph::DEdgeOrg) {  // follows original orientation of edges
00114 
00120         OA_ptr<DGraph::EdgesIteratorInterface> it = 
00121           node->getOutgoingEdgesIterator();  
00122         edgeIterPtr = it;
00123       } else {
00124         
00125        
00131         OA_ptr<DGraph::EdgesIteratorInterface> it =
00132           node->getIncomingEdgesIterator();  
00133         edgeIterPtr = it;
00134       }
00135       for (; edgeIterPtr->isValid(); ++(*edgeIterPtr)) {
00136         changed |= atDGraphEdge(edgeIterPtr->current(), alongFlow);
00137       }
00138 
00139     } // end for all nodes
00140 
00141     nodeIterPtr->reset();
00142 
00143   } while (changed);
00144 
00145 
00146   //---------------------------------------------------------------
00147   // finalize dataflow information at each of the nodes and edges
00148   //---------------------------------------------------------------
00149   for (; nodeIterPtr->isValid(); ++(*nodeIterPtr)) {
00150     node = nodeIterPtr->current();
00151     finalizeNode(node);
00152 
00157     OA::OA_ptr<DGraph::EdgesIteratorInterface> edgeIterPtr;
00158     if (alongFlow==DGraph::DEdgeOrg) {  // follows original orientation of edges
00159 
00165         OA::OA_ptr<DGraph::EdgesIteratorInterface> it =
00166             node->getOutgoingEdgesIterator();  
00167       edgeIterPtr = it;
00168     } else {
00169 
00175       OA_ptr<DGraph::EdgesIteratorInterface> it =
00176           node->getIncomingEdgesIterator();
00177       edgeIterPtr = it;
00178     }
00179     for (; edgeIterPtr->isValid(); ++(*edgeIterPtr)) {
00180       finalizeEdge(edgeIterPtr->current());
00181     }
00182 
00183   }
00184 
00185   numIter = iterCnt; // set value for retrieval
00186   if (debug) { 
00187       std::cout << "DGraphIterativeDFP: iterCnt = " << iterCnt << std::endl;
00188   }
00189   return;
00190 
00191 }
00192 
00193 
00194 //-----------------------------------------------------------------------
00195 // solver callbacks
00196 //-----------------------------------------------------------------------
00205 bool DGraphIterativeDFP::atDGraphNode
00206      (OA_ptr<DGraph::NodeInterface>, DGraph::DGraphEdgeDirection)
00207 {
00208     
00209     return false;
00210 }
00211 
00212 
00213 
00222 bool DGraphIterativeDFP::atDGraphEdge
00223      (OA_ptr<DGraph::EdgeInterface>, DGraph::DGraphEdgeDirection)
00224 {
00225     return false;
00226 }
00227 
00228 
00229 
00230 //-----------------------------------------------------------------------
00231 // finalization callbacks
00232 //-----------------------------------------------------------------------
00233 
00234 
00243  void DGraphIterativeDFP::finalizeEdge(OA_ptr<DGraph::EdgeInterface>)
00244 {
00245 }
00246 
00247 
00256  void DGraphIterativeDFP::finalizeNode(OA_ptr<DGraph::NodeInterface>)
00257 {
00258 }
00259 
00260   } // end of DataFlow namespace
00261 }  // end of OA namespace
00262 

Generated on Sat Oct 31 05:21:21 2009 for OpenAnalysis by  doxygen 1.6.1