Skip to content

Add adjacency representation generator for closed Hamiltonian tours - #13645

Open
Naman-Vasudev wants to merge 5 commits into
TheAlgorithms:masterfrom
Naman-Vasudev:genetic
Open

Naman-Vasudev wants to merge 5 commits into
TheAlgorithms:masterfrom
Naman-Vasudev:genetic

Conversation

@Naman-Vasudev

Copy link
Copy Markdown
Contributor

This pull request adds a new algorithm that converts a path (permutation form) of a closed Hamiltonian tour into an adjacency representation vector.
Each position in the resulting vector corresponds to a city (in fixed alphabetical order), and the value at that position denotes the next city in the tour.

@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Oct 21, 2025
@algorithms-keeper algorithms-keeper Bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Oct 21, 2025

@priya-sundaram-dev priya-sundaram-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @Naman-Vasudev — clear docstring, type hints and doctests, and the closed-tour wrap-around logic reads well.

One robustness suggestion: next_city_map.get(city, "-") silently yields "-" when a node in nodes never appears in path. Since a valid tour should visit every node, I'd validate set(path) == set(nodes) up front and raise a ValueError on mismatch, so malformed input fails loudly instead of producing a "-" placeholder.

This pairs with your #13647 (ordinal representation) — both are TSP tour encodings used in GA crossover. It might read more cohesively if the two docstrings cross-reference each other (or live together), so a reader sees them as a family of representations.

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

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants