Skip to content

Combinatorial: fix GA crossover identity bug, 2-opt move, ACO-MST tail, CH retry guard - #115

Merged
fundthmcalculus merged 1 commit into
mainfrom
fix/combinatorial-correctness
Aug 23, 2026
Merged

Combinatorial: fix GA crossover identity bug, 2-opt move, ACO-MST tail, CH retry guard#115
fundthmcalculus merged 1 commit into
mainfrom
fix/combinatorial-correctness

Conversation

@fundthmcalculus

Copy link
Copy Markdown
Owner

Correctness fixes in the TSP/combinatorial solvers, from the 2026-08-23 review.

# fix severity
O1 GA crossover returned the identity permutation every time — np.unique(return_index=True) sorts by value, so child[idx] rebuilt [0..N-1], discarding both parents (GA was mutation-only). Sort the indices. high
O5 GA _2opt_refine applied an endpoint swap but d1/d2 measure a segment reversal → "improving" moves could lengthen the tour. Reverse the segment. med
O11 ACO-MST inverse-CDF argmin(new_p>cum_p) picks index 0 on tail float-overflow. Use searchsorted + clip. low
O8 ConvexHullTSP "retry once" guard restarted never set True. low

Verified

_crossover: 0/200 identity tours (was always identity), all valid perms. _2opt_refine: accepted move now shortens the tour. tests/test_combinatorics.py green (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

…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
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