File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,20 @@ class BMSSP {
44 this . graph = [ ] ;
55 // Set to store unique node IDs
66 this . nodeIDs = new Set ( ) ;
7+ // Array to store shortest paths
8+ this . shortestPaths = [ ] ;
79
810 for ( let edge of inputGraph ) {
911 // Create a deep copy of each edge array
1012 this . graph . push ( [ ...edge ] ) ;
1113 // Add node IDs to the set
1214 this . nodeIDs . add ( edge [ 0 ] ) ;
1315 this . nodeIDs . add ( edge [ 1 ] ) ;
16+
17+ // Initialize shortest paths with Infinity on each nodeID
18+ for ( let nodeId of this . nodeIDs ) {
19+ this . shortestPaths . push ( [ nodeId , Infinity ] ) ;
20+ }
1421 }
1522 }
1623}
Original file line number Diff line number Diff line change @@ -37,3 +37,14 @@ describe("BMSSP nodeIDs", () => {
3737 expect ( myBMSSP . nodeIDs ) . toEqual ( uniqueNodeIDs ) ;
3838 } ) ;
3939} ) ;
40+
41+ describe ( "BMSSP shortestPaths" , ( ) => {
42+ test ( "initializes shortest paths with Infinity" , ( ) => {
43+ const myBMSSP = new BMSSP ( roadNetCA ) ;
44+ const expectedShortestPaths = [ ] ;
45+ myBMSSP . nodeIDs . forEach ( ( nodeId ) => {
46+ expectedShortestPaths . push ( [ nodeId , Infinity ] ) ;
47+ } ) ;
48+ expect ( myBMSSP . shortestPaths ) . toEqual ( expectedShortestPaths ) ;
49+ } ) ;
50+ } ) ;
You can’t perform that action at this time.
0 commit comments