https://github.com/noweh/laravel-dijkstra
Dijkstra Shortest path-algorithm for Laravel.
https://github.com/noweh/laravel-dijkstra
dijkstra-algorithm graph-algorithms laravel-package php
Last synced: 2 months ago
JSON representation
Dijkstra Shortest path-algorithm for Laravel.
- Host: GitHub
- URL: https://github.com/noweh/laravel-dijkstra
- Owner: noweh
- License: mit
- Created: 2022-08-09T10:00:19.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-09-02T19:00:38.000Z (over 3 years ago)
- Last Synced: 2025-03-29T04:11:15.872Z (9 months ago)
- Topics: dijkstra-algorithm, graph-algorithms, laravel-package, php
- Language: PHP
- Homepage:
- Size: 351 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Dijkstra algorithm for Laravel
[](https://laravel.com/)

[](LICENSE)
A laravel implementation of [Dijkstra algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm).
Dijkstra's algorithm, conceived by computer scientist Edsger Dijkstra, is a graph search algorithm that solves in single-source shortest path problem for a graph with non-negative edge path costs, producing a shortest path tree.
## Installation
First you need to add the component to your composer.json
```
composer require noweh/laravel-dijkstra
```
Update your packages with *composer update* or install with *composer install*.
Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
### Laravel without auto-discovery
After updating composer, add the ServiceProvider to the providers array in config/app.php
Noweh\Dijkstra\DijkstraServiceProvider::class,
### Migration
The migrations of this package are publishable under the "migrations" tag via:
php artisan vendor:publish --provider="Noweh\Dijkstra\DijkstraServiceProvider" --tag="migrations"
## Usage
### Operations with Points and draw graph / find shortest path
```php
createStructure([
['name' => 'A', 'x' => 250, 'y' => 120],
['name' => 'B', 'x' => 120, 'y' => 228],
// ...
['name' => 'H', 'x' => 400, 'y' => 460]
], [
['A' => 'B'],
// ...
['H' => 'D']
]);
// add One point
$pointsService->addPoint(['name' => 'I', 'x' => 60, 'y' => 30]);
// Remove one point
$pointsService->removePoint('B');
// Add relation
$pointsService->addRelation(['E' => 'I']);
// Remove relation
$pointsService->removeRelation(['A' => 'B']);
// Retrieve all points
dump($pointsService->getPoints());
/** @var IGraphService $graphService */
$graphService = \Dijkstra::graphService();
$pointFrom = $pointsService->getPoint('B');
$pointTo = $pointsService->getPoint('C');
dump($graphService->findShortestPath($pointFrom, $pointTo));
// Draw a Graph
$graphService->drawGraph($pointFrom, $pointTo);
```
#### Display example with the use of the drawGraph() method
