A package containing a simple graph implementation and important graph algorithms for pathfinding to specific nodes.
With this package you are able to
- create a simple graph with as many nodes as you want
- connect multiple nodes
- generate a list of all nodes, which contain a list of all adjacent nodes
- pathfind from any node to any other node (1:1 routing)
- pathfind from any node to a list of other nodes (1:1^n routing, meaning creating a route to n nodes without re-visiting the first node)
Currently the underlaying routing algorithm is implemented with dijkstra and a navie priority queue. Support for a fibonacci queue is planned.
To use this package you just need to import it. Since this package is not published on pub.dev
or any other package repository, you need to import it from github:
dependencies:
store_navigation_graph:
git:
url: https://github.com/ShoppingNavigation/navigation_graph.git
ref: main
A minimal example to route in a graph with just two nodes:
final Node nodeA = Node('A');
final Node nodeB = Node('B');
final NavigationGraph graph = NavigationGraph(nodes: [nodeA, nodeB]);
// create an unidirectional connection between node a and node b
// (no need to do '.connect(nodeB, nodeA)' as well)
graph.connect(nodeA, nodeB, 2);
final RouteToResult? result = graph.routeTo(nodeA, nodeB);
An example with a more complicated graph can be found in the examples folder (example/more_complicated_example.dart
).
The following graph was used in the example: