Skip to content

Latest commit

 

History

History
26 lines (23 loc) · 593 Bytes

README.md

File metadata and controls

26 lines (23 loc) · 593 Bytes

Dijkstra's algorithm in PHP

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