File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Fhaculty \Graph \Algorithm ;
4
+
5
+ use Fhaculty \Graph \Edge \Directed as EdgeDirected ;
6
+ use Fhaculty \Graph \Graph ;
7
+ use Fhaculty \Graph \Vertex ;
8
+
9
+ class Symmetric extends Base
10
+ {
11
+ /**
12
+ *
13
+ * @var Graph
14
+ */
15
+ private $ graph ;
16
+
17
+ public function __construct (Graph $ graph )
18
+ {
19
+ $ this ->graph = $ graph ;
20
+ }
21
+
22
+ /**
23
+ * checks whether this graph is symmetric (for every edge a->b there's also an edge b->a)
24
+ *
25
+ * @return boolean
26
+ * @uses Graph::getEdges()
27
+ * @uses EdgeDirected::getVertexStart()
28
+ * @uses EdgeDirected::getVertedEnd()
29
+ * @uses Vertex::hasEdgeTo()
30
+ */
31
+ public function isSymmetric ()
32
+ {
33
+ // check all edges
34
+ foreach ($ this ->graph ->getEdges () as $ edge ) {
35
+ // only check directed edges (undirected ones are symmetric by definition)
36
+ if ($ edge instanceof EdgeDirected) {
37
+ // check if end also has an edge to start
38
+ if (!$ edge ->getVertexEnd ()->hasEdgeTo ($ edge ->getVertexStart ())) {
39
+ return false ;
40
+ }
41
+ }
42
+ }
43
+
44
+ return true ;
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments