Repository navigation
Description
Student: Pruthviraj Gojare
Task: R23-T049 · 9 of 10
Repository: https://github.com/S-AI-Projects/TheAlgorithms-Python
Assigned working branch: student/e26b07f0834
Goal
Use a debugger to watch the algorithm run on a small input, and turn your observations into documentation and a test. Fix the random seed and trace one generation: population, fitness values, selection and crossover results.
Steps
- Choose a small input (from a doctest or your own) and step through with
python -m pdbor breakpoint(); record the key variables at each step. - Write work/R23-T049/TRACE.md as a table of steps and variable values.
- Turn one observation into a new doctest (e.g. an intermediate value or an edge case you discovered).
- Explain one thing that surprised you.
- Make the code change in the repository: genetic_algorithm/travelling_salesman_problem.py: a seeded doctest for one generation step based on your trace. Re-run the automated check and the repo's own tests afterwards.
- Prepare the PR: on branch R23-T049, commit the code change plus your work/R23-T049/ evidence, put your findings in the PR description and open the PR against the org fork. For a later upstream PR, create a second branch containing only the code change (no work/ folder).
Done when
☐ TRACE.md (fixed seed) records one generation: population, fitness values, chose_ts/chose_rws selections, crossing and mutate results.
☐ genetic_algorithm/travelling_salesman_problem.py gains a seeded doctest for one generation step based on the trace.
☐ Existing 39 doctests pass.
Additional task guidance
Additional curated task guidance
Item:
genetic_algorithm/travelling_salesman_problem.py (364 lines; 39 doctests)
Task type:
Trace the execution
Code change (goes into the PR):
genetic_algorithm/travelling_salesman_problem.py: a seeded doctest for one generation step based on your trace.
Automated check:
uv run pytest genetic_algorithm/travelling_salesman_problem.py
Prerequisites:
Linux/WSL2/Codespaces with uv (https://docs.astral.sh/uv/getting-started/installation/); run uv sync --group=test once – it installs the Python version CI uses (.python-version = 3.15t) and the test dependencies, about 1–2 GB
Upstream PR rules:
Follow CONTRIBUTING.md: type hints on every parameter/return, doctests for valid and erroneous input, snake_case file names, no duplicate of an existing implementation, no hand edits to DIRECTORY.md. CI (pytest with doctests, ruff) must pass – bots close PRs without tests or type hints. Keep work/ (benchmarks, notes, property tests) out of the upstream branch; put results in the PR description.
Source (pinned):
https://github.com/TheAlgorithms/Python/blob/574d100b7181956e9c8384552fd078165e4cc326/genetic_algorithm/travelling_salesman_problem.py
Change:
No change recorded
PR destination:
Preserved pilot guidance
Submission checklist
- Complete this task and its checks.
- Add the required evidence and link your pull request here.
- Select this S-AI-Projects fork as the PR base repository.
- Request instructor review.
Keep this PR focused on this task. Do not submit assignment PRs to the upstream repository.
Activity