Skip to content

Hamiltonian path finding function and associated tests#889

Open
ap4108735 wants to merge 22 commits intodigraphs:mainfrom
ap4108735:main
Open

Hamiltonian path finding function and associated tests#889
ap4108735 wants to merge 22 commits intodigraphs:mainfrom
ap4108735:main

Conversation

@ap4108735
Copy link
Copy Markdown
Contributor

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.

Comment thread gap/oper.gi
return true;
end);

InstallMethod(TestHamiltonianPath, "for a digraph", [IsDigraph],
Copy link
Copy Markdown
Member

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:

Suggested change
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.

Comment thread gap/oper.gi
P := HamiltonianPath(D);

if P = fail then
Print("HamiltonianPath returned fail.\n");
Copy link
Copy Markdown
Member

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

Comment thread gap/oper.gi

# 2. Check if path has no repeated vertices
if not IsDuplicateFreeList(P) then
Print("FAIL: Path repeats vertices.\n");
Copy link
Copy Markdown
Member

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

Comment thread gap/oper.gi

# 3. Check if path length equals number of vertices
if Length(P) <> DigraphNrVertices(D) then
Print("FAIL: Path length is ", Length(P),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And again

Comment thread gap/oper.gi
return false;
fi;

Print("SUCCESS: Path is a valid Hamiltonian path.\n");
Copy link
Copy Markdown
Member

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.

Comment thread configure~
Copy link
Copy Markdown
Member

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.

Comment thread digraph.dot
Copy link
Copy Markdown
Member

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.

Comment thread k4.dot
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Comment thread my_digraph.dot
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Comment thread preset.dot
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Comment thread gap/attr.gi
# trivial cases
if v <= 1 then
return DigraphVertices(D);
elif v < 256 then
Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants