File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
algorithm/graph_search/bellman_ford/shortest_path Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,10 @@ function BELLMAN_FORD (src, dest) {
33
44 for ( var i = 0 ; i < G . length ; i ++ ) {
55 weights [ i ] = MAX_VALUE ;
6+ tracer . _weight ( i , weights [ i ] ) ;
67 }
78 weights [ src ] = 0 ;
9+ tracer . _weight ( src , 0 ) ;
810
911 tracer . _print ( 'Initializing weights to: [' + weights + ']' ) ;
1012 tracer . _print ( '' ) ;
@@ -19,14 +21,13 @@ function BELLMAN_FORD (src, dest) {
1921 for ( var currentNodeNeighbor = 0 ; currentNodeNeighbor <= G . length ; currentNodeNeighbor ++ ) {
2022 if ( G [ currentNode ] [ currentNodeNeighbor ] ) { //proceed to relax Edges only if a particular weight != 0 (0 represents no edge)
2123 tracer . _print ( 'Exploring edge from ' + currentNode + ' to ' + currentNodeNeighbor + ', weight = ' + G [ currentNode ] [ currentNodeNeighbor ] ) ;
22- tracer . _visit ( currentNodeNeighbor , currentNode , undefined ) ;
2324
2425 if ( weights [ currentNodeNeighbor ] > ( weights [ currentNode ] + G [ currentNode ] [ currentNodeNeighbor ] ) ) {
2526 weights [ currentNodeNeighbor ] = weights [ currentNode ] + G [ currentNode ] [ currentNodeNeighbor ] ;
2627 tracer . _print ( 'weights [' + currentNodeNeighbor + '] = weights [' + currentNode + '] + ' + G [ currentNode ] [ currentNodeNeighbor ] ) ;
2728 }
28-
29- tracer . _leave ( currentNodeNeighbor , currentNode , undefined ) ;
29+ tracer . _visit ( currentNodeNeighbor , currentNode , weights [ currentNodeNeighbor ] ) ;
30+ tracer . _leave ( currentNodeNeighbor , currentNode ) ;
3031 }
3132 }
3233 }
You can’t perform that action at this time.
0 commit comments