4
4
5
5
use Fhaculty \Graph \Algorithm \BaseGraph ;
6
6
use Fhaculty \Graph \Edge \Directed as EdgeDirected ;
7
+ use Fhaculty \Graph \Edge \Undirected as EdgeUndirected ;
7
8
8
9
/**
9
10
* Basic algorithms for working with the undirected or directed Graphs (digraphs) / Walks.
14
15
class Directed extends BaseDual
15
16
{
16
17
/**
17
- * checks whether the graph has any directed edges (aka digraph)
18
+ * checks whether the graph has any directed edges
19
+ *
20
+ * This method is intentionally not named "isDirected()" (aka digraph),
21
+ * because that might be misleading in regards to empty and/or mixed graphs.
18
22
*
19
23
* @return boolean
20
24
*/
21
- public function isDirected ()
25
+ public function hasDirected ()
22
26
{
23
27
foreach ($ this ->set ->getEdges () as $ edge ) {
24
28
if ($ edge instanceof EdgeDirected) {
@@ -28,4 +32,35 @@ public function isDirected()
28
32
29
33
return false ;
30
34
}
35
+
36
+ /**
37
+ * checks whether the graph has any undirected edges
38
+ *
39
+ * This method is intentionally not named "isUndirected()",
40
+ * because that might be misleading in regards to empty and/or mixed graphs.
41
+ *
42
+ * @return boolean
43
+ */
44
+ public function hasUndirected ()
45
+ {
46
+ foreach ($ this ->set ->getEdges () as $ edge ) {
47
+ if ($ edge instanceof EdgeUndirected) {
48
+ return true ;
49
+ }
50
+ }
51
+
52
+ return false ;
53
+ }
54
+
55
+ /**
56
+ * checks whether this is a mixed graph (contains both directed and undirected edges)
57
+ *
58
+ * @return boolean
59
+ * @uses self::hasDirected()
60
+ * @uses self::hasUndirected()
61
+ */
62
+ public function isMixed ()
63
+ {
64
+ return ($ this ->hasDirected () && $ this ->hasUndirected ());
65
+ }
31
66
}
0 commit comments