File tree Expand file tree Collapse file tree 5 files changed +28
-10
lines changed Expand file tree Collapse file tree 5 files changed +28
-10
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Fhaculty \Graph \Algorithm \BaseGraph ;
6
6
use Fhaculty \Graph \Graph ;
7
+ use Fhaculty \Graph \Algorithm \Degree ;
7
8
8
9
class Eulerian extends BaseGraph
9
10
{
@@ -12,16 +13,18 @@ class Eulerian extends BaseGraph
12
13
*
13
14
* @return boolean
14
15
* @uses Graph::isConnected()
15
- * @uses Vertex::getDegree ()
16
+ * @uses Degree::getDegreeVertex ()
16
17
* @todo isolated vertices should be ignored
17
18
* @todo definition is only valid for undirected graphs
18
19
*/
19
20
public function hasCycle ()
20
21
{
21
22
if ($ this ->graph ->isConnected ()) {
23
+ $ alg = new Degree ($ this ->graph );
24
+
22
25
foreach ($ this ->graph ->getVertices () as $ vertex ) {
23
26
// uneven degree => fail
24
- if ($ vertex -> getDegree ( ) & 1 ) {
27
+ if ($ alg -> getDegreeVertex ( $ vertex ) & 1 ) {
25
28
return false ;
26
29
}
27
30
}
Original file line number Diff line number Diff line change 8
8
use Fhaculty \Graph \Exception \UnderflowException ;
9
9
use Fhaculty \Graph \Exception \UnexpectedValueException ;
10
10
use Fhaculty \Graph \Algorithm \Search \StrictDepthFirst ;
11
+ use Fhaculty \Graph \Algorithm \Degree ;
11
12
12
13
/**
13
14
* Abstract base class for tree algorithms
35
36
*/
36
37
abstract class Base extends BaseGraph
37
38
{
39
+ /**
40
+ *
41
+ * @var Degree
42
+ */
43
+ protected $ degree ;
44
+
45
+ public function __construct (Graph $ graph )
46
+ {
47
+ parent ::__construct ($ graph );
48
+
49
+ $ this ->degree = new Degree ($ graph );
50
+ }
51
+
38
52
/**
39
53
* checks whether the given graph is actually a tree
40
54
*
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ class InTree extends DirectedTree
25
25
public function getVerticesChildren (Vertex $ vertex )
26
26
{
27
27
$ vertices = $ vertex ->getVerticesEdgeFrom ();
28
- if (count ($ vertices ) !== $ vertex -> getDegreeIn ( )) {
28
+ if (count ($ vertices ) !== $ this -> degree -> getDegreeInVertex ( $ vertex )) {
29
29
throw new UnexpectedValueException ();
30
30
}
31
31
@@ -35,7 +35,7 @@ public function getVerticesChildren(Vertex $vertex)
35
35
protected function getVerticesParent (Vertex $ vertex )
36
36
{
37
37
$ vertices = $ vertex ->getVerticesEdgeTo ();
38
- if (count ($ vertices ) !== $ vertex -> getDegreeOut ( )) {
38
+ if (count ($ vertices ) !== $ this -> degree -> getDegreeOutVertex ( $ vertex )) {
39
39
throw new UnexpectedValueException ();
40
40
}
41
41
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ class OutTree extends DirectedTree
25
25
public function getVerticesChildren (Vertex $ vertex )
26
26
{
27
27
$ vertices = $ vertex ->getVerticesEdgeTo ();
28
- if (count ($ vertices ) !== $ vertex -> getDegreeOut ( )) {
28
+ if (count ($ vertices ) !== $ this -> degree -> getDegreeOutVertex ( $ vertex )) {
29
29
throw new UnexpectedValueException ();
30
30
}
31
31
@@ -35,7 +35,7 @@ public function getVerticesChildren(Vertex $vertex)
35
35
protected function getVerticesParent (Vertex $ vertex )
36
36
{
37
37
$ vertices = $ vertex ->getVerticesEdgeFrom ();
38
- if (count ($ vertices ) !== $ vertex -> getDegreeIn ( )) {
38
+ if (count ($ vertices ) !== $ this -> degree -> getDegreeInVertex ( $ vertex )) {
39
39
throw new UnexpectedValueException ();
40
40
}
41
41
Original file line number Diff line number Diff line change 10
10
use Fhaculty \Graph \Vertex ;
11
11
use Fhaculty \Graph \Edge \Base as Edge ;
12
12
use Fhaculty \Graph \Edge \UndirectedId as UndirectedEdge ;
13
+ use Fhaculty \Graph \Algorithm \Degree ;
13
14
14
15
/**
15
16
* Undirected tree implementation
@@ -76,23 +77,23 @@ public function isTree()
76
77
*
77
78
* @param Vertex $vertex
78
79
* @return boolean
79
- * @uses Vertex::getDegree ()
80
+ * @uses Degree::getDegreeVertex ()
80
81
*/
81
82
public function isVertexLeaf (Vertex $ vertex )
82
83
{
83
- return ($ vertex -> getDegree ( ) === 1 );
84
+ return ($ this -> degree -> getDegreeVertex ( $ vertex ) === 1 );
84
85
}
85
86
86
87
/**
87
88
* checks if the given $vertex is an internal vertex (inner vertex with at least 2 edges)
88
89
*
89
90
* @param Vertex $vertex
90
91
* @return boolean
91
- * @uses Vertex::getDegree ()
92
+ * @uses Degree::getDegreeVertex ()
92
93
*/
93
94
public function isVertexInternal (Vertex $ vertex )
94
95
{
95
- return ($ vertex -> getDegree ( ) >= 2 );
96
+ return ($ this -> degree -> getDegreeVertex ( $ vertex ) >= 2 );
96
97
}
97
98
98
99
/**
You can’t perform that action at this time.
0 commit comments