Skip to content

Commit 1fbfa9a

Browse files
committed
Fix checking hamiltonian property in cycles
1 parent 6809d9c commit 1fbfa9a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Property/WalkProperty.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ public function isSimple()
152152
*/
153153
public function isHamiltonian()
154154
{
155-
return $this->isArrayContentsEqual($this->walk->getVerticesSequence(), $this->walk->getGraph()->getVertices());
155+
$vertices = $this->walk->getVerticesSequence();
156+
// ignore starting vertex for cycles as it's always the same as ending vertex
157+
if ($this->isCycle()) {
158+
unset($vertices[0]);
159+
}
160+
return $this->isArrayContentsEqual($vertices, $this->walk->getGraph()->getVertices());
156161
}
157162

158163
/**

0 commit comments

Comments
 (0)