File tree Expand file tree Collapse file tree 11 files changed +32
-21
lines changed Expand file tree Collapse file tree 11 files changed +32
-21
lines changed Original file line number Diff line number Diff line change 17
17
use Fhaculty \Graph \Graph ;
18
18
use Fhaculty \Graph \Vertex ;
19
19
use Fhaculty \Graph \Edge \Base as Edge ;
20
+ use Fhaculty \Graph \Set \Edges ;
20
21
use Fhaculty \Graph \Algorithm \Base ;
21
22
use Fhaculty \Graph \Algorithm \ResidualGraph ;
22
23
use Fhaculty \Graph \Exception ;
@@ -86,7 +87,7 @@ public function createGraph()
86
87
// If path exists add the new flow to graph
87
88
if ($ pathFlow ) {
88
89
// 2. get max flow from path
89
- $ maxFlowValue = Edge:: getFirst ( $ pathFlow ->getEdges (), Edge ::ORDER_CAPACITY )->getCapacity ();
90
+ $ maxFlowValue = $ pathFlow ->getEdges ()-> getEdgeOrder (Edges ::ORDER_CAPACITY )->getCapacity ();
90
91
91
92
// 3. add flow to path
92
93
foreach ($ pathFlow ->getEdges () as $ edge ) {
Original file line number Diff line number Diff line change 5
5
use Fhaculty \Graph \Algorithm \BaseGraph ;
6
6
use Fhaculty \Graph \Graph ;
7
7
use Fhaculty \Graph \Edge \Base as Edge ;
8
+ use Fhaculty \Graph \Set \Edges ;
8
9
9
10
abstract class Base extends BaseGraph
10
11
{
@@ -35,7 +36,7 @@ public function createGraph()
35
36
/**
36
37
* create new resulting graph with minimum-cost flow on edges
37
38
*
38
- * @return Edge[]
39
+ * @return Edges
39
40
*/
40
41
abstract public function getEdges ();
41
42
}
Original file line number Diff line number Diff line change 6
6
use Fhaculty \Graph \Algorithm \Weight as AlgorithmWeight ;
7
7
use Fhaculty \Graph \Exception \UnderflowException ;
8
8
use Fhaculty \Graph \Edge \Base as Edge ;
9
+ use Fhaculty \Graph \Set \Edges ;
9
10
use Fhaculty \Graph \Exception \UnexpectedValueException ;
10
11
use Fhaculty \Graph \Graph ;
11
12
@@ -32,14 +33,14 @@ protected function checkBalance()
32
33
* helper used to add $newFlow to original edges of $clonedEdges in graph $resultGraph
33
34
*
34
35
* @param Graph $resultGraph graph to look for original edges
35
- * @param Edge[] $clonedEdges array of cloned edges to be modified
36
+ * @param Edges $clonedEdges set of cloned edges to be modified
36
37
* @param number $newFlow flow to add
37
38
* @uses Graph::getEdgeClone()
38
39
* @uses Graph::getEdgeCloneInverted()
39
40
* @uses Edge::getFlow()
40
41
* @uses Edge::setFlow()
41
42
*/
42
- protected function addFlow (Graph $ resultGraph , $ clonedEdges , $ newFlow )
43
+ protected function addFlow (Graph $ resultGraph , Edges $ clonedEdges , $ newFlow )
43
44
{
44
45
foreach ($ clonedEdges as $ clonedEdge ) {
45
46
try {
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fhaculty \Graph \Algorithm \MinimumCostFlow ;
4
4
5
+
5
6
use Fhaculty \Graph \Exception \UnexpectedValueException ;
6
7
7
8
use Fhaculty \Graph \Exception \UnderflowException ;
8
9
9
10
use Fhaculty \Graph \Edge \Base as Edge ;
11
+ use Fhaculty \Graph \Set \Edges ;
10
12
use Fhaculty \Graph \Algorithm \MaxFlow \EdmondsKarp as MaxFlowEdmondsKarp ;
11
13
use Fhaculty \Graph \Algorithm \DetectNegativeCycle ;
12
14
use Fhaculty \Graph \Algorithm \ResidualGraph ;
@@ -66,7 +68,7 @@ public function createGraph()
66
68
}
67
69
68
70
// calculate maximal possible flow = minimum capacity remaining for all edges
69
- $ newFlow = Edge:: getFirst ( $ clonedEdges, Edge ::ORDER_CAPACITY_REMAINING )->getCapacityRemaining ();
71
+ $ newFlow = $ clonedEdges-> getEdgeOrder (Edges ::ORDER_CAPACITY_REMAINING )->getCapacityRemaining ();
70
72
71
73
// set flow on original graph
72
74
$ this ->addFlow ($ resultGraph , $ clonedEdges , $ newFlow );
Original file line number Diff line number Diff line change 12
12
use Fhaculty \Graph \Vertex ;
13
13
use Fhaculty \Graph \Edge \Base as Edge ;
14
14
use Fhaculty \Graph \Edge \Directed as EdgeDirected ;
15
+ use Fhaculty \Graph \Set \Edges ;
15
16
use Fhaculty \Graph \Algorithm \ShortestPath \MooreBellmanFord as SpMooreBellmanFord ;
16
17
use Fhaculty \Graph \Algorithm \ResidualGraph ;
17
18
use Fhaculty \Graph \Algorithm \Search \BreadthFirst as SearchBreadthFirst ;
@@ -98,7 +99,7 @@ public function createGraph()
98
99
}
99
100
100
101
// get minimum of capacity remaining on path
101
- $ minCapacity = Edge:: getFirst ( $ edgesOnFlow, Edge ::ORDER_CAPACITY_REMAINING )->getCapacityRemaining ();
102
+ $ minCapacity = $ edgesOnFlow-> getEdgeOrder (Edges ::ORDER_CAPACITY_REMAINING )->getCapacityRemaining ();
102
103
if ($ minCapacity < $ newflow ) {
103
104
$ newflow = $ minCapacity ;
104
105
}
Original file line number Diff line number Diff line change 3
3
namespace Fhaculty \Graph \Algorithm \MinimumSpanningTree ;
4
4
5
5
use Fhaculty \Graph \Algorithm \Base as AlgorithmBase ;
6
+ use Fhaculty \Graph \Set \Edges ;
6
7
7
8
abstract class Base extends AlgorithmBase
8
9
{
@@ -24,7 +25,7 @@ abstract protected function getGraph();
24
25
/**
25
26
* get all edges on minimum spanning tree
26
27
*
27
- * @return Edge[]
28
+ * @return Edges
28
29
*/
29
30
abstract public function getEdges ();
30
31
}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ protected function getGraph()
36
36
37
37
/**
38
38
*
39
- * @return Edge[]
39
+ * @return Edges
40
40
*/
41
41
public function getEdges ()
42
42
{
Original file line number Diff line number Diff line change 8
8
use Fhaculty \Graph \Exception \InvalidArgumentException ;
9
9
use Fhaculty \Graph \Vertex ;
10
10
use Fhaculty \Graph \Edge \Base as Edge ;
11
+ use Fhaculty \Graph \Set \Edges ;
11
12
use Fhaculty \Graph \Set \Vertices ;
12
13
13
14
abstract class Base extends BaseVertex
@@ -162,10 +163,10 @@ public function createGraph()
162
163
* get cheapest edges (lowest weight) for given map of vertex predecessors
163
164
*
164
165
* @param Vertex[] $predecessor
165
- * @return Edge[]
166
+ * @return Edges
166
167
* @uses Graph::getVertices()
167
168
* @uses Vertex::getEdgesTo()
168
- * @uses Edge::getFirst ()
169
+ * @uses Edges::getEdgeOrder ()
169
170
*/
170
171
protected function getEdgesCheapestPredecesor (array $ predecessor )
171
172
{
@@ -180,17 +181,17 @@ protected function getEdgesCheapestPredecesor(array $predecessor)
180
181
$ predecesVertex = $ predecessor [$ vid ];
181
182
182
183
// get cheapest edge
183
- $ edges []= Edge:: getFirst ( $ predecesVertex ->getEdgesTo ($ vertex ), Edge ::ORDER_WEIGHT );
184
+ $ edges []= $ predecesVertex ->getEdgesTo ($ vertex )-> getEdgeOrder (Edges ::ORDER_WEIGHT );
184
185
}
185
186
}
186
187
187
- return $ edges ;
188
+ return new Edges ( $ edges) ;
188
189
}
189
190
190
191
/**
191
192
* get all edges on shortest path for this vertex
192
193
*
193
- * @return Edge[]
194
+ * @return Edges
194
195
*/
195
196
abstract public function getEdges ();
196
197
}
Original file line number Diff line number Diff line change 4
4
5
5
use Fhaculty \Graph \Graph ;
6
6
use Fhaculty \Graph \Edge \Base as Edge ;
7
+ use Fhaculty \Graph \Set \Edges ;
7
8
use Fhaculty \Graph \Algorithm \MinimumSpanningTree \Kruskal as MstKruskal ;
8
9
use Fhaculty \Graph \Algorithm \Search \BreadthFirst as SearchDepthFirst ;
9
10
@@ -32,7 +33,7 @@ protected function getGraph()
32
33
33
34
/**
34
35
*
35
- * @return Edge[]
36
+ * @return Edges
36
37
*/
37
38
public function getEdges ()
38
39
{
@@ -58,16 +59,16 @@ public function getEdges()
58
59
$ startVertex = $ vertex ;
59
60
} else {
60
61
// get edge(s) to clone, multiple edges are possible (returns an array if undirected edge)
61
- $ returnEdges []= Edge:: getFirst ( $ oldVertex ->getEdgesTo ($ vertex ));
62
+ $ returnEdges []= $ oldVertex ->getEdgesTo ($ vertex )-> getEdgeFirst ( );
62
63
}
63
64
64
65
$ oldVertex = $ vertex ;
65
66
}
66
67
67
68
// connect last vertex with start vertex
68
69
// multiple edges are possible (returns an array if undirected edge)
69
- $ returnEdges []= Edge:: getFirst ( $ oldVertex ->getEdgesTo ($ startVertex ));
70
+ $ returnEdges []= $ oldVertex ->getEdgesTo ($ startVertex )-> getEdgeFirst ( );
70
71
71
- return $ returnEdges ;
72
+ return new Edges ( $ returnEdges) ;
72
73
}
73
74
}
Original file line number Diff line number Diff line change 6
6
7
7
use Fhaculty \Graph \Vertex ;
8
8
use Fhaculty \Graph \Edge \Base as Edge ;
9
+ use Fhaculty \Graph \Set \Edges ;
9
10
use \SplPriorityQueue ;
10
11
11
12
class NearestNeighbor extends Base
@@ -33,7 +34,7 @@ protected function getGraph()
33
34
34
35
/**
35
36
*
36
- * @return Edge[]
37
+ * @return Edges
37
38
*/
38
39
public function getEdges ()
39
40
{
@@ -85,8 +86,8 @@ public function getEdges()
85
86
// check if there is a way from end edge to start edge
86
87
// get first connecting edge
87
88
// connect the last vertex with the start vertex
88
- $ returnEdges []= Edge:: getFirst ( $ vertex ->getEdgesTo ($ this ->vertex ));
89
+ $ returnEdges []= $ vertex ->getEdgesTo ($ this ->vertex )-> getEdgeFirst ( );
89
90
90
- return $ returnEdges ;
91
+ return new Edges ( $ returnEdges) ;
91
92
}
92
93
}
You can’t perform that action at this time.
0 commit comments