File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-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 \Graph ;
6
+
7
+ class Complete extends Base
8
+ {
9
+ /**
10
+ *
11
+ * @var Graph
12
+ */
13
+ private $ graph ;
14
+
15
+ public function __construct (Graph $ graph )
16
+ {
17
+ $ this ->graph = $ graph ;
18
+ }
19
+
20
+ /**
21
+ * checks whether this graph is complete (every vertex has an edge to any other vertex)
22
+ *
23
+ * @return boolean
24
+ * @uses Graph::getVertices()
25
+ * @uses Vertex::hasEdgeTo()
26
+ */
27
+ public function isComplete ()
28
+ {
29
+ // copy of array (separate iterator but same vertices)
30
+ $ c = $ vertices = $ this ->graph ->getVertices ();
31
+ // from each vertex
32
+ foreach ($ vertices as $ vertex ) {
33
+ // to each vertex
34
+ foreach ($ c as $ other ) {
35
+ // missing edge => fail
36
+ if ($ other !== $ vertex && !$ vertex ->hasEdgeTo ($ other )) {
37
+ return false ;
38
+ }
39
+ }
40
+ }
41
+
42
+ return true ;
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments