C++实现的高效A*算法

时间:2020-04-28 03:46:41
【文件属性】:

文件名称:C++实现的高效A*算法

文件大小:10KB

文件格式:ZIP

更新时间:2020-04-28 03:46:41

算法

A-Star Algorithm 这是使用C++实现的高效的A-Star算法。只对算法的程序实现做了尽力而为的优化,并没有对算法自身进行改良。优化措施主要在于:快速判断路径节点是否在开启/关闭列表中、快速查找最小f值的节点以及优化路径节点频繁分配内存的问题。 运行环境 支持c++11的编译器 使用示例 char maps[10][10] = { { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 }, { 0, 0, 0, 1, 0, 1, 0, 1, 0, 1 }, { 1, 1, 1, 1, 0, 1, 0, 1, 0, 1 }, { 0, 0, 0, 1, 0, 0, 0, 1, 0, 1 }, { 0, 1, 0, 1, 1, 1, 1, 1, 0, 1 }, { 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }, { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 }, { 1, 1, 0, 0, 1, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 }, }; // 搜索参数 AStar::Params param; param.width = 10; param.height = 10; param.corner = false; param.start = AStar::Vec2(0, 0); param.end = AStar::Vec2(9, 9); param.can_pass = [&](const AStar::Vec2 &pos)->bool { return maps[pos.y][pos.x] == 0; }; // 执行搜索 BlockAllocator allocator; AStar algorithm(&allocator); auto path = algorithm.find(param); 编译代码 make build && cd build cmake ../example && make


【文件预览】:
a-star-algorithm-master
----astar()
--------a_star.cpp(8KB)
--------blockallocator.cpp(5KB)
--------blockallocator.h(2KB)
--------a_star.h(4KB)
----LICENSE(1KB)
----README.md(1KB)
----example()
--------test.cpp(1KB)
--------CMakeLists.txt(623B)

网友评论

  • 还好吧,可以用
  • 值得学习 谢谢