patches-own 一个 vector in netlogo

patches-own a vector in netlogo

在开头的 patches-own 部分,我可以索引一个品种的变量,使其成为一个向量而不是单个变量吗?

具体来说,我有一个名为 Developers 的品种(它是房屋建筑的 ABM),并且 patches 拥有土地价格,但我希望他们为每个开发商拥有不同的土地价格。这可能吗?

我与 2 名开发人员的失败尝试是

patches-own [ land-price ( n-values 2 developer ) ]

谢谢。

这可以通过多种方式解决。

一个解决方案是让补丁变量成为一个列表。你不能在 patches-own 块中初始化它。相反,在您的设置方法中初始化它。

patches-own [land-prices]

to setup
    ca
    create-developers 10
    let initial-price 10
    ask patches [ set land-prices (count developers) initial-price]
end

不过您在订购时需要小心。例如,许多像 of 这样的命令会生成一个随机大小的列表。您可能需要使用开发人员的 who 来为它们编制索引。

解决这个问题的一种方法是使用 table 扩展来创建 table 谁来定价。您需要在扩展中包含 table 并修改您的设置。参见:https://ccl.northwestern.edu/netlogo/docs/table.html

考虑 table 解决方案,我在 tables 中使用 from-list 函数来初始化 table:

patches-own [land-prices]
breed [developers developer]
extensions [table]
to setup
  ca
  create-developers 10
  let initial-price 10
  ask patches [ set land-prices table:from-list [(list who initial-price)] of developers]
end

这两个都是内存密集型操作。您可能需要谨慎行事或解释为什么有必要存储如此多的信息。

@mattsap 关于使用 table 扩展名的建议可能是可行的方法,但仅作记录:您也可以考虑使用 links.

在这种情况下,问题是 link 只能在乌龟和乌龟之间,而不能在乌龟和瓦片之间。

但是,您可以考虑制作您的 "lands" 海龟,并且只在每个补丁上放一个。这是我的意思的完整示例:

breed [ lands land ]
breed [ developers developer ]
undirected-link-breed [ price-links price-link ]
price-links-own [ price ]

to setup
  clear-all
  set-default-shape lands "square"
  create-developers 10
  ask patches [
    sprout-lands 1 [
      set color green - 3
      create-price-links-with n-of 2 developers [
        hide-link
        set price random 100
      ]
    ]
  ]
end

根据您要执行的操作,可能会涉及一些权衡取舍(内存是其中之一),但从概念上讲,这是一种非常简洁的方法。

而且 NetLogo 使使用 links 变得非常容易和愉快(在我看来比使用 table 扩展要愉快得多)。主要优点是可以从两个方向查询links:

observer> ask one-of developers [ show [ price ] of my-price-links ]
(developer 6): [85 68 79 26 40 60 72 85 94 50 63 75 81 97 15 46 71 34 75 15 87 0 30 9 57 23 14 63 73 66 5 13 94 20 78 8 36 12 18 49 43 35 24 38 93 34 15 72 63 68 15 86 46 21 30 67 19 89 73 62 83 33 14 13 62 46 54 17 12 35 58 7 29 51 35 99 95 96 78 74 81 36 98 45 86 2 3 45 24 35 35 43 11 63 72 11 50 16 14 60 36 89 83 50 64 65 11 38 92 75 78 94 76 12 77 30 6 61 79 63 39 68 20 99 43 72 74 1 12 18 70 98 23 72 2 15 11 44 29 17 24 73 74 53 42 63 23 53 86 45 6 60 17 49 98 79 69 96 54 6 19 20 99 46 1 31 66 85 22 42 74 2 19 60 93 54 37 20 77 75 64 42 78 40 82 11 91 13 56 56 28 34 42 5 75 7 46 91 69 83 76 92 69 71 14 35 30 85 78 95 25 3 2 1 77 73 92 31 54 83 5 89 2 32 19 10 59 72 80 93 60 62 44 92 49 49]
observer> ask one-of lands [ show [ price ] of my-price-links ]
(land 997): [43 70]

或者您可以直接从土地上联系开发商(反之亦然):

observer> ask one-of lands [ show sort price-link-neighbors ]
(land 112): [(developer 4) (developer 5)]

显示特定开发商对特定土地的价格:

observer> ask developer 2 [ show [ price ] of price-link-with land 737 ]
(developer 2): 94

查看 Links section of the NetLogo dictionnary 了解您可以做的所有整洁的事情...