用随机算法优化八皇后问题,动态剪枝提升求解速度
Solving N-Queen Problem using Las Vegas Algorithm with State Pruning
- 在随机放置棋子时动态排除无效位置,缩小搜索空间
- 相比传统回溯法,N增大时仍能更快生成有效解
- 适合对速度要求高、资源有限的场景使用
N皇后问题是在N×N棋盘上放置所有N个皇后,使它们互不攻击的经典约束满足问题。尽管回溯法等完备方法能保证求解,但其指数级时间复杂度使其难以处理大规模实例,因此常采用拉斯维加斯类随机算法。然而,这类方法因随机放置导致性能波动大。本文提出一种基于标准拉斯维加斯框架的混合算法,通过迭代剪枝机制,在随机分配阶段动态消除非法位置,显著压缩搜索空间。分析表明,传统回溯法随N增大而严重恶化;相比之下,所提方法在保持解质量的同时更快速生成有效解,是追求单次及时解而非完备性的优选方案。虽在大N下存在轻微性能波动,但该算法在计算成本与解准确率间实现了高效权衡,特别适用于资源受限环境。
原文摘要 · Abstract (English)
The N-Queens problem, placing all N queens in a N x N chessboard where none attack the other, is a classic problem for constraint satisfaction algorithms. While complete methods like backtracking guarantee a solution, their exponential time complexity makes them impractical for large-scale instances thus, stochastic approaches, such as Las Vegas algorithm, are preferred. While it offers faster approximate solutions, it suffers from significant performance variance due to random placement of queens on the board. This research introduces a hybrid algorithm built on top of the standard Las Vegas framework through iterative pruning, dynamically eliminating invalid placements during the random assignment phase, thus this method effectively reduces the search space. The analysis results that traditional backtracking scales poorly with increasing N. In contrast, the proposed technique consistently generates valid solutions more rapidly, establishing it as a superior alternative to use where a single, timely solution is preferred over completeness. Although large N causes some performance variability, the algorithm demonstrates a highly effective trade-off between computational cost and solution fidelity, making it particularly suited for resource-constrained computing environments.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。