File tree Expand file tree Collapse file tree 5 files changed +18
-16
lines changed Expand file tree Collapse file tree 5 files changed +18
-16
lines changed Original file line number Diff line number Diff line change 6
6
use Fhaculty \Graph \Graph ;
7
7
use Fhaculty \Graph \Vertex ;
8
8
use Fhaculty \Graph \Exception \UnexpectedValueException ;
9
+ use Fhaculty \Graph \Set \Vertices ;
9
10
10
11
/**
11
12
* Basic algorithms for working with the degrees of Graphs.
@@ -49,25 +50,25 @@ public function getDegree()
49
50
*
50
51
* @return int
51
52
* @throws Exception if graph is empty or directed
52
- * @uses Vertex::getFirst ()
53
+ * @uses Vertices::getVertexOrder ()
53
54
* @uses Vertex::getDegree()
54
55
*/
55
56
public function getDegreeMin ()
56
57
{
57
- return Vertex:: getFirst ( $ this ->graph ->getVertices (), Vertex ::ORDER_DEGREE )->getDegree ();
58
+ return $ this ->graph ->getVertices ()-> getVertexOrder (Vertices ::ORDER_DEGREE )->getDegree ();
58
59
}
59
60
60
61
/**
61
62
* get maximum degree of vertices
62
63
*
63
64
* @return int
64
65
* @throws Exception if graph is empty or directed
65
- * @uses Vertex::getFirst ()
66
+ * @uses Vertices::getVertexOrder ()
66
67
* @uses Vertex::getDegree()
67
68
*/
68
69
public function getDegreeMax ()
69
70
{
70
- return Vertex:: getFirst ( $ this ->graph ->getVertices (), Vertex ::ORDER_DEGREE , true )->getDegree ();
71
+ return $ this ->graph ->getVertices ()-> getVertexOrder (Vertices ::ORDER_DEGREE , true )->getDegree ();
71
72
}
72
73
73
74
/**
Original file line number Diff line number Diff line change @@ -29,11 +29,6 @@ public function getEdges()
29
29
// create temporary flow graph with supersource and supersink
30
30
$ graphFlow = $ this ->graph ->createGraphCloneEdgeless ();
31
31
32
- // get all vertices
33
- $ vertices = $ graphFlow ->getVertices ();
34
- // above $vertices does NOT contain supersource and supersink, because
35
- // we want to skip over them as they do not have a partition assigned
36
-
37
32
$ superSource = $ graphFlow ->createVertex ()->setLayoutAttribute ('label ' , 's* ' );
38
33
$ superSink = $ graphFlow ->createVertex ()->setLayoutAttribute ('label ' , 't* ' );
39
34
@@ -42,7 +37,10 @@ public function getEdges()
42
37
$ groupB = $ groups [1 ];
43
38
44
39
// connect supersource s* to set A and supersink t* to set B
45
- foreach ($ vertices as $ vertex ) {
40
+ foreach ($ graphFlow ->getVertices () as $ vertex ) {
41
+ // we want to skip over supersource & supersink as they do not have a partition assigned
42
+ if ($ vertex === $ superSource || $ vertex === $ superSink ) continue ;
43
+
46
44
$ group = $ vertex ->getGroup ();
47
45
48
46
// source
Original file line number Diff line number Diff line change 5
5
use Fhaculty \Graph \Algorithm \BaseGraph ;
6
6
use Fhaculty \Graph \Exception \UnexpectedValueException ;
7
7
use Fhaculty \Graph \Vertex ;
8
+ use Fhaculty \Graph \Set \Vertices ;
8
9
use Fhaculty \Graph \Graph ;
9
10
10
11
/**
@@ -32,11 +33,11 @@ public function getVertices()
32
33
// TODO: find alternative to recursive algorithm to avoid hitting recursion limit with ~100 nodes
33
34
// TODO: avoid having to reverse all vertices multiple times
34
35
35
- foreach (array_reverse ($ this ->graph ->getVertices ()) as $ vertex ) {
36
+ foreach (array_reverse ($ this ->graph ->getVertices ()-> getVector () ) as $ vertex ) {
36
37
$ this ->visit ($ vertex , $ visited , $ tsl );
37
38
}
38
39
39
- return array_reverse ($ tsl , true );
40
+ return new Vertices ( array_reverse ($ tsl , true ) );
40
41
}
41
42
42
43
protected function visit (Vertex $ vertex , array &$ visited , array &$ tsl )
Original file line number Diff line number Diff line change 6
6
use Fhaculty \Graph \Edge \Base as Edge ;
7
7
use Fhaculty \Graph \Algorithm \ShortestPath \BreadthFirst ;
8
8
use Fhaculty \Graph \Loader \CompleteGraph ;
9
+ use Fhaculty \Graph \Set \Vertices ;
9
10
10
11
class BreadthFirstTest extends PHPUnit_Framework_TestCase
11
12
{
@@ -24,7 +25,7 @@ public function testOne()
24
25
$ edge ->destroy ();
25
26
}
26
27
27
- $ start = Vertex:: getFirst ( $ graph, Vertex ::ORDER_RANDOM );
28
+ $ start = $ graph-> getVertices ()-> getVertexOrder (Vertices ::ORDER_RANDOM );
28
29
$ start ->setLayoutAttribute ('shape ' , 'doublecircle ' );
29
30
30
31
// actually start breadth search
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ public function testGraphEmpty()
13
13
14
14
$ alg = new TopologicalSort ($ graph );
15
15
16
- $ this ->assertSame (array (), $ alg ->getVertices ());
16
+ $ this ->assertInstanceOf ('Fhaculty\Graph\Set\Vertices ' , $ alg ->getVertices ());
17
+ $ this ->assertTrue ($ alg ->getVertices ()->isEmpty ());
17
18
}
18
19
19
20
public function testGraphIsolated ()
@@ -24,7 +25,7 @@ public function testGraphIsolated()
24
25
25
26
$ alg = new TopologicalSort ($ graph );
26
27
27
- $ this ->assertSame (array (1 => $ graph ->getVertex (1 ), 2 => $ graph ->getVertex (2 )), $ alg ->getVertices ());
28
+ $ this ->assertSame (array ($ graph ->getVertex (1 ), $ graph ->getVertex (2 )), $ alg ->getVertices ()-> getVector ());
28
29
}
29
30
30
31
public function testGraphSimple ()
@@ -34,7 +35,7 @@ public function testGraphSimple()
34
35
35
36
$ alg = new TopologicalSort ($ graph );
36
37
37
- $ this ->assertSame (array (1 => $ graph ->getVertex (1 ), 2 => $ graph ->getVertex (2 )), $ alg ->getVertices ());
38
+ $ this ->assertSame (array ($ graph ->getVertex (1 ), $ graph ->getVertex (2 )), $ alg ->getVertices ()-> getVector ());
38
39
}
39
40
40
41
/**
You can’t perform that action at this time.
0 commit comments