Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. <?php
  2. use Fhaculty\Graph\Graph;
  3. use Fhaculty\Graph\Vertex;
  4. use Graphp\Algorithms\Tarjan;
  5.  
  6. // Create a simple directed 3 node loop
  7. $graph = new Graph();
  8. $a = $graph->createVertex('a');
  9. $b = $graph->createVertex('b');
  10. $c = $graph->createVertex('c');
  11. $a->createEdgeTo($b); $b->createEdgeTo($c); $c->createEdgeTo($a);
  12.  
  13. // Run the algorithm
  14. $algorithm = new Tarjan();
  15. $ret = $algorithm->getStronglyConnectedVerticesFromDirectedGraph($graph);
  16. var_dump($ret[0]->getIds());
  17.  
  18. // display following: (there is obviously only one strongly connected component)
  19. array(3) {
  20. [0]=>
  21. string(1) "c"
  22. [1]=>
  23. string(1) "b"
  24. [2]=>
  25. string(1) "a"
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement