bmssp 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,20 +29,31 @@ To use this package, you can import it in your JavaScript code as follows:
29
29
 
30
30
  ```javascript
31
31
  // This is a WIP example
32
- import { printMessage, processMessage } from "bmssp";
32
+ import { BMSSP } from "bmssp";
33
33
 
34
- printMessage("Hello, World!");
35
- processMessage("Hello, World!");
34
+ const myBMSSP = new BMSSP([
35
+ [0, 1, 50],
36
+ [1, 2, 75],
37
+ [0, 2, 25],
38
+ ]);
39
+
40
+ console.log(myBMSSP.graph);
36
41
  ```
37
42
 
38
43
  The file must use ECMAScript modules (ESM) syntax and have the `.mjs` file extension. Go to the `examples` directory for more usage examples.
39
44
 
40
45
  ### Using the docker image
41
46
 
42
- You can also use the published docker image and run your tests (assuming a `mytest.mjs` in this example) in a pre-configured environment:
47
+ You can also use the published docker image and run the example:
48
+
49
+ ```bash
50
+ docker run -it sirivasv/bmssp-js:latest
51
+ ```
52
+
53
+ Or your tests in a pre-configured environment (replace `folder-mytest/` with your tests folder and `index.mjs` with your test file):
43
54
 
44
55
  ```bash
45
- docker run -it -v ./mytest.mjs:/bmssp-js/mytest.mjs sirivasv/bmssp-js:latest node /bmssp-js/mytest.mjs
56
+ docker run -it -v ./folder-mytest/:/bmssp-js/folder-mytest/ sirivasv/bmssp-js:latest node /bmssp-js/folder-mytest/index.mjs
46
57
  ```
47
58
 
48
59
  Other versions of the docker image can be found on [Docker Hub](https://hub.docker.com/r/sirivasv/bmssp-js/tags).
package/index.mjs CHANGED
@@ -1 +1 @@
1
- export { printMessage, processMessage } from "./src/bmssp.mjs";
1
+ export { BMSSP } from "./src/bmssp.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bmssp",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Javascript package implementation of the bmssp algorithm.",
5
5
  "main": "index.mjs",
6
6
  "keywords": [
package/src/bmssp.mjs CHANGED
@@ -1,9 +1,46 @@
1
- function printMessage(message) {
2
- return message;
3
- }
1
+ class BMSSP {
2
+ constructor(inputGraph) {
3
+ // Main graph represented as an array of edges
4
+ this.graph = [];
5
+ // Set to store unique node IDs
6
+ this.nodeIDs = new Set();
7
+ // Map to store shortest paths
8
+ this.shortestPaths = new Map();
9
+
10
+ for (let edge of inputGraph) {
11
+ // Create a deep copy of each edge array
12
+ this.graph.push([...edge]);
13
+
14
+ // Add node IDs to the set
15
+ this.nodeIDs.add(edge[0]);
16
+ this.nodeIDs.add(edge[1]);
17
+ }
18
+
19
+ // Initialize shortest paths map
20
+ this.initializeShortestPaths();
21
+ }
22
+
23
+ // Method to initialize the shortest paths map
24
+ initializeShortestPaths() {
25
+ for (let nodeId of this.nodeIDs) {
26
+ this.shortestPaths.set(nodeId, Infinity);
27
+ }
28
+ }
29
+
30
+ // Method to calculate shortest paths (placeholder implementation)
31
+ calculateShortestPaths(startNode) {
32
+ // To clean the state before calculation
33
+ this.initializeShortestPaths();
34
+
35
+ // validate startNode
36
+ if (!this.nodeIDs.has(startNode)) {
37
+ throw new Error("Start node not found in the graph");
38
+ }
4
39
 
5
- function processMessage(message) {
6
- return `Processed: ${message}`;
40
+ // Placeholder logic for shortest path calculation
41
+ // This should be replaced with an actual implementation of BMSSP algorithm
42
+ this.shortestPaths.set(startNode, 0);
43
+ }
7
44
  }
8
45
 
9
- export { printMessage, processMessage };
46
+ export { BMSSP };