Skip to content

Reuse precomputed distances in TSP evaluation - #81

Open
er-s-an wants to merge 1 commit into
Optima-CityU:mainfrom
er-s-an:codex/reuse-tsp-distance-matrix
Open

Reuse precomputed distances in TSP evaluation#81
er-s-an wants to merge 1 commit into
Optima-CityU:mainfrom
er-s-an:codex/reuse-tsp-distance-matrix

Conversation

@er-s-an

@er-s-an er-s-an commented Aug 17, 2026

Copy link
Copy Markdown

What changed

  • build the neighborhood ordering directly from each precomputed distance matrix
  • calculate the completed tour cost from the same matrix
  • remove the second set of coordinate-distance calculations from evaluation

Why

GetData.generate_instances() already computes a complete distance matrix, but TSPEvaluation recomputed pairwise distances for neighborhood ordering and recomputed every tour edge from coordinates. Reusing the existing matrix removes redundant work while preserving the generated dataset and evaluator callback API.

Fixes #16.

Validation

  • python3 -m py_compile llm4ad/task/optimization/tsp_construct/evaluation.py
  • compared the new neighborhood order and tour cost with the previous coordinate-based calculations on a fixed instance
  • ran a complete small evaluation while making any call to np.linalg.norm fail; evaluation completed with a finite score, confirming that the precomputed matrix is reused throughout

Signed-off-by: er-s-an <3137612974@qq.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.

优化TSP评估中的距离计算,避免重复计算(Optimize distance calculation in TSP evaluation to avoid redundant computations)

1 participant