You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB
PHP

<?php
namespace Graphp\Algorithms\Tree;
use Graphp\Algorithms\Tree\BaseDirected as DirectedTree;
use Fhaculty\Graph\Exception\UnexpectedValueException;
use Fhaculty\Graph\Vertex;
/**
* Usual OutTree implementation where Edges "point away" from root Vertex
*
* ROOT
* / \
* A <--/ \--> B
* \
* \--> C
*
* also known as arborescence
*
* @link http://en.wikipedia.org/wiki/Arborescence_%28graph_theory%29
* @see DirectedTree for more information on directed, rooted trees
*/
class OutTree extends DirectedTree
{
public function getVerticesChildren(Vertex $vertex)
{
$vertices = $vertex->getVerticesEdgeTo();
if ($vertices->hasDuplicates()) {
throw new UnexpectedValueException();
}
return $vertices;
}
protected function getVerticesParent(Vertex $vertex)
{
$vertices = $vertex->getVerticesEdgeFrom();
if ($vertices->hasDuplicates()) {
throw new UnexpectedValueException();
}
return $vertices;
}
}