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.

53 lines
1.1 KiB
PHP

<?php
namespace Graphp\Algorithms;
use Graphp\Algorithms\BaseDual;
use Fhaculty\Graph\Edge\Base as Edge;
use Fhaculty\Graph\Vertex;
/**
* Basic algorithms for working with loop edges
*
* A loop (also called a self-loop or a "buckle") is an edge that connects a
* Vertex to itself. A simple graph contains no loops.
*
* @link http://en.wikipedia.org/wiki/Loop_%28graph_theory%29
*/
class Loop extends BaseDual
{
/**
* checks whether this graph has any loops (edges from vertex to itself)
*
* @return boolean
* @uses Edge::isLoop()
*/
public function hasLoop()
{
foreach ($this->set->getEdges() as $edge) {
if ($edge->isLoop()) {
return true;
}
}
return false;
}
/**
* checks whether this vertex has a loop (edge to itself)
*
* @return boolean
* @uses Edge::isLoop()
*/
public function hasLoopVertex(Vertex $vertex)
{
foreach ($vertex->getEdges() as $edge) {
if ($edge->isLoop()) {
return true;
}
}
return false;
}
}