@@ -7,6 +7,7 @@ import checkDelta3 from './checkDelta3';
7
7
import statistics from './statistics' ;
8
8
import endpoints from './endpoints' ;
9
9
import neighbours from './neighbours' ;
10
+ import blossomLeaves from './blossomLeaves' ;
10
11
11
12
// Adapted from http://jorisvr.nl/maximummatching.html
12
13
// All credit for the implementation goes to Joris van Rantwijk [http://jorisvr.nl].
@@ -193,23 +194,6 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
193
194
return dualvar [ i ] + dualvar [ j ] - 2 * wt ;
194
195
} ;
195
196
196
- // Generate the leaf vertices of a blossom.
197
- const blossomLeaves = function ( b , fn ) {
198
- if ( b < nvertex ) {
199
- if ( fn ( b ) ) return true ;
200
- } else {
201
- let i ;
202
- let t ;
203
- const length_ = blossomchilds [ b ] . length ;
204
- for ( i = 0 ; i < length_ ; ++ i ) {
205
- t = blossomchilds [ b ] [ i ] ;
206
- if ( t < nvertex ) {
207
- if ( fn ( t ) ) return true ;
208
- } else if ( blossomLeaves ( t , fn ) ) return true ;
209
- }
210
- }
211
- } ;
212
-
213
197
// Assign label t to the top-level blossom containing vertex w
214
198
// and record the fact that w was reached through the edge with
215
199
// remote endpoint p.
@@ -225,7 +209,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
225
209
bestedge [ b ] = - 1 ;
226
210
if ( t === 1 ) {
227
211
// B became an S-vertex/blossom; add it(s vertices) to the queue.
228
- blossomLeaves ( b , function ( v ) {
212
+ blossomLeaves ( nvertex , blossomchilds , b , function ( v ) {
229
213
queue . push ( v ) ;
230
214
} ) ;
231
215
console . debug ( 'DEBUG: PUSH ' + queue ) ;
@@ -379,7 +363,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
379
363
// Set dual variable to zero.
380
364
dualvar [ b ] = 0 ;
381
365
// Relabel vertices.
382
- blossomLeaves ( b , function ( v ) {
366
+ blossomLeaves ( nvertex , blossomchilds , b , function ( v ) {
383
367
if ( label [ inblossom [ v ] ] === 2 ) {
384
368
// This T-vertex now turns into an S-vertex because it becomes
385
369
// part of an S-blossom; add it to the queue.
@@ -403,7 +387,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
403
387
// This subblossom does not have a list of least-slack edges;
404
388
// get the information from the vertices.
405
389
nblists = [ ] ;
406
- blossomLeaves ( bv , function ( v ) {
390
+ blossomLeaves ( nvertex , blossomchilds , bv , function ( v ) {
407
391
j = neighbend [ v ] . length ;
408
392
temporary_ = new Array ( j ) ;
409
393
while ( j -- ) {
@@ -499,7 +483,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
499
483
// Recursively expand this sub-blossom.
500
484
expandBlossom ( s , endstage ) ;
501
485
} else {
502
- blossomLeaves ( s , function ( v ) {
486
+ blossomLeaves ( nvertex , blossomchilds , s , function ( v ) {
503
487
inblossom [ v ] = s ;
504
488
} ) ;
505
489
}
@@ -569,7 +553,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
569
553
continue ;
570
554
}
571
555
572
- blossomLeaves ( bv , function ( v ) {
556
+ blossomLeaves ( nvertex , blossomchilds , bv , function ( v ) {
573
557
if ( label [ v ] !== 0 ) {
574
558
// If the sub-blossom contains a reachable vertex, assign
575
559
// label T to the sub-blossom.
@@ -875,7 +859,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
875
859
nvertex,
876
860
edges,
877
861
blossomparent,
878
- blossomLeaves ,
862
+ blossomchilds ,
879
863
neighbend,
880
864
label,
881
865
endpoint,
0 commit comments