https://github.com/comradevanti/fdijkstra
An F# implementation of Dijkstras algorithm
https://github.com/comradevanti/fdijkstra
Last synced: about 1 month ago
JSON representation
An F# implementation of Dijkstras algorithm
- Host: GitHub
- URL: https://github.com/comradevanti/fdijkstra
- Owner: ComradeVanti
- Created: 2021-12-18T08:21:19.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-19T10:27:53.000Z (over 1 year ago)
- Last Synced: 2025-09-01T12:20:48.399Z (about 1 month ago)
- Language: F#
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# FDijkstra
[](https://www.nuget.org/packages/ComradeVanti.FDijkstra)An F# implementation of Dijkstras algorithm
**⚠️ Development is paused ⚠️**
No new features will be added or bugs fixed unless requested through an issue.
If you wish to fork this repository and continue the work, you are very welcome
to do so.The implementation works with all sorts of graphs as long as it fulfills the following requirements:
- It has vertices
- It can find vertices connected to a specific vertex
- It can measure the distance between two connected verticesThe general syntax for using the algorithm is
`ComradeVanti.FDijkstra.Dijkstra.solve start goal vertices neighbors distanceBetween`
with
- `start` is the vertex where from which to begin the search
- `goal` is the vertex where to which a path should be searched
- `vertices` are all the vertices in the graph
- `neighbors` is a function which finds adjacent vertices to a vertex
- `distanceBetween` is a function which measures distance between two connected verticesAn example with actual values could be:
```
let vertices = [ 0; 1; 2; 3 ]// Tuples are of the form ((vertex1, vertex2), distance)
let edges =
[ ((0, 1), 2)
((1, 2), 4)
((2, 3), 3)
((1, 3), 7)
((0, 2), 4) ]let neighbors v =
[ edges
|> List.filter (fst >> fst >> (=) v)
|> List.map (fst >> snd)
edges
|> List.filter (fst >> snd >> (=) v)
|> List.map (fst >> fst) ]
|> List.concatlet distance v1 v2 =
edges
|> List.tryFind (fst >> (fun e -> e = (v1, v2) || e = (v2, v1)))
|> Option.map snd
|> Option.defaultValue 1000solve 0 3 vertices neighbors distance
```