继如何提高我的最低成本路径模型的仿真速度,我试图找到一种方法来加速在较大空间范围内运行的最低成本路径模型.我的景观面积为100km²(1000个斑块x 1000个斑块,其中1个斑块= 1像素).
Following on from How can I increase speed up simulation of my least-cost path model, I try to find a way to speed up my least-cost path model that runs at a large spatial scale. My landscape has an extent of 100km² (1000 patches x 1000 patches with 1 patch = 1 pixel).
目前,我的代码似乎可以运行,但运行速度非常慢:我的代码花了几个小时才能绘制一条成本最低的路径.问题是我的模型在100天内根据2分钟的离散时间步长演化,而我的景观中有1000头狼.对于每只狼,在每个时间步长处,我的模型都必须在存在狼的多边形(由多个补丁组成的多边形)和围绕该狼的半径3km内的所有多边形之间建立成本最低的路径.
For the moment, my code seems to work but it runs very slow: my code takes several hours to draw one least-cost path. The problem is that my model evolves according to discrete time steps of two minutes during 100 days and I have 1000 wolves in my landscape. For each wolf and at each time step, my model has to build the least-cost path between a polygon (composed of several patches) where there is a wolf and all polygons that are situated in a radius of 3km around the wolf.
我使用了NW-extension的新版本,并尝试通过保存所有已计算出的成本来优化模型,以避免重新绘制成本最低的路径.不幸的是,我的代码仍然太慢,我不知道如何加快速度.这是我的代码,用于计算一条最小成本路径的成本(如果需要,我可以向某人提供更多代码)
I used the new version of NW-extension and I tried to optimize my model by saving all costs that have already been calculated to avoid to re-draw the least-cost paths. Unfortunately, my code is yet too slow and I don't know how to speed up it. Here is my code to calculate the cost of one least-cost path (If need be, I can provide more code to someone)
to-report path-cost-between-polygons [ID-polygon-1 ID-polygon-2] let path-cost -1 ;; Define polygon edges ask patches with [ID-polygon != ID-polygon-1] [ ask neighbors with [ID-polygon = ID-polygon-1] [ ask nodes-here [ set color red ] ] ] ask patches with [ID-polygon != ID-polygon-2] [ ask neighbors with [ID-polygon = ID-polygon-2] [ ask nodes-here [ set color red ] ] ] ;; Calculate path cost foreach sort ( (nodes-on patches with [ID-polygon = ID-polygon-1]) with [color = red] ) [ let node-on-polygon-1 ? foreach sort ( (nodes-on patches with [ID-polygon = ID-polygon-2]) with [color = red] ) [ let node-on-polygon-2 ? ask node-on-polygon-1 [ let cost nw:weighted-distance-to node-on-polygon-2 "link-cost" if path-cost = -1 or cost < path-cost [ set path-cost cost ] ] ] ] ;; Save path cost between polygons set list-ID-polygons lput (list ID-polygon-1 ID-polygon-2) list-ID-polygons set list-path-costs-between-polygons lput path-cost list-path-costs-between-polygons ask nodes with [color = red] [ set color white] report path-cost end非常感谢您的帮助.
推荐答案我目前正在开发NW扩展的新版本,该版本将更快.不幸的是,对于加权路径,要等到NetLogo 5.0.6才可以使用.
I'm currently working on a new version of the NW-extension that will be much faster. Unfortunately, for weighted paths, it won't be available till NetLogo 5.0.6 comes out.
在此之前,您可以编写自己的成本最低的路径代码. A * 非常适合您的情况.实施肯定会有些棘手,但可行.如果有时间,我会把它拍下来并张贴在这里.
Until then, you could code your own least-cost path code. A* would be perfect for your situation. Implementing would definitely be somewhat tricky, but doable. If I have the time, I'll give it shot and post it here.
更多推荐
如何在大空间范围内加速最小成本路径模型
发布评论