home *** CD-ROM | disk | FTP | other *** search
- From markus@mpii01002.cs.uni-sb.de Mon Oct 28 11:08:16 1991
- From: markus@mpii01002.cs.uni-sb.de
- To: stefan
- Subject: Gen. Matching
-
- ' Morgen.
-
- Ich schicke Dir mal die Heuristik, die (fast) alle Pfade der
- Laenge <= 3 findet. Sie ist kaum langsamer als die "Greedy"-Methode,
- aber wesentlich besser. Die Laufzeit des nachfolgenden Algorithmus
- reduziert sich auf ca. 1/5 (je nach Dichte).
-
- Markus
-
-
-
-
-
- /*
- * finds almost all augmenting paths of length <=3 with two passes over
- * the adjacency lists
- * ("almost": discovery of a blossom {v,w,x,v} leads to a skip of the
- * edge (x,v), even if the base v stays unmatched - it's not worth while
- * to fix this problem)
- * if all adjacent nodes w of v are matched, try to find an other
- * partner for mate[x], and match v and w on success
- */
- int heuristic( graph &G, node_array(node)& mate )
- {
- node u, v, w, x ;
- int card = 0 ;
- bool found ;
- node_array(bool) all_matched( G, false ) ;
-
- G.reset() ;
- forall_nodes( v, G ) {
- if( mate[v]==nil ) { // first pass
- while( (found=G.next_adj_node( w, v )) && (mate[w]!=nil) ) ;
- if( found ) {
- mate[v] = w ; mate[w] = v ;
- card++ ;
- }
- else {
- all_matched[v] = true ;
- G.init_adj_iterator( v ) ; // second pass
- while( G.next_adj_node( w, v ) ) {
- if( ! all_matched[ ( x = mate[w] ) ] ) {
- while( (found=G.next_adj_node( u, x )) && ( (u==v) || (mate[u]!=nil) ) ) ;
- if( found ) {
- mate[u] = x ; mate[x] = u ;
- mate[v] = w ; mate[w] = v ;
- card++ ;
- break ;
- }
- else
- all_matched[x] = true ;
- }
- }
- }
- }
- } ;
- G.reset() ;
-
- return( card ) ;
- }
-
-