private function getVerticesSubtreeRecursive(Vertex $vertex, array &$vertices, Vertex $ignore = null)
    {
        if (isset($vertices[$vertex->getId()])) {
            // vertex already visited => must be a cycle
            throw new UnexpectedValueException('Vertex already visited');
        }
        $vertices[$vertex->getId()] = $vertex;

        foreach ($this->getVerticesNeighbor($vertex) as $vertexNeighboor) {
            if ($vertexNeighboor === $ignore) {
                // ignore source vertex only once
                $ignore = null;
                continue;
            }
            $this->getVerticesSubtreeRecursive($vertexNeighboor, $vertices, $vertex);
        }
    }
private function getVerticesSubtreeRecursive(Vertex $vertex, array &$vertices, Vertex $ignore = null)
    {
        if (isset($vertices[$vertex->getId()])) {
            // vertex already visited => must be a cycle
            throw new UnexpectedValueException('Vertex already visited');
        }
        $vertices[$vertex->getId()] = $vertex;

        foreach ($this->getVerticesNeighbor($vertex) as $vertexNeighboor) {
            if ($vertexNeighboor === $ignore) {
                // ignore source vertex only once
                $ignore = null;
                continue;
            }
            $this->getVerticesSubtreeRecursive($vertexNeighboor, $vertices, $vertex);
        }
    }
private function getVerticesSubtreeRecursive ( Vertex $ vertex , array & $ vertices , Vertex $ ignore = null ) { if ( isset ( $ vertices [ $ vertex -> getId ( ) ] ) ) { // vertex already visited => must be a cycle throw new UnexpectedValueException ( 'Vertex already visited' ) ; } $ vertices [ $ vertex -> getId ( ) ] = $ vertex ; foreach ( $ this -> getVerticesNeighbor ( $ vertex ) as $ vertexNeighboor ) { if ( $ vertexNeighboor === $ ignore ) { // ignore source vertex only once $ ignore = null ; continue ; } $ this -> getVerticesSubtreeRecursive ( $ vertexNeighboor , $ vertices , $ vertex ) ; } }
get subtree for given Vertex and ignore path to "parent" ignoreVertex

@param Vertex      $vertex
@param Vertex[]    $vertices
@param Vertex|null $ignore
@throws UnexpectedValueException for cycles or directed edges (check isTree()!)
@uses self::getVerticesNeighbor()
@uses self::getVerticesSubtreeRecursive() to recurse into sub-subtrees
get subtree for given Vertex and ignore path to parent ignoreVertex