Combinatorial: fix GA crossover identity bug, 2-opt move, ACO-MST tail, CH retry guard - #115
Merged
Merged
Conversation
…H retry Correctness fixes in the TSP/combinatorial solvers (autonomous review 2026-08-23). - GA crossover (ga.py): np.unique(return_index=True) returns indices sorted by value, so `child[idx]` rebuilt the tour as [0,1,..,N-1] EVERY time -- crossover discarded both parents and injected the identity tour, making the GA effectively mutation-only. Sort the indices to preserve first-occurrence order. Verified: now 0/200 identity tours, distinct valid children. - GA _2opt_refine (ga.py): the accepted move swapped only the two segment endpoints, but d1/d2 measure a full segment REVERSAL, so an "improving" test could lengthen the tour. Reverse new_route[ij+1 .. jk]. Verified: tour length now decreases on an accepted move. - ACO-MST (aco_mst.py): inverse-CDF sampling `argmin(new_p > cum_p)` returns index 0 when new_p exceeds every cumulative bin (float round-off) -> silently picks the first city-pair. Use searchsorted with a clip, like aco.py. - ConvexHullTSP (strategy.py): the "retry once" guard `restarted` was never set True, so the else/break was unreachable. Set it in the retry branch. Deferred: StepWiseOptimizer's optimize_whole_solution_deck=True branch is broken (crashes on entry) but the flag defaults False and is never set True anywhere -- a dead, unexercised path; fixing it safely needs a test of that path (separate issue). Tests: tests/test_combinatorics.py green (10). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LxgEQmoqtAj589pvbwuGo4
This was referenced Aug 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Correctness fixes in the TSP/combinatorial solvers, from the 2026-08-23 review.
np.unique(return_index=True)sorts by value, sochild[idx]rebuilt[0..N-1], discarding both parents (GA was mutation-only). Sort the indices._2opt_refineapplied an endpoint swap butd1/d2measure a segment reversal → "improving" moves could lengthen the tour. Reverse the segment.argmin(new_p>cum_p)picks index 0 on tail float-overflow. Usesearchsorted+ clip.ConvexHullTSP"retry once" guardrestartednever set True.Verified
_crossover: 0/200 identity tours (was always identity), all valid perms._2opt_refine: accepted move now shortens the tour.tests/test_combinatorics.pygreen (10). Full suite + Cython via CI.Deferred
StepWiseOptimizer.optimize_whole_solution_deck=True(O3) crashes on entry but is a dead, never-enabled branch. Separate follow-ups: O2 (thread-unsafe legacy np.random under joblib), O4/O6/O9 (determinism), O10 (early-stop window logic).🤖 Generated with Claude Code
https://claude.ai/code/session_01LxgEQmoqtAj589pvbwuGo4