【问题标题】:Put agents on a patch with the same variable value as the agents'将代理放在与代理的变量值相同的补丁上
【发布时间】:2019-10-02 17:00:40
【问题描述】:

我正在将我的代理从 .csv 文件加载到带有 csv 扩展名的 NetLogo 中。这些代理将其居住地的邮政编码作为其属性之一。 补丁也作为邮政编码的属性,在 GIS 扩展的帮助下从 shapefile 加载。 我想要实现的是将代理直接放入具有匹配邮政编码的补丁之一中。

目前的工作是,代理一直在行走,直到它们位于正确的补丁中。

这里是简化版:

turtles-own [ turtle-location ]
patches-own [ location ]

to setup
 ca
 crt 10 [
  set turtle-location random 10
 ]  
ask patches [
 set location random 10 
]
end

to go
 ask turtles [
  location-turtles 
 ]
end

to location-turtles
 if (location != turtle-location)
  [ fd 2 ]
end

但是,这实际上并不可行,我希望找到一种解决方案,将代理直接放在正确的位置。也许有新芽/孵化?

我想过这样的事情(不工作的例子):

ask turtles [
 move-to one-of patches with [ location = turtle-location ]  
]

但是这段代码给了我错误信息:

您不能在补丁上下文中使用 TURTLE-LOCATION,因为 TURTLE-LOCATION 仅适用于海龟。

【问题讨论】:

  • 最后一段代码有什么问题?您是否遇到错误,或者他们没有移动,或者...
  • 使用最后一段代码(移动到部分)我收到错误消息:您不能在补丁上下文中使用 TURTLE-LOCATION,因为 TURTLE-LOCATION 是仅海龟(我在文本中添加了这个)。

标签: attributes location netlogo patch agent


【解决方案1】:

试试这个:

ask turtles [
 move-to one-of patches with [ location = [turtle-location] of myself ]  
]

您需要让 NetLogo 知道从哪个海龟获取海龟位置。

【讨论】:

    猜你喜欢
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多