Skip to content

About

Python 数值优化与旅行商实验 / Reproducible numerical search and traveling salesman problem (TSP) experiments with genetic algorithms, fixed seeds and convergence plots.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

数值优化实验 · Optimization Notes

English

一条旅行商路线可以有多少种走法?一个二维函数的低点该往哪里找?这个项目用小规模实验观察搜索策略如何更新候选解,以及随机性如何影响结果。目的在于理解编码、适应度、选择与位置更新,而不是给算法排性能名次。

从问题到结果

旅行商实验先生成城市坐标,把访问顺序编码为排列;每代按路线长度选择父代,经交叉与变异产生新路线,并保留精英。数值实验则在指定范围内初始化候选位置,按各自规则迭代,用目标函数评价位置。统一入口固定随机种子,将结果写成 JSON,并绘制旅行商距离曲线。

代码索引

文件 做什么
optimization/genetic_tsp.py 路径编码、距离计算、选择、交叉和变异;精英路线使用独立副本。
optimization/particle_search.py 在简单二次目标上演示粒子位置与速度更新。
optimization/wolf_search.py 使用当前最佳位置引导候选位置更新,逐维处理向量。
optimization/sine_search.py 通过正弦扰动探索 Rosenbrock 函数。
optimization/beetle_search.py 用受边界约束的随机位移进行搜索。
optimization/polar_search.py 在球面函数上观察群体均值与随机扰动的影响。
optimization/demo.py 组织实验、设置种子、保存数值结果和曲线。
tests/test_optimization.py 检查路线、精英保护、返回值和目标函数的一致性。

运行一次

Python 3.12,建议在虚拟环境中执行:

python -m pip install -r requirements.txt
python -m optimization.demo --seed 42
python -m unittest discover -s tests -v

查看 results/optimization/summary.json 和 convergence.png。--output 可以指定输出目录。

这些实现是教学用简化搜索:部分方法省略了标准算法中的历史最优维护或调度机制,不能视为论文复现。不同函数上的数值也不能直接比较;程序完成迭代并不等于找到了全局最优。

About

Python 数值优化与旅行商实验 / Reproducible numerical search and traveling salesman problem (TSP) experiments with genetic algorithms, fixed seeds and convergence plots.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages