Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hbarcelos/best-route
Finds the best (cheapest) route from a starting point towards a destination
https://github.com/hbarcelos/best-route
dijkstra-algorithm functional-programming graph graph-algorithms graphs javascript ramda tape
Last synced: about 1 month ago
JSON representation
Finds the best (cheapest) route from a starting point towards a destination
- Host: GitHub
- URL: https://github.com/hbarcelos/best-route
- Owner: hbarcelos
- Created: 2019-02-25T03:30:14.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-30T12:55:41.000Z (over 1 year ago)
- Last Synced: 2024-04-14T05:53:09.637Z (8 months ago)
- Topics: dijkstra-algorithm, functional-programming, graph, graph-algorithms, graphs, javascript, ramda, tape
- Language: JavaScript
- Size: 424 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Best Route
## Summary
Given a file containing all available flight prices between different airports and the desired origin and destination, it gives you the best (cheapest) route.
## Environment Setup
This project uses Node.js as runtime environment and Yarn as package manager.
Requirements:
- [Node.js](https://nodejs.org/dist/v11.10.0/) >= 11.0.0
- [Yarn](https://yarnpkg.com/en/docs/install) >= 1.13.0After installing the packages above, clone this repository:
```bash
git clone https://github.com/hbarcelos/best-route.git
```Switch to the project folder:
```bash
cd best-route
```## Dependencies
Once in the project folder, run to install the project dependencies:
```bash
yarn install
```## Usage
```bash
yarn start " - "
```## Testing
```bash
yarn test
```## Architectural Overview
### File structure
```
./
├── digraph/
│ ├── digraph.js
│ ├── digraph.test.js
│ ├── edge-set.js
│ ├── edge-set.test.js
│ ├── edge.js
│ ├── edge.test.js
│ ├── index.js
│ ├── priority-queue.js
│ └── priority-queue.test.js
├── csv.js
├── index.js
├── package.json
├── parse-available-routes.js
├── parse-query-route.js
├── read-file.js
├── sample-input.csv
├── test-runner.js
└── yarn.lock
```### Remarks
- Within the `digraph` folder lies the implementation of a Directed Graph, which provides a `.shortestPath()` method that is used to find the best route.
- `digraph.Digraph#shortestPath()` implements a slightly modified version of the [Dijkstra's Shortest Path First algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm).
- Instead of relying solely on arrays and maps, `digraph.EdgeSet` is a higher-level representation of graph edges.
- `digraph.PriorityQueue` is used by `digraph.Digraph#shortestPath()` to allow prioritization of the cheapest nodes during graph traversal.
- `parseAvailableRoutes` is a pure functional pipeline to parse the routes CSV representation into a `digraph.Digraph` instance.
- `parseQueryRoute` will parse the second CLI param: the desired route.
- `csv` module is another pure functional pipeline to parse CSV text into JavaScript arrays.
- It works only with in-memory CSV. The file read is performed in the `main` function in `index.js` before calling this function.
- `readFile` is a convenience wrapper around Node.js native `fs` module.