Skip to content

Commit abe4ec8

Browse files
committed
Add WalkProperty::isCircuit() and lots of examples in documentation
1 parent 1f70835 commit abe4ec8

File tree

1 file changed

+80
-3
lines changed

1 file changed

+80
-3
lines changed

src/Property/WalkProperty.php

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,61 @@ public function __construct(Walk $walk)
3434
* checks whether walk is a cycle (i.e. source vertex = target vertex)
3535
*
3636
* 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.
3838
*
3939
* A walk with no edges is not considered a cycle. The shortest possible
4040
* cycle is a single loop edge.
4141
*
4242
* @return bool
4343
* @link http://en.wikipedia.org/wiki/Cycle_%28graph_theory%29
44+
* @see self::isCircuit()
45+
* @see self::isLoop()
4446
*/
4547
public function isCycle()
4648
{
4749
$vertices = $this->walk->getVerticesSequence();
4850
return (reset($vertices) === end($vertices) && $this->walk->getEdges());
4951
}
5052

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+
5192
/**
5293
* checks whether walk is a path (i.e. does not contain any duplicate edges)
5394
*
@@ -67,6 +108,14 @@ public function isPath()
67108
*
68109
* a walk that CONTAINS a cycle does not neccessarily have to BE a cycle
69110
*
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+
*
70119
* @return bool
71120
* @uses self::hasArrayDuplicates()
72121
* @see self::isCycle()
@@ -89,7 +138,15 @@ public function isLoop()
89138
}
90139

91140
/**
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+
* \--/
93150
*
94151
* @return boolean
95152
* @uses AlgorithmLoop::hasLoop()
@@ -105,9 +162,23 @@ public function hasLoop()
105162
/**
106163
* checks whether this walk is a digon (a pair of parallel edges in a multigraph or a pair of antiparallel edges in a digraph)
107164
*
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
109166
* two distinct edges.
110167
*
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+
*
111182
* @return boolean
112183
* @uses self::hasArrayDuplicates()
113184
* @uses self::isCycle()
@@ -127,6 +198,12 @@ public function isDigon()
127198
/**
128199
* checks whether this walk is a triangle (a simple cycle with exactly three distinct vertices)
129200
*
201+
* The following Graph is a valid directed triangle:
202+
*
203+
* 1->2->3
204+
* ^ |
205+
* \-----/
206+
*
130207
* @return boolean
131208
* @uses self::isCycle()
132209
*/

0 commit comments

Comments
 (0)