|
4 | 4 |
|
5 | 5 | use Fhaculty\Graph\Algorithm\Base as AlgorithmBase;
|
6 | 6 | use Fhaculty\Graph\Set\Edges;
|
| 7 | +use Fhaculty\Graph\Exception\UnexpectedValueException; |
| 8 | +use Fhaculty\Graph\Edge\Directed as EdgeDirected; |
7 | 9 |
|
| 10 | +/** |
| 11 | + * Abstract base class for minimum spanning tree (MST) algorithms |
| 12 | + * |
| 13 | + * A minimum spanning tree of a graph is a subgraph that is a tree and connects |
| 14 | + * all the vertices together while minimizing the total sum of all edges' |
| 15 | + * weights. |
| 16 | + * |
| 17 | + * A spanning tree thus requires a connected graph (single connected component), |
| 18 | + * otherwise we can span multiple trees (spanning forest) within each component. |
| 19 | + * Because a null graph (a Graph with no vertices) is not considered connected, |
| 20 | + * it also can not contain a spanning tree. |
| 21 | + * |
| 22 | + * @link http://en.wikipedia.org/wiki/Minimum_Spanning_Tree |
| 23 | + * @link http://en.wikipedia.org/wiki/Spanning_Tree |
| 24 | + * @link http://mathoverflow.net/questions/120536/is-the-empty-graph-a-tree |
| 25 | + */ |
8 | 26 | abstract class Base extends AlgorithmBase
|
9 | 27 | {
|
10 | 28 | /**
|
11 | 29 | * create new resulting graph with only edges on minimum spanning tree
|
12 | 30 | *
|
13 | 31 | * @return Graph
|
14 |
| - * @uses AlgorithmMst::getEdges() |
| 32 | + * @uses self::getGraph() |
| 33 | + * @uses self::getEdges() |
15 | 34 | * @uses Graph::createGraphCloneEdges()
|
16 | 35 | */
|
17 | 36 | public function createGraph()
|
18 | 37 | {
|
19 |
| - // Copy Graph |
20 | 38 | return $this->getGraph()->createGraphCloneEdges($this->getEdges());
|
21 | 39 | }
|
22 | 40 |
|
23 |
| - abstract protected function getGraph(); |
24 |
| - |
25 | 41 | /**
|
26 | 42 | * get all edges on minimum spanning tree
|
27 | 43 | *
|
28 | 44 | * @return Edges
|
29 | 45 | */
|
30 | 46 | abstract public function getEdges();
|
| 47 | + |
| 48 | + /** |
| 49 | + * return reference to current Graph |
| 50 | + * |
| 51 | + * @return Graph |
| 52 | + */ |
| 53 | + abstract protected function getGraph(); |
31 | 54 | }
|
0 commit comments