@@ -64,7 +64,10 @@ class TopoGroups {
6464 }
6565}
6666
67- function resolve ( mixedGraph , startVertices , tech , backsort ) {
67+ function resolve ( mixedGraph , startVertices , tech , reverse ) {
68+ const _positions = startVertices . reduce ( ( res , e , pos ) => { res [ e . id ] = pos + 1 ; return res ; } , { } ) ;
69+ const backsort = ( a , b ) => _positions [ a . id ] - _positions [ b . id ] ;
70+
6871 const orderedSuccessors = [ ] ; // L ← Empty list that will contain the sorted nodes
6972 const _orderedVisits = { } ; // Hash with visiting flags: temporary - false, permanently - true
7073 const unorderedSuccessors = new VertexSet ( ) ; // The rest nodes
@@ -74,7 +77,7 @@ function resolve(mixedGraph, startVertices, tech, backsort) {
7477 // ... while there are unmarked nodes do
7578 startVertices . forEach ( v => visit ( v , false ) ) ;
7679
77- const _orderedSuccessors = Array . from ( new VertexSet ( orderedSuccessors . reverse ( ) ) ) ;
80+ const _orderedSuccessors = reverse ? [ ] : Array . from ( new VertexSet ( orderedSuccessors . reverse ( ) ) ) ;
7881 const _unorderedSuccessors = Array . from ( unorderedSuccessors ) . sort ( backsort ) ;
7982
8083 // console.log({topogroups, ordered: Array.from(_orderedSuccessors).map(v => v.id), unordered: Array.from(_unorderedSuccessors).map(v => v.id)});
@@ -115,7 +118,7 @@ function resolve(mixedGraph, startVertices, tech, backsort) {
115118 topo . lookupCreate ( fromVertex . id ) ;
116119
117120 // ... for each node m with an edge from n to m do
118- const orderedDirectSuccessors = mixedGraph . directSuccessors ( fromVertex , { ordered : true , tech } ) ;
121+ const orderedDirectSuccessors = reverse ? [ ] : mixedGraph . directSuccessors ( fromVertex , { ordered : true , tech } ) ;
119122
120123 for ( let successor of orderedDirectSuccessors ) {
121124 if ( successor . id === fromVertex . id ) { // TODO: Filter loops earlier
@@ -146,7 +149,7 @@ function resolve(mixedGraph, startVertices, tech, backsort) {
146149 weak || orderedSuccessors . unshift ( fromVertex ) ;
147150 weak && unorderedSuccessors . add ( fromVertex ) ;
148151
149- const unorderedDirectSuccessors = mixedGraph . directSuccessors ( fromVertex , { ordered : false , tech } ) ;
152+ const unorderedDirectSuccessors = mixedGraph . directSuccessors ( fromVertex , { ordered : false , tech, reversed : reverse } ) ;
150153
151154 for ( let successor of unorderedDirectSuccessors ) {
152155 // console.log('unordered', successor.id);
0 commit comments