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,6 +4,8 @@ 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
@@ -12,6 +14,11 @@ class BMSSP {
1214 this . nodeIDs . add ( edge [ 0 ] ) ;
1315 this . nodeIDs . add ( edge [ 1 ] ) ;
1416 }
17+
18+ // Initialize shortest paths with Infinity on each nodeID (after all nodes are collected)
19+ for ( let nodeId of this . nodeIDs ) {
20+ this . shortestPaths . push ( [ nodeId , Infinity ] ) ;
21+ }
1522 }
1623}
1724
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