Skip to content

Commit 86636bf

Browse files
committed
Fix accessing Sets of Vertices and Edges
1 parent 3554405 commit 86636bf

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

src/Degree.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function getDegreeVertex(Vertex $vertex)
175175
*/
176176
public function isVertexIsolated(Vertex $vertex)
177177
{
178-
return !$vertex->getEdges();
178+
return $vertex->getEdges()->isEmpty();
179179
}
180180

181181
/**

src/MinimumSpanningTree/Prim.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ public function getEdges()
5454
try {
5555
// Get next cheapest edge
5656
$cheapestEdge = $edgeQueue->extract();
57+
/* @var $cheapestEdge EdgeDirected */
5758
} catch (Exception $e) {
5859
return $returnEdges;
5960
throw new UnexpectedValueException('Graph has more than one component');
6061
}
6162

6263
// Check if edge is between unmarked and marked edge
6364

64-
$startVertices = $cheapestEdge->getVerticesStart();
65-
$vertexA = $startVertices[0];
65+
$vertexA = $cheapestEdge->getVerticesStart()->getVertexFirst();
6666
$vertexB = $cheapestEdge->getVertexToFrom($vertexA);
6767

6868
// Edge is between marked and unmared vertex

src/Property/GraphProperty.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class GraphProperty extends BaseGraph
1818
*/
1919
public function isEdgeless()
2020
{
21-
return !$this->graph->getEdges();
21+
return $this->graph->getEdges()->isEmpty();
2222
}
2323

2424
/**
@@ -28,6 +28,6 @@ public function isEdgeless()
2828
*/
2929
public function isTrivial()
3030
{
31-
return (!$this->graph->getEdges() && $this->graph->getNumberOfVertices() === 1);
31+
return ($this->graph->getEdges()->isEmpty() && $this->graph->getNumberOfVertices() === 1);
3232
}
3333
}

src/Property/WalkProperty.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Fhaculty\Graph\Algorithm\Property;
44

55
use Fhaculty\Graph\Walk;
6+
use Fhaculty\Graph\Set\Edges;
67
use Fhaculty\Graph\Algorithm\Base as BaseAlgorithm;
78
use Fhaculty\Graph\Algorithm\Loop as AlgorithmLoop;
89

@@ -60,8 +61,8 @@ public function __construct(Walk $walk)
6061
*/
6162
public function isCycle()
6263
{
63-
$vertices = $this->walk->getVerticesSequence();
64-
return (reset($vertices) === end($vertices) && $this->walk->getEdges());
64+
$vertices = $this->walk->getVertices()->getVector();
65+
return (reset($vertices) === end($vertices) && !$this->walk->getEdges()->isEmpty());
6566
}
6667

6768
/**
@@ -114,7 +115,7 @@ public function isCircuit()
114115
*/
115116
public function isPath()
116117
{
117-
return !$this->hasArrayDuplicates($this->walk->getEdgesSequence());
118+
return !$this->hasArrayDuplicates($this->walk->getEdges()->getVector());
118119
}
119120

120121
/**
@@ -138,7 +139,7 @@ public function isPath()
138139
*/
139140
public function hasCycle()
140141
{
141-
return $this->hasArrayDuplicates($this->walk->getVerticesSequence());
142+
return $this->hasArrayDuplicates($this->walk->getVertices()->getVector());
142143
}
143144

144145
/**
@@ -215,9 +216,9 @@ public function isDigon()
215216
// exactly 2 edges
216217
return ($this->walk->getNumberOfEdges() === 2 &&
217218
// no duplicate edges
218-
!$this->hasArrayDuplicates($this->walk->getEdgesSequence()) &&
219+
!$this->hasArrayDuplicates($this->walk->getEdges()->getVector()) &&
219220
// exactly two distinct vertices
220-
count($this->walk->getVertices()) === 2 &&
221+
count($this->walk->getVertices()->getVerticesDistinct()) === 2 &&
221222
// this is actually a cycle
222223
$this->isCycle());
223224
}
@@ -239,7 +240,7 @@ public function isTriangle()
239240
// exactly 3 (implicitly distinct) edges
240241
return ($this->walk->getNumberOfEdges() === 3 &&
241242
// exactly three distinct vertices
242-
count($this->walk->getVertices()) === 3 &&
243+
count($this->walk->getVertices()->getVerticesDistinct()) === 3 &&
243244
// this is actually a cycle
244245
$this->isCycle());
245246
}
@@ -293,7 +294,7 @@ public function isTriangle()
293294
*/
294295
public function isSimple()
295296
{
296-
$vertices = $this->walk->getVerticesSequence();
297+
$vertices = $this->walk->getVertices()->getVector();
297298
// ignore starting vertex for cycles as it's always the same as ending vertex
298299
if ($this->isCycle()) {
299300
unset($vertices[0]);
@@ -314,12 +315,12 @@ public function isSimple()
314315
*/
315316
public function isHamiltonian()
316317
{
317-
$vertices = $this->walk->getVerticesSequence();
318+
$vertices = $this->walk->getVertices()->getVector();
318319
// ignore starting vertex for cycles as it's always the same as ending vertex
319320
if ($this->isCycle()) {
320321
unset($vertices[0]);
321322
}
322-
return $this->isArrayContentsEqual($vertices, $this->walk->getGraph()->getVertices());
323+
return $this->isArrayContentsEqual($vertices, $this->walk->getGraph()->getVertices()->getVector());
323324
}
324325

325326
/**
@@ -332,7 +333,7 @@ public function isHamiltonian()
332333
*/
333334
public function isEulerian()
334335
{
335-
return $this->isArrayContentsEqual($this->walk->getEdgesSequence(), $this->walk->getGraph()->getEdges());
336+
return $this->isArrayContentsEqual($this->walk->getEdges()->getVector(), $this->walk->getGraph()->getEdges()->getVector());
336337
}
337338

338339
/**

0 commit comments

Comments
 (0)