PHP code example of bmichotte / dijkstra

1. Go to this page and download the library: Download bmichotte/dijkstra library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bmichotte / dijkstra example snippets


// 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