taniko/dijkstra

dijkstra algorithm

v1.1.0 2017-12-06 05:58 UTC

This package is not auto-updated.

Last update: 2024-04-28 02:37:44 UTC


README

Build Status

Installation

composer require taniko/dijkstra

Usage

$graph = Taniko\Dijkstra\Graph::create();
$graph
    ->add('s', 'a', 1)
    ->add('s', 'b', 2)
    ->add('a', 'b', 2)
    ->add('a', 'c', 4)
    ->add('b', 'c', 2)
    ->add('b', 'd', 5)
    ->add('c', 'd', 1)
    ->add('c', 't', 3)
    ->add('d', 't', 1);
$route = $graph->search('s', 't'); // ['s', 'b', 'c', 'd', 't']
$cost  = $graph->cost($route);     // 6.0