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_;
187 if (parent_)
delete [] parent_; parent_ = NULL;
204 template <
typename LO>
212 t=matchedVertexForU[u];
213 matchedVertexForV[v]=u;
214 matchedVertexForU[u]=v;
233 template <
typename LO>
238 for(i=lookahead_[u];i<mCRS_rowPtrs[u+1];i++)
241 assert(ind>=0 && ind<numV);
242 if(matchedVertexForV[ind]==-1)
245 if (visitedV_[ind]==0)
263 for(i=mCRS_rowPtrs[u];i<mCRS_rowPtrs[u+1];i++)
266 assert(ind>=0 && ind<numV);
269 if (visitedV_[ind]==0)
278 res=dfs_path_finder(matchedVertexForV[ind]);
286 for(i=mCRS_rowPtrs[u+1]-1;i>=mCRS_rowPtrs[u];i--)
289 assert(ind>=0 && ind<numV);
293 if (visitedV_[ind]==0)
302 res=dfs_path_finder(matchedVertexForV[ind]);
400 template <
typename LO>
403 LO i,flag=0,flag1=0,count=0,totc=0,index=numU,cur=0;
418 if(matchedVertexForU[i]==-1)
419 unmatchedU_[cur++]=i;
428 LO ind=dfs_path_finder(u);
432 augment_matching(ind);
436 if(flag==0 || flag1==0)
443 if(matchedVertexForU[unmatchedU_[i]]==-1)
444 unmatchedU_[cur++]=unmatchedU_[i];
494 template <
typename LO>
501 for(j=mCRS_rowPtrs[i];j<mCRS_rowPtrs[i+1];j++)
506 if (visitedV_[ind]==0)
514 matchedVertexForU[i]=ind;
515 matchedVertexForV[ind]=i;
529 template <
typename LO>
543 template <
typename LO>
576 template <
typename LO>
578 std::vector<LO> &bigraphCRSCols,
579 const std::vector<LO> &vertSMatches,
580 const std::vector<LO> &vertTMatches,
581 const std::vector<LO> &bigraphVMapU,
582 const std::vector<LO> &bigraphVMapV,
585 LO numS = vertSMatches.size();
586 LO numT = vertTMatches.size();
592 for(LO i=0;i<numS; i++)
594 if(vertSMatches[i]==-1)
606 for (LO uID=0;uID<numS;uID++)
608 for (LO eIdx=bigraphCRSRowPtr[uID];eIdx<bigraphCRSRowPtr[uID+1];eIdx++)
610 LO vID = bigraphCRSCols[eIdx];
612 if (vertSMatches[uID]==vID)
614 bigraphCRSCols[eIdx]=-1;
626 std::queue<LO> vqueue;
628 std::copy(X.begin(), X.end(), std::inserter( L, L.begin() ) );
632 typename std::set<LO>::const_iterator iter;
633 for(iter = X.begin(); iter != X.end(); ++iter)
635 L.insert(bigraphVMapU[*iter]);
641 while(vqueue.size()!=0)
644 LO nstarts=vqueue.size();
646 for (LO i=0; i<nstarts; i++)
648 LO start = vqueue.front();
655 for (LO eIdx=bigraphCRSRowPtr[start];eIdx<bigraphCRSRowPtr[start+1];eIdx++)
657 LO newV = bigraphCRSCols[eIdx];
663 if(L.find(bigraphVMapV[newV])==L.end())
665 L.insert(bigraphVMapV[newV]);
676 LO newU = vertTMatches[start];
679 if(L.find(bigraphVMapU[newU])==L.end())
681 L.insert(bigraphVMapU[newU]);
694 for(LO uID=0;uID<numS;uID++)
697 if(L.find(bigraphVMapU[uID])==L.end())
699 VC.push_back(bigraphVMapU[uID]);
703 for(LO vID=0;vID<numT;vID++)
706 if(L.find(bigraphVMapV[vID])!=L.end())
708 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.