@@ -34,20 +34,61 @@ public function __construct(Walk $walk)
34
34
* checks whether walk is a cycle (i.e. source vertex = target vertex)
35
35
*
36
36
* A cycle is also known as a closed path, a walk that is NOT a cycle is
37
- * alsos known as an open path.
37
+ * also known as an open path.
38
38
*
39
39
* A walk with no edges is not considered a cycle. The shortest possible
40
40
* cycle is a single loop edge.
41
41
*
42
42
* @return bool
43
43
* @link http://en.wikipedia.org/wiki/Cycle_%28graph_theory%29
44
+ * @see self::isCircuit()
45
+ * @see self::isLoop()
44
46
*/
45
47
public function isCycle ()
46
48
{
47
49
$ vertices = $ this ->walk ->getVerticesSequence ();
48
50
return (reset ($ vertices ) === end ($ vertices ) && $ this ->walk ->getEdges ());
49
51
}
50
52
53
+ /**
54
+ * checks whether this walk is a circuit (i.e. a cycle with no duplicate edges)
55
+ *
56
+ * A circuit is also known as a closed (=cycle) trail (=path), that has at
57
+ * least one edge.
58
+ *
59
+ * The following Walk is considered both a valid cycle and a valid circuit:
60
+ *
61
+ * 1 -> 2 -> 3 -\
62
+ * ^ |
63
+ * | |
64
+ * \------------/
65
+ *
66
+ * The following Walk is also considered both a valid cycle and a valid circuit:
67
+ *
68
+ * /->3--\
69
+ * | |
70
+ * 1 -> 2 -\ |
71
+ * ^ ^ | |
72
+ * | \--/ |
73
+ * | |
74
+ * \----------/
75
+ *
76
+ * The later circuit walk can be expressed by its Vertex IDs as
77
+ * "1, 2, 2, 3, 1". If however, the inner loop would be "walked along"
78
+ * several times, the resulting walk would be expressed as
79
+ * "1, 2, 2, 2, 3, 1", which would still be a valid cycle, but NOT a valid
80
+ * circuit anymore.
81
+ *
82
+ * @return boolean
83
+ * @link http://www.proofwiki.org/wiki/Definition:Circuit
84
+ * @uses self::isCycle()
85
+ * @uses self::isPath()
86
+ */
87
+ public function isCircuit ()
88
+ {
89
+ return ($ this ->isCycle () && $ this ->isPath ());
90
+ }
91
+
51
92
/**
52
93
* checks whether walk is a path (i.e. does not contain any duplicate edges)
53
94
*
@@ -67,6 +108,14 @@ public function isPath()
67
108
*
68
109
* a walk that CONTAINS a cycle does not neccessarily have to BE a cycle
69
110
*
111
+ * The following Walk is NOT a cycle, but it contains a valid cycle:
112
+ *
113
+ * /->4
114
+ * |
115
+ * 1 -> 2 -> 3 -\
116
+ * ^ |
117
+ * \-------/
118
+ *
70
119
* @return bool
71
120
* @uses self::hasArrayDuplicates()
72
121
* @see self::isCycle()
@@ -89,7 +138,15 @@ public function isLoop()
89
138
}
90
139
91
140
/**
92
- * checks whether this walk HAS a look (single edge connecting vertex A with vertex A again)
141
+ * checks whether this walk HAS a loop (single edge connecting vertex A with vertex A again)
142
+ *
143
+ * The following Walk is NOT a valid loop, but it contains a valid loop:
144
+ *
145
+ * /->3
146
+ * |
147
+ * 1 -> 2 -\
148
+ * ^ |
149
+ * \--/
93
150
*
94
151
* @return boolean
95
152
* @uses AlgorithmLoop::hasLoop()
@@ -105,9 +162,23 @@ public function hasLoop()
105
162
/**
106
163
* checks whether this walk is a digon (a pair of parallel edges in a multigraph or a pair of antiparallel edges in a digraph)
107
164
*
108
- * a digon is a cycle connecting exactly two distinct vertices with exactly
165
+ * A digon is a cycle connecting exactly two distinct vertices with exactly
109
166
* two distinct edges.
110
167
*
168
+ * The following Graph represents a digon in an undirected Graph:
169
+ *
170
+ * /--\
171
+ * 1 2
172
+ * \--/
173
+ *
174
+ * The following Graph represents a digon as a set of antiparallel directed
175
+ * Edges in directed Graph:
176
+ *
177
+ * 1 -> 2
178
+ * ^ |
179
+ * | |
180
+ * \----/
181
+ *
111
182
* @return boolean
112
183
* @uses self::hasArrayDuplicates()
113
184
* @uses self::isCycle()
@@ -127,6 +198,12 @@ public function isDigon()
127
198
/**
128
199
* checks whether this walk is a triangle (a simple cycle with exactly three distinct vertices)
129
200
*
201
+ * The following Graph is a valid directed triangle:
202
+ *
203
+ * 1->2->3
204
+ * ^ |
205
+ * \-----/
206
+ *
130
207
* @return boolean
131
208
* @uses self::isCycle()
132
209
*/
0 commit comments