getditto / dijkstra-calculator Goto Github PK
View Code? Open in Web Editor NEWA simple JS calculator for finding the shortest path in a graph of nodes.
Home Page: https://getditto.github.io/dijkstra-calculator/
License: MIT License
A simple JS calculator for finding the shortest path in a graph of nodes.
Home Page: https://getditto.github.io/dijkstra-calculator/
License: MIT License
I'm submitting a ...
[ ] bug report
[x] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project
Summary
Can this return the weight as well?
I'm submitting a ...
[ ] bug report
[x] feature request
[x] question about the decisions made in the repository
[ ] question about how to use this project
Summary
It seems that the current implementation assumes graph is undirected, so calling addEdge("A", "B")
is symetric to addEdge("B", "A")
(and actually does both).
This means that it's not possible to calculate Dijkstra for directed graphs.
Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
I compared this behavior with the dijkstrajs
module, which does support directed graphs.
Here's the comparison code:
const { DijkstraCalculator } = require("dijkstra-calculator");
const { find_path } = require ("dijkstrajs");
// Directed graph
// Vertex:
// A, B, C, D
// Edges:
// B -> A
// C -> B
// D -> B
// D -> C
// Test #1
// D => A expected D -> B -> A
// Test #2
// A => D expected to throw / return empty
// dijkstra-calculator
const graph = new DijkstraCalculator();
graph.addVertex("A");
graph.addVertex("B");
graph.addVertex("C");
graph.addVertex("D");
graph.addEdge("B", "A");
graph.addEdge("C", "B");
graph.addEdge("D", "B");
graph.addEdge("D", "C");
console.log(`dijkstra-calculator: D->A: ${graph.calculateShortestPath("D", "A")}`); // should be ["D", "B", "A"]
console.log(`dijkstra-calculator: A->D: ${graph.calculateShortestPath("A", "D")}`); // should be [] or thorw
// dijkstra-js
const graph2 = {
"A": {},
"B": {
"A": 1
},
"C": {
"B": 1
},
"D": {
"B": 1,
"C": 1
}
}
console.log(`dijkstra-js: D->A: ${find_path(graph2, "D", "A")}`); // should be ["D", "B", "A"]
console.log(`dijkstra-js: A->D: ${find_path(graph2, "A", "D")}`); // should throw
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.