void transitivePredecessorComponents(const ComponentGraph& compgraph, Component from, Set& preds) { // we need a hash map, as component graph is no graph with vecS-storage // typedef boost::unordered_map<Component, boost::default_color_type> CompColorHashMap; typedef boost::associative_property_map<CompColorHashMap> CompColorMap; CompColorHashMap ccWhiteHashMap; // fill white hash map ComponentIterator cit, cit_end; for(boost::tie(cit, cit_end) = compgraph.getComponents(); cit != cit_end; ++cit) { //boost::put(ccWhiteHashMap, *cit, boost::white_color); ccWhiteHashMap[*cit] = boost::white_color; } CompColorHashMap ccHashMap(ccWhiteHashMap); // // do DFS // DFSVisitor dfs_vis(compgraph, preds); //LOG("doing dfs visit for root " << *itr); boost::depth_first_visit( compgraph.getInternalGraph(), from, dfs_vis, CompColorMap(ccHashMap)); DBGLOG(DBG,"predecessors of " << from << " are " << printrange(preds)); }
/* * The mex function runs a BFS or DFS with a visitor. */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mwIndex mrows, ncols; mwIndex n,nz; /* sparse matrix */ mwIndex *ia, *ja; /* start */ mwIndex u; const mxArray *vis; int call; if (nrhs != 4) { mexErrMsgTxt("2 inputs required."); } /* The first input must be a sparse matrix. */ mrows = mxGetM(prhs[0]); ncols = mxGetN(prhs[0]); if (mrows != ncols || !mxIsSparse(prhs[0])) { mexErrMsgTxt("Input must be a square sparse matrix."); } n = mrows; /* The second input must be a scalar. */ if (mxGetNumberOfElements(prhs[1]) > 1 || !mxIsDouble(prhs[1])) { mexErrMsgTxt("Invalid scalar."); } /* The third input must be a structure. */ if (!mxIsStruct(prhs[2])) { mexErrMsgTxt("Invalid structure."); } /* The fourth input must be a scalar. */ if (mxGetNumberOfElements(prhs[3]) > 1 || !mxIsDouble(prhs[3])) { mexErrMsgTxt("Invalid scalar."); } /* Get the sparse matrix */ /* recall that we've transposed the matrix */ ja = mxGetIr(prhs[0]); ia = mxGetJc(prhs[0]); nz = ia[n]; /* Get the scalar */ u = (mwIndex)mxGetScalar(prhs[1]); u = u-1; if (u < 0 || u >= n) { mexErrMsgIdAndTxt("matlab_bgl:invalidParameter", "start vertex (%i) not a valid vertex.", u+1); } vis = prhs[2]; call = (int)mxGetScalar(prhs[3]); if (call == 101) { bfs_vis(n, ja, ia, u, vis); } else if (call == 201) { /* call without the "full" option */ dfs_vis(n, ja, ia, u, 0, vis); } else if (call == 202) { /* call with the "full" option */ dfs_vis(n, ja, ia, u, 1, vis); } else { mexErrMsgTxt("Invalid call."); } #ifdef _DEBUG mexPrintf("done!\n"); #endif #ifdef _DEBUG mexPrintf("return\n"); #endif }