Netlogo-根据曼哈顿距离查找最近的代理商 [英] Netlogo - find the closest agent based on Manhattan distance

查看:267
本文介绍了Netlogo-根据曼哈顿距离查找最近的代理商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个大型仓库操作建模(请参见下图).

I am modelling a big warehouse operations (see below pic).

我已经在每个面片(绿点)上实现了一个顶点并将其链接起来,这样我就可以计算出每个顶点到所有其他顶点的最短路径(使用dijkstra算法),并存储在每个顶点的表(字典)中.此过程在设置阶段完成,非常耗时.然后,黄色的库存单元(矩形)将发出完成任务的需求请求.

I have implemented a vertex on each patch (green dots) and link them so that I could compute the shortest path (using dijkstra algorithm) from each vertex to all other vertices, stored in a table (dictionary) of each vertex. This process is done during setup stage and is quite time-consuming. Then the yellow inventory cells (rectangle) will issue the demand request for task fulfillment.

叉车(有些在路上)假定在不忙时停留在顶点(节点)之一上.收到需求请求时,它将要求其当前的固定顶点(节点)获取要到达的库存单元的starting_node和end_node.然后,叉车要求starting_node从其表中获取最短路径,以获取最短路径(节点组合)并驶向end_node(黄色单元格).

The forklift truck (some in the path) is assuming to stay put on one of the vertex (node) when it's not busy. When get the demand request, it will ask its current standing vertex (node) to get the starting_node and the end_node of the inventory cell it is going to. Then the forklift ask the starting_node to get the shortest path from its table to get the shortest path (combination of nodes) and drive to the end_node (the yellow cell).

目前,黄色牢房只是在仓库中随机挑选免费的叉车.作为进一步的发展,我想添加一个功能,该功能允许黄色单元格根据实际距离(而不是Netlogo中内置的欧氏距离)来识别最接近它的免费卡车.由于卡车很多,因此使用"foreach"遍历所有可用卡车并使用上述方法计算实际距离不是很好.您可以使用原始的距离我自己"来快速定位卡车,但这并不准确.有没有一种更好的方法可以使用更快的计算方法来识别最近的卡车?

Currently, the yellow cells just randomly pick free forklift truck in the warehouse. As a further development, I want to add the function that allows the yellow cell to identify the free truck that is closest to it based on the actual distance (not the euclidean distance built in Netlogo). As there are many trucks so it's not good to use "foreach" to loop through all available trucks and compute the actual distance using above method. You could use primitive "distance myself" to locate the truck quickly but that's not accurate. Is there a good way to identify the closest truck with a faster computational method?

推荐答案

我不知道这是否适用于您当前的设置,但是您可能还会发现nw扩展名很有帮助.例如,尝试以下设置(我为您的长度表示歉意,只是近似于您的世界):

I don't know if this would work with your current setup, but you may also find the nw extension helpful. For example, try this setup (I apologize for the length, just approximating your world):

extensions [ nw ]

breed [ nodes node ]
breed [ trucks truck ]
breed [ cells cell ]

to setup
  ca

  resize-world -29 29 -14 14

  ask patches with [ ( pxcor mod 5 = 0 or pycor = 0 ) ] [
    set pcolor grey 
    sprout-nodes 1 [
      set size 0.5
      set shape "circle"
      set color green
    ]
  ]

  ask nodes [
    create-links-with turtles-on neighbors4 [
      set color green  
    ]
  ]

  ask n-of 5 nodes [
    hatch 1 [
      set size 1
      set color red
      set breed trucks 
      set shape "car"
    ]
  ]

  ask n-of 2 trucks [
    set color blue
  ]

  ask one-of nodes [
    ask one-of neighbors with [ pcolor = black ] [
      sprout-cells 1 [
        set size 1.5
        set shape "box"
        set color yellow
      ]
    ]
  ]
  reset-ticks
end

提供一个像这样的简单世界:

Gives a simple world like this:

您可以使用nw扩展名即时计算距离,而不必将其存储在每个单元格表中,并使叉车(此处为卡车)遵循最短路径.评论中的更多详细信息:

You can use the nw extension to calculate the distances on the fly, rather than storing them in a per-cell table, and have the forklifts (trucks, here) follow the shortest path. More details in comments:

to summon-nearest-truck 
  ; Treat blue trucks as 'empty' and ready to go to a cell
  let ready-trucks trucks with [ color = blue ]

  ; Get the nodes associated with those ready trucks
  let truck-proxies turtle-set map [ i -> [nodes-on patch-here] of i ] sort ready-trucks

  ; Randomly ask one of the cells to
  ask one-of cells [

    ; Choose one of the neighboring road nodes as a proxy for distance calculation
    let node-proxy one-of nodes-on neighbors4 

    ; Get the node proxy to:
    ask node-proxy [
      ; Find the nearest (by network distance) trucks, and select the node
      ; located on the same patch as that truck
      let my-truck-proxy min-one-of truck-proxies [length ( nw:turtles-on-path-to myself) ]

      ; Get that truck-proxy node to generate the path to the original asking node
      ; and have the appropriate truck follow that path
      ask my-truck-proxy [
        ; Generate the path to follow
        let path-to-follow nw:turtles-on-path-to myself

        ; Highlight that path for visualization
        ask turtle-set path-to-follow [
          set color orange
        ]

        ; Get the truck ready to move
        let ready-truck one-of trucks-here with [ color = blue ]
        ask ready-truck[
          set color yellow
        ]

        ; Move that truck along the path-to-follow
        ask ready-truck [
          foreach path-to-follow [
            n ->
            face n
            move-to n
            ; For visualization only
            wait 0.1
          ]
        ]
      ]
    ]
  ]
end

这有一个黄色框,它根据返回的nw:turtles-on-path-to的长​​度来召唤最近的卡车.那辆卡车沿着通往召唤节点的路径走:

This has the yellow box summon the nearest truck based on the length of nw:turtles-on-path-to that is returned. That truck follows the path to the summoning node:

这篇关于Netlogo-根据曼哈顿距离查找最近的代理商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆