1 #ifndef _ZOLTAN2_MatcherHelper_hpp_
2 #define _ZOLTAN2_MatcherHelper_hpp_
7 #ifdef ZOLTAN2ND_HAVE_OMP
39 template <
typename LO>
54 std::vector<LO> matchedVertexForU;
57 std::vector<LO> matchedVertexForV;
59 std::vector<LO> queue;
66 LO numE,avgDegU_,k_star_,icm_,BFSInd_,numThread_,Qst_,Qend_,numMatched;
70 void delete_matched_v();
74 LO construct_layered_graph();
76 LO recursive_path_finder(LO, LO);
77 LO dfs_path_finder(LO);
79 LO augment_matching(LO);
90 Matcher(LO *_rowPtr, LO *_cols, LO _numU, LO _numV, LO _numE);
107 for(
unsigned int i=0;i<matchedVertexForU.size(); i++)
109 if(matchedVertexForU[i]!=-1)
125 std::vector<LO> &bigraphCRSCols,
126 const std::vector<LO> &vertUMatches,
127 const std::vector<LO> &vertVMatches,
128 const std::vector<LO> &bigraphVMapU,
129 const std::vector<LO> &bigraphVMapV,
130 std::vector<LO> &VC);
142 template <
typename LO>
144 :mCRS_rowPtrs(_rowPtr),mCRS_cols(_cols),numU(_numU),numV(_numV),numE(_numE)
147 avgDegU_=numE/numU+1;
148 matchedVertexForU.resize(numU);
149 matchedVertexForV.resize(numV);
151 lookahead_=
new LO[numU];
152 unmatchedU_=
new LO[numU];
154 for(LO i=0;i<numU;i++)
156 matchedVertexForU[i]=-1;
158 lookahead_[i]=mCRS_rowPtrs[i];
162 visitedV_=
new LO[numV];
164 parent_=
new LO[numV];
166 for(LO i=0;i<numV;i++)
170 matchedVertexForV[i]=-1;
181 template <
typename LO>
184 delete [] lookahead_;
185 delete [] unmatchedU_;
189 delete [] parent_; parent_ = NULL;
207 template <
typename LO>
215 t=matchedVertexForU[u];
216 matchedVertexForV[v]=u;
217 matchedVertexForU[u]=v;
236 template <
typename LO>
237 LO Matcher<LO>::dfs_path_finder(LO u)
241 for(i=lookahead_[u];i<mCRS_rowPtrs[u+1];i++)
244 assert(ind>=0 && ind<numV);
245 if(matchedVertexForV[ind]==-1)
248 if (visitedV_[ind]==0)
266 for(i=mCRS_rowPtrs[u];i<mCRS_rowPtrs[u+1];i++)
269 assert(ind>=0 && ind<numV);
272 if (visitedV_[ind]==0)
281 res=dfs_path_finder(matchedVertexForV[ind]);
289 for(i=mCRS_rowPtrs[u+1]-1;i>=mCRS_rowPtrs[u];i--)
292 assert(ind>=0 && ind<numV);
296 if (visitedV_[ind]==0)
305 res=dfs_path_finder(matchedVertexForV[ind]);
403 template <
typename LO>
404 LO Matcher<LO>::dfs_augment()
406 LO i,flag=0,flag1=0,count=0,totc=0,index=numU,cur=0;
421 if(matchedVertexForU[i]==-1)
422 unmatchedU_[cur++]=i;
431 LO ind=dfs_path_finder(u);
435 augment_matching(ind);
439 if(flag==0 || flag1==0)
446 if(matchedVertexForU[unmatchedU_[i]]==-1)
447 unmatchedU_[cur++]=unmatchedU_[i];
497 template <
typename LO>
498 LO Matcher<LO>::SGM()
504 for(j=mCRS_rowPtrs[i];j<mCRS_rowPtrs[i+1];j++)
509 if (visitedV_[ind]==0)
517 matchedVertexForU[i]=ind;
518 matchedVertexForV[ind]=i;
532 template <
typename LO>
533 LO Matcher<LO>::match_dfs()
546 template <
typename LO>
579 template <
typename LO>
581 std::vector<LO> &bigraphCRSCols,
582 const std::vector<LO> &vertSMatches,
583 const std::vector<LO> &vertTMatches,
584 const std::vector<LO> &bigraphVMapU,
585 const std::vector<LO> &bigraphVMapV,
588 LO numS = vertSMatches.size();
589 LO numT = vertTMatches.size();
595 for(LO i=0;i<numS; i++)
597 if(vertSMatches[i]==-1)
609 for (LO uID=0;uID<numS;uID++)
611 for (LO eIdx=bigraphCRSRowPtr[uID];eIdx<bigraphCRSRowPtr[uID+1];eIdx++)
613 LO vID = bigraphCRSCols[eIdx];
615 if (vertSMatches[uID]==vID)
617 bigraphCRSCols[eIdx]=-1;
629 std::queue<LO> vqueue;
631 std::copy(X.begin(), X.end(), std::inserter( L, L.begin() ) );
635 typename std::set<LO>::const_iterator iter;
636 for(iter = X.begin(); iter != X.end(); ++iter)
638 L.insert(bigraphVMapU[*iter]);
644 while(vqueue.size()!=0)
647 LO nstarts=vqueue.size();
649 for (LO i=0; i<nstarts; i++)
651 LO start = vqueue.front();
658 for (LO eIdx=bigraphCRSRowPtr[start];eIdx<bigraphCRSRowPtr[start+1];eIdx++)
660 LO newV = bigraphCRSCols[eIdx];
666 if(L.find(bigraphVMapV[newV])==L.end())
668 L.insert(bigraphVMapV[newV]);
679 LO newU = vertTMatches[start];
682 if(L.find(bigraphVMapU[newU])==L.end())
684 L.insert(bigraphVMapU[newU]);
697 for(LO uID=0;uID<numS;uID++)
700 if(L.find(bigraphVMapU[uID])==L.end())
702 VC.push_back(bigraphVMapU[uID]);
706 for(LO vID=0;vID<numT;vID++)
709 if(L.find(bigraphVMapV[vID])!=L.end())
711 VC.push_back(bigraphVMapV[vID]);
LO match()
Computes the maximum cardinality matching.
void getVCfromMatching(const std::vector< LO > &bigraphCRSRowPtr, std::vector< LO > &bigraphCRSCols, const std::vector< LO > &vertUMatches, const std::vector< LO > &vertVMatches, const std::vector< LO > &bigraphVMapU, const std::vector< LO > &bigraphVMapV, std::vector< LO > &VC)
LO getNumberOfMatchedVertices()
An implementation of the Matcher interface that operates on Epetra matrices and Graphs.
const std::vector< LO > & getVertexUMatches()
const std::vector< LO > & getVertexVMatches()
virtual ~Matcher()
Destructor.
Matcher(LO *_rowPtr, LO *_cols, LO _numU, LO _numV, LO _numE)
Constructor.