目前我的Pathfinding系统遇到了一些麻烦,这个系统在我的大图上“非正常”缓慢:
图的每个顶点都由以下内容定义:
最后一条规则,地球不与海洋相连(所以我们有很多子图)。
我的启发式非常经典:我计算当前顶点位置和目标位置之间的点。
我没有边缘的预计算权重。我使用“复杂”算法(取决于步行者的速度,地面的种类,如果我们上下)
float PathWorld::updateWeight(const Agent& agent, const EdgeInfo& edgeInfo) const
{
const Agent::Navigation& navigation = agent.getNavigation();
const auto& fromTerrain = edgeInfo._from->_terrain;
const auto& toTerrain = edgeInfo._to->_terrain;
const float mean = (navigation._speed.at(fromTerrain._type) + navigation._speed.at(toTerrain._type)) * 0.5f;
const float diff = BT::Maths::clamp((1000.0f + toTerrain._height - fromTerrain._height) / 1000.0f, 0.5f, 2.0f);
return edgeInfo._distance / mean * diff;
}
目前,当我计算一条路径时,执行时间不到1毫秒到1秒。路径解决方案只有8到80个顶点,我没有比例时间。 (因此,8个顶点路径可能需要1秒,80个顶点路径需要1毫秒)。
我使用visual Studio进行快速分析:提升是我的瓶颈。
所有完整的代码和测试数据都可以在我的GitHub上找到。
https://github.com/Rominitch/myBlogSource/tree/master/DEMO/TestPathfinding
简单/小型演示不会受到我的影响。只是复杂的情况。所有图表均由同一程序生成(未公布)。
我的测试程序非常虚拟: - 我从一个节点开始进入我的图形 - 我在此之后使用XXX节点(使用索引)和计算路径。
输出:
Statistics:
Start node: Ocean H= 0 SubGraph= 2
nbValid: 2053/15000 (valid path / number of path computed)
min / max: 1/75 (number of vertex in path computed)
min time for one path: 0 ms
max time for one path: 7 ms
Statistics:
Start node: Forest H= 100 SubGraph= 1
nbValid: 1420/1500
min / max: 1/76
min time for one path: 0 ms
max time for one path: 558 ms
Statistics:
Start node: Swamp H= 50 SubGraph= 1
nbValid: 601/1000
min / max: 1/51
min time for one path: 0 ms
max time for one path: 1246 ms
Statistics:
Start node: Clay H= 300 SubGraph= 22
nbValid: 138/15000
min / max: 1/12
min time for one path: 0 ms
max time for one path: 0 ms
谢谢 !
好 !我发现了我的问题。
目前,Bug在我的启发式实现中,它不计算当前节点和目标之间的距离的平方。它只是制作一个“准随机”启发式算法。
而且,就我而言
boost::astar_search
表现不如
boost::astar_search_tree
最后,我优化我的图形(删除虚边)。
新统计数据:
Statistics:
Start node: Ocean H= 0 SubGraph= 2
nbValid: 2028/15000
min / max: 1/145
min time for one path: 0 ms
max time for one path: 13 ms
mean: 0 ms
Global time: 1845 ms
Statistics:
Start node: Forest H= 100 SubGraph= 1
nbValid: 1420/1500
min / max: 1/92
min time for one path: 0 ms
max time for one path: 13 ms
mean: 0 ms
Global time: 1232 ms
Statistics:
Start node: Swamp H= 50 SubGraph= 1
nbValid: 601/1000
min / max: 1/50
min time for one path: 0 ms
max time for one path: 11 ms
mean: 0 ms
Global time: 504 ms
Statistics:
Start node: Clay H= 300 SubGraph= 23
nbValid: 138/15000
min / max: 1/17
min time for one path: 0 ms
max time for one path: 1 ms
mean: 0 ms
Global time: 115 ms