Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Fhaculty\Graph\Graph;
- use Fhaculty\Graph\Vertex;
- use Graphp\Algorithms\Tarjan;
- // Create a simple directed 3 node loop
- $graph = new Graph();
- $a = $graph->createVertex('a');
- $b = $graph->createVertex('b');
- $c = $graph->createVertex('c');
- $a->createEdgeTo($b); $b->createEdgeTo($c); $c->createEdgeTo($a);
- // Run the algorithm
- $algorithm = new Tarjan();
- $ret = $algorithm->getStronglyConnectedVerticesFromDirectedGraph($graph);
- var_dump($ret[0]->getIds());
- // display following: (there is obviously only one strongly connected component)
- array(3) {
- [0]=>
- string(1) "c"
- [1]=>
- string(1) "b"
- [2]=>
- string(1) "a"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement