Uh oh!
There was an error while loading. Please reload this page.
Hamiltonian path finding function and associated tests - #889
Conversation
| return true; | ||
| end); | ||
| InstallMethod(TestHamiltonianPath, "for a digraph", [IsDigraph], |
There was a problem hiding this comment.
This would be more consistent with elsewhere in the Digraphs package if it was:
| InstallMethod(TestHamiltonianPath, "for a digraph", [IsDigraph], | |
| InstallMethod(IsHamiltonianPath, "for a digraph", [IsDigraph, IsList], |
i.e. returns true if the 2nd argument is a hamiltonian path in the 1st argument.
| P := HamiltonianPath(D); | ||
| if P = fail then | ||
| Print("HamiltonianPath returned fail.\n"); |
There was a problem hiding this comment.
This should be an info statement
| # 2. Check if path has no repeated vertices | ||
| if not IsDuplicateFreeList(P) then | ||
| Print("FAIL: Path repeats vertices.\n"); |
There was a problem hiding this comment.
Same as above should be an info statement
| # 3. Check if path length equals number of vertices | ||
| if Length(P) <> DigraphNrVertices(D) then | ||
| Print("FAIL: Path length is ", Length(P), |
| return false; | ||
| fi; | ||
| Print("SUCCESS: Path is a valid Hamiltonian path.\n"); |
There was a problem hiding this comment.
And this should probably be removed.
There was a problem hiding this comment.
This was committed by accident and should removed.
There was a problem hiding this comment.
Remove, unless required for something, but I can't see how it could be.
| # trivial cases | ||
| if v <= 1 then | ||
| return DigraphVertices(D); | ||
| elif v < 256 then |
There was a problem hiding this comment.
Magic number, comment on reason for choice.
I have added a function to find the more general notion of a Hamiltonian path, to be used alongside the existing Hamiltonian cycle function. I have also added an associated testing function. At the moment, for large cases the function is not very efficient so I will continue to look into some possible fixes for that.