Skip to content

Commit afbd6c0

Browse files
committed
Replace all occurances of $graph->getNumberOfVertices()
replaced with count($graph->getVertices())
1 parent ea2516d commit afbd6c0

File tree

12 files changed

+14
-16
lines changed

12 files changed

+14
-16
lines changed

src/ConnectedComponents.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ private function createSearch(Vertex $vertex)
6565
* connected here.
6666
*
6767
* @return boolean
68-
* @uses AlgorithmSearchBreadthFirst::getNumberOfVertices()
6968
* @see self::getNumberOfComponents()
7069
*/
7170
public function isSingle()
@@ -79,7 +78,7 @@ public function isSingle()
7978
}
8079
$alg = $this->createSearch($vertex);
8180

82-
return ($this->graph->getNumberOfVertices() === $alg->getNumberOfVertices());
81+
return (count($this->graph->getVertices()) === count($alg->getVertices()));
8382
}
8483

8584
/**

src/MinimumCostFlow/SuccessiveShortestPath.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,12 @@ public function createGraph()
124124
* @param Graph $graph
125125
* @return boolean
126126
* @throws Exception if given graph is not a clone of the original graph (each vertex has to be present in both graphs)
127-
* @uses Graph::getNumberOfVertices()
128127
* @uses Graph::getBalanace()
129128
* @uses Graph::getVertex()
130129
*/
131130
private function isBalanceReached(Graph $graph)
132131
{
133-
if ($graph->getNumberOfVertices() !== $this->graph->getNumberOfVertices()) {
132+
if (count($graph->getVertices()) !== count($this->graph->getVertices())) {
134133
throw new DomainException('Given graph does not appear to be a clone of input graph');
135134
}
136135
foreach ($this->graph->getVertices()->getMap() as $vid => $vertex) {

src/MinimumSpanningTree/Kruskal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function getEdges()
125125

126126
// definition of spanning tree: number of edges = number of vertices - 1
127127
// above algorithm does not check isolated edges or may otherwise return multiple connected components => force check
128-
if (count($returnEdges) !== ($this->graph->getNumberOfVertices() - 1)) {
128+
if (count($returnEdges) !== (count($this->graph->getVertices()) - 1)) {
129129
throw new UnexpectedValueException('Graph is not connected');
130130
}
131131

src/MinimumSpanningTree/Prim.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getEdges()
3535
$returnEdges = array();
3636

3737
// iterate n-1 times (per definition, resulting MST MUST have n-1 edges)
38-
for ($i = 0, $n = $this->startVertex->getGraph()->getNumberOfVertices() - 1; $i < $n; ++$i) {
38+
for ($i = 0, $n = count($this->startVertex->getGraph()->getVertices()) - 1; $i < $n; ++$i) {
3939
$markInserted[$vertexCurrent->getId()] = true;
4040

4141
// get unvisited vertex of the edge and add edges from new vertex

src/Property/GraphProperty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public function isNull()
4646
*/
4747
public function isTrivial()
4848
{
49-
return ($this->graph->getEdges()->isEmpty() && $this->graph->getNumberOfVertices() === 1);
49+
return ($this->graph->getEdges()->isEmpty() && count($this->graph->getVertices()) === 1);
5050
}
5151
}

src/ShortestPath/Dijkstra.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getEdges()
4646
$isFirst = true;
4747

4848
// Repeat until all vertices have been marked
49-
$totalCountOfVertices = $this->vertex->getGraph()->getNumberOfVertices();
49+
$totalCountOfVertices = count($this->vertex->getGraph()->getVertices());
5050
for ($i = 0; $i < $totalCountOfVertices; ++$i) {
5151
$currentVertex = NULL;
5252
$currentVertexId = NULL;

src/ShortestPath/MooreBellmanFord.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function getEdges()
7979
// the usal algorithm says we repeat (n-1) times.
8080
// but because we also want to check for loop edges on the start vertex,
8181
// we have to add an additional step:
82-
$numSteps = $this->vertex->getGraph()->getNumberOfVertices();
82+
$numSteps = count($this->vertex->getGraph()->getVertices());
8383
$edges = $this->vertex->getGraph()->getEdges();
8484
$changed = true;
8585

src/TravelingSalesmanProblem/Bruteforce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected function getGraph()
108108
*/
109109
public function getEdges()
110110
{
111-
$this->numEdges = $this->graph->getNumberOfVertices();
111+
$this->numEdges = count($this->graph->getVertices());
112112
if ($this->numEdges < 3) {
113113
throw new UnderflowException('Needs at least 3 vertices');
114114
}

src/TravelingSalesmanProblem/NearestNeighbor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getEdges()
4040
{
4141
$returnEdges = array();
4242

43-
$n = $this->vertex->getGraph()->getNumberOfVertices();
43+
$n = count($this->vertex->getGraph()->getVertices());
4444

4545
$vertex = $this->vertex;
4646
$visitedVertices = array($vertex->getId() => true);

src/Tree/BaseDirected.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function isTree()
9696
}
9797

9898
// check number of vertices reachable from root should match total number of vertices
99-
return ($num === $this->graph->getNumberOfVertices());
99+
return ($num === count($this->graph->getVertices()));
100100
}
101101

102102
/**

0 commit comments

Comments
 (0)