假设有一个网格,包含两个墙(被阻塞的单元)以及放置在网格上任何位置的食物。

现在,假设我们试图确定在这个网格上放置蚁群的最佳位置,这样蚂蚁必须以最小的距离(向任何方向到达/从蚁群的起点)获得最大的食物量。
到目前为止,我想出的最佳方法如下:
for each square on the grid
use a shortest path algorithm to find the distance to/from each food source from this square
sum these distances to find a number and put the number in that square
select the square with the smallest number这种做法是否可行呢?有没有更有效的解决方案?
发布于 2015-02-07 18:23:30
是的,您的算法可以工作,但您可以优化它的情况下,当食品包的数量,<<的方块数在网格中。例如:在上面的图表中。
distances = new int[ROWS][COLS];
for each food-packet on the grid
use a shortest path algorithm to find the distance to/from each square from this food-packet
accumulate the distances for each square in the 'distances' array最后,距离数组将包含蚁群捕获网格上所有食物包所必须做的工作量。将蚁群放在最小值的广场上。
但是请注意,这种方法的渐近复杂性仍然与您在问题中给出的算法相同。
在评论中,taoufiq给出了对算法的另一个明显的优化。即。到目前为止,停止计算任何超过最短距离的最短路径之和。
希望这是有用的。
发布于 2015-02-07 19:07:41
https://stackoverflow.com/questions/28379271
复制相似问题