Skip to content

Commit

Permalink
example
Browse files Browse the repository at this point in the history
  • Loading branch information
bmichotte committed Feb 28, 2019
1 parent 48e258c commit 7c7c2d2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,30 @@ More on the algorithm : https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

You can find an example on the `example` directory. The result of this example should be something like
![shortest paths](https://github.com/bmichotte/dijkstra/blob/master/example/image.png)

## Installation

Run `composer require bmichotte/dijkstra`

## Usage

```php
// create some points
$point1 = new \Bmichotte\Dijkstra\Point(/* x */ 1, /* y */ 1);
$point2 = new \Bmichotte\Dijkstra\Point(2, 2);
$point3 = new \Bmichotte\Dijkstra\Point(3, 3);

$all_points = [$point1, $point2, $point3];

// "join" them
$point1->addPoint($point2);
$point1->addPoint($point3);
$point2->addPoint($point3);

// find the shortest path
$dijkstra = new \Bmichotte\Dijkstra\Dijkstra($all_points, /* from */ $point1, /* to */ $point3);
$shortest_path = $dijkstra->findShortestPath();

// $shortest_path[0] == $point1
// $shortest_path[1] == $point3
```

0 comments on commit 7c7c2d2

Please sign in to comment.