Skip to content

Add seeded TSP generation doctest - #113

Open
pruthvirajgojare-source wants to merge 2 commits into
S-AI-Projects:masterfrom
pruthvirajgojare-source:R23-T049
Open

pruthvirajgojare-source wants to merge 2 commits into
S-AI-Projects:masterfrom
pruthvirajgojare-source:R23-T049

Conversation

@pruthvirajgojare-source

@pruthvirajgojare-source pruthvirajgojare-source commented Nov 21, 2026 •

Copy link
Copy Markdown

Description

Adds a fixed-seed doctest to the travelling salesman genetic algorithm that shows one generation's intermediate values. The test makes the effects of fitness evaluation, selection, crossover, and mutation concrete and reproducible for learners.

Related Issue

No related issue identified.
Fixes: N/A (no related issue)

Type of Change

  • Bug Fix
  • New Feature
  • UI/UX Improvement
  • Performance Improvement
  • Tests
  • Documentation
  • Refactoring / Maintenance
  • CI/CD

Changes Made

  • Added a seeded doctest for one generation on four square cities with seed 23.
  • The doctest verifies the fitness values and best-so-far result, roulette-selected population, crossover output, and mutated population.
  • Added work/R23-T049/TRACE.md with the debugger trace, including both chose_ts and chose_rws selection results.

The observed roulette selection chose three copies of a lower-fitness tour and did not select the best individual in that draw; the best-so-far route is tracked separately.

Screenshots / Recordings

Not applicable; no UI changes.

Testing

  • Baseline uv run pytest genetic_algorithm/travelling_salesman_problem.py — passed, 8 pytest items; baseline direct doctests: 39 passed.
  • uv run pytest genetic_algorithm/travelling_salesman_problem.py after the source commit — passed, 8 pytest items.
  • Final uv run pytest genetic_algorithm/travelling_salesman_problem.py after the evidence commit — passed, 8 pytest items.
  • uv run python -m doctest -v genetic_algorithm/travelling_salesman_problem.py — passed, all 53 doctest examples.
  • uvx ruff check genetic_algorithm/travelling_salesman_problem.py — passed.
  • uvx ruff format --check genetic_algorithm/travelling_salesman_problem.py — passed.

Checklist

  • I have tested my changes locally.
  • I have added or updated tests, if needed.
  • I have updated documentation, if needed.
  • I have followed the project's coding guidelines.
  • I have run the relevant tests and checks.
  • I have addressed previous review feedback, if applicable. (No review feedback received yet.)

Additional Notes

The task branch contains the algorithm doctest and requested trace evidence. A separate local upstream/R23-T049 branch contains only the code change; no upstream PR was opened.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant