Skip to content

Commit 50753b1

Browse files
committed
Add example graphs to documentation
1 parent abe4ec8 commit 50753b1

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

src/Property/WalkProperty.php

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,21 @@ public function __construct(Walk $walk)
3737
* also known as an open path.
3838
*
3939
* A walk with no edges is not considered a cycle. The shortest possible
40-
* cycle is a single loop edge.
40+
* cycle is a single loop edge:
41+
*
42+
* 1--\
43+
* ^ |
44+
* \--/
45+
*
46+
* The following Walk is also considered a valid cycle:
47+
*
48+
* /->3--\
49+
* | |
50+
* 1 -> 2 -\ |
51+
* ^ ^ | |
52+
* | \--/ |
53+
* | |
54+
* \----------/
4155
*
4256
* @return bool
4357
* @link http://en.wikipedia.org/wiki/Cycle_%28graph_theory%29
@@ -106,9 +120,11 @@ public function isPath()
106120
/**
107121
* checks whether walk contains a cycle (i.e. contains a duplicate vertex)
108122
*
109-
* a walk that CONTAINS a cycle does not neccessarily have to BE a cycle
123+
* A walk that CONTAINS a cycle does not neccessarily have to BE a cycle.
124+
* Conversely, a Walk that *is* a cycle, automatically always *contains* a
125+
* cycle.
110126
*
111-
* The following Walk is NOT a cycle, but it contains a valid cycle:
127+
* The following Walk is NOT a cycle, but it *contains* a valid cycle:
112128
*
113129
* /->4
114130
* |
@@ -128,6 +144,17 @@ public function hasCycle()
128144
/**
129145
* checks whether this walk IS a loop (single edge connecting vertex A with vertex A again)
130146
*
147+
* A loop is the simplest possible cycle. As such, each loop is also a
148+
* cycle. Accordingly, every Walk that *is* a loop, automatically also *is*
149+
* a cycle and automatically *contains* a loop and automatically *contains*
150+
* a cycle.
151+
*
152+
* The following Walk represents a simple (directed) loop:
153+
*
154+
* 1--\
155+
* ^ |
156+
* \--/
157+
*
131158
* @return boolean
132159
* @uses self::isCycle()
133160
* @see self::hasLoop()
@@ -172,7 +199,7 @@ public function hasLoop()
172199
* \--/
173200
*
174201
* The following Graph represents a digon as a set of antiparallel directed
175-
* Edges in directed Graph:
202+
* Edges in a directed Graph:
176203
*
177204
* 1 -> 2
178205
* ^ |
@@ -225,9 +252,44 @@ public function isTriangle()
225252
*
226253
* A simple Walk is also known as a chain.
227254
*
255+
* The term "simple walk" is somewhat related to a walk with no cycles. If
256+
* a Walk has a cycle, it is not simple - with one single exception: a Walk
257+
* that IS a cycle automatically also contains a cycle, but if it contains
258+
* no "further" additional cycles, it is considered a simple cycle.
259+
*
260+
* The following Graph represents a (very) simple Walk:
261+
*
262+
* 1 -- 2
263+
*
264+
* The following Graph IS a cycle and is simple:
265+
*
266+
* 1 -> 2
267+
* ^ |
268+
* \----/
269+
*
270+
* The following Graph contains a cycle and is NOT simple:
271+
*
272+
* /->4
273+
* |
274+
* 1 -> 2 -> 3 -\
275+
* ^ |
276+
* \-------/
277+
*
278+
* The following Graph IS a cycle and thus automatically contains a cycle.
279+
* Due to the additional "inner" cycle (loop at vertex 2), it is NOT simple:
280+
*
281+
* /->3--\
282+
* | |
283+
* 1 -> 2 -\ |
284+
* ^ ^ | |
285+
* | \--/ |
286+
* | |
287+
* \----------/
288+
*
228289
* @return boolean
229290
* @uses self::isCycle()
230291
* @uses self::hasArrayDuplicates()
292+
* @see self::hasCycle()
231293
*/
232294
public function isSimple()
233295
{

0 commit comments

Comments
 (0)