如何在海龟和补丁之间创建链接?

问题描述 投票:0回答:1

我有以下代码,它为海龟提供了补丁的属性。有谁知道如何在海龟及其拥有的补丁之间创建链接?

或者,更好的是,创建一条线来包围属于海龟的斑块?

我尝试了以下代码,但它给出了错误,因为

CREATE-LINKS-WITH expected input to be a turtle agentset but got the agentset (agentset, 25 patches) instead.
似乎不允许使用带有补丁的链接。有什么想法吗?

patches-own [
  state 
  patch-owner  
]

turtles-own [
 property 
]

to setup
  clear-all
  create-turtles 10 [
    move-to one-of patches with [not any? turtles-here]
  ]
  setup-patches
  set-ownership
end

to setup-patches
  ask patches [
    let closest-turtle min-one-of turtles [distance myself]
    set patch-owner closest-turtle
  ]
end

to set-ownership
  ask turtles [
    let my-patches patches with [patch-owner = myself]
     create-links-with my-patches
    ]
  ]
end
netlogo agent-based-modeling
1个回答
2
投票

您是正确的,无法创建从海龟到补丁或补丁到补丁的链接。然而,做同样事情的典型方法是将一只乌龟放在补丁上并链接到该乌龟。为了避免混淆,最好将这些“补丁海龟”变成不同的品种。所以,你可能会做类似的事情

breed [locations location]

    to set-ownership
      ask turtles [
        let my-patches patches with [patch-owner = myself]
        ask my-patches [
          sprout-locations 1
        ]
        create-links-with locations with [member patch-here my-patches]
        ]
      ]

如果您愿意,您可以使海龟的位置不可见,或者某种形状或颜色。

概述补丁并不简单 - 请参阅此处: NetLogo 中的补丁大纲 简单地给补丁上色会有帮助吗?

© www.soinside.com 2019 - 2024. All rights reserved.