Skip to content

Commit 6a1f521

Browse files
committed
Always return Set\Edges instead of array of Edge instances
1 parent 844e149 commit 6a1f521

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

src/MinimumSpanningTree/Kruskal.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Fhaculty\Graph\Graph;
1010
use Fhaculty\Graph\Edge\Directed as EdgeDirected;
11+
use Fhaculty\Graph\Set\Edges;
1112
use \SplPriorityQueue;
1213

1314
class Kruskal extends Base
@@ -153,6 +154,6 @@ public function getEdges()
153154
throw new UnexpectedValueException('Graph is not connected');
154155
}
155156

156-
return $returnEdges;
157+
return new Edges($returnEdges);
157158
}
158159
}

src/MinimumSpanningTree/Prim.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Fhaculty\Graph\Exception\UnexpectedValueException;
66
use Fhaculty\Graph\Edge\Directed as EdgeDirected;
7+
use Fhaculty\Graph\Set\Edges;
78
use Fhaculty\Graph\Vertex;
89
use \SplPriorityQueue;
910
use \Exception;
@@ -22,7 +23,7 @@ public function __construct(Vertex $startVertex)
2223

2324
/**
2425
*
25-
* @return Edge[]
26+
* @return Edges
2627
*/
2728
public function getEdges()
2829
{
@@ -78,7 +79,7 @@ public function getEdges()
7879
}
7980
}
8081

81-
return $returnEdges;
82+
return new Edges($returnEdges);
8283
}
8384

8485
protected function getGraph()

src/ShortestPath/Base.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getWalkTo(Vertex $endVertex)
3232
*
3333
* @param Vertex $endVertex
3434
* @throws Exception
35-
* @return Edge[]
35+
* @return Edges
3636
* @uses AlgorithmSp::getEdges()
3737
* @uses AlgorithmSp::getEdgesToInternal()
3838
*/
@@ -47,7 +47,7 @@ public function getEdgesTo(Vertex $endVertex)
4747
* @param Vertex $endVertex
4848
* @param array $edges array of all input edges to operate on
4949
* @throws Exception
50-
* @return Edge[]
50+
* @return Edges
5151
* @uses AlgorithmSp::getEdges() if no edges were given
5252
*/
5353
protected function getEdgesToInternal(Vertex $endVertex, array $edges)
@@ -72,17 +72,17 @@ protected function getEdgesToInternal(Vertex $endVertex, array $edges)
7272
}
7373
}
7474

75-
return array_reverse($path);
75+
return new Edges(array_reverse($path));
7676
}
7777

7878
/**
7979
* get sum of weight of given edges
8080
*
81-
* @param Edge[] $edges
81+
* @param Edges $edges
8282
* @return float
8383
* @uses Edge::getWeight()
8484
*/
85-
private function sumEdges(array $edges)
85+
private function sumEdges(Edges $edges)
8686
{
8787
$sum = 0;
8888
foreach ($edges as $edge) {

src/ShortestPath/Dijkstra.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Fhaculty\Graph\Algorithm\ShortestPath;
44

5+
use Fhaculty\Graph\Set\Edges;
56
use Fhaculty\Graph\Exception\UnexpectedValueException;
67
use \SplPriorityQueue;
78

@@ -10,7 +11,7 @@ class Dijkstra extends Base
1011
/**
1112
* get all edges on shortest path for this vertex
1213
*
13-
* @return Edge[]
14+
* @return Edges
1415
*/
1516
public function getEdges()
1617
{

src/ShortestPath/MooreBellmanFord.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class MooreBellmanFord extends Base
1111
/**
1212
*
1313
*
14-
* @param Edge[] $edges
14+
* @param Edges $edges
1515
* @param int[] $totalCostOfCheapestPathTo
1616
* @param Vertex[] $predecessorVertexOfCheapestPathTo
1717
*
1818
* @return Vertex|NULL
1919
*/
20-
private function bigStep(array &$edges, array &$totalCostOfCheapestPathTo, array &$predecessorVertexOfCheapestPathTo)
20+
private function bigStep(Edges $edges, array &$totalCostOfCheapestPathTo, array &$predecessorVertexOfCheapestPathTo)
2121
{
2222
$changed = NULL;
2323
// check for all edges
@@ -50,7 +50,7 @@ private function bigStep(array &$edges, array &$totalCostOfCheapestPathTo, array
5050
/**
5151
* Calculate the Moore-Bellman-Ford-Algorithm and get all edges on shortest path for this vertex
5252
*
53-
* @return Edge[]
53+
* @return Edges
5454
* @throws NegativeCycleException if there is a negative cycle
5555
*/
5656
public function getEdges()

src/TravelingSalesmanProblem/Base.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Fhaculty\Graph\Cycle;
66
use Fhaculty\Graph\Vertex;
77
use Fhaculty\Graph\Edge\Base as Edge;
8+
use Fhaculty\Graph\Set\Edges;
89
use Fhaculty\Graph\Algorithm\Base as AlgorithmBase;
910

1011
abstract class Base extends AlgorithmBase
@@ -63,7 +64,7 @@ public function getWeight()
6364
/**
6465
* get array of edges connecting all vertices in a circle
6566
*
66-
* @return Edge[]
67+
* @return Edges
6768
*/
6869
abstract public function getEdges();
6970
}

src/TravelingSalesmanProblem/Bruteforce.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Fhaculty\Graph\Graph;
1010
use Fhaculty\Graph\Vertex;
11+
use Fhaculty\Graph\Set\Edges;
1112
use Fhaculty\Graph\Algorithm\TravelingSalesmanProblem\MinimumSpanningTree as AlgorithmTspMst;
1213

1314
class Bruteforce extends Base
@@ -103,7 +104,7 @@ protected function getGraph()
103104
* get resulting (first) best circle of edges connecting all vertices
104105
*
105106
* @throws Exception on error
106-
* @return Edge[]
107+
* @return Edges
107108
*/
108109
public function getEdges()
109110
{
@@ -128,7 +129,7 @@ public function getEdges()
128129
throw new UnexpectedValueException('No resulting solution for TSP found');
129130
}
130131

131-
return $result;
132+
return new Edges($result);
132133
}
133134

134135
/**

0 commit comments

Comments
 (0)