-
Notifications
You must be signed in to change notification settings - Fork 61
Hamiltonian path finding function and associated tests #889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| return true; | ||
| end); | ||
|
|
||
| InstallMethod(TestHamiltonianPath, "for a digraph", [IsDigraph], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again
| return false; | ||
| fi; | ||
|
|
||
| Print("SUCCESS: Path is a valid Hamiltonian path.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this should probably be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was committed by accident and should removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove, unless required for something, but I can't see how it could be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
| # trivial cases | ||
| if v <= 1 then | ||
| return DigraphVertices(D); | ||
| elif v < 256 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.