如何在 NetLogo 中转换每个项目都是从 1 到 31 的数字的列表?

How to transform a list where each item is a number from 1 to 31 in NetLogo?

我在以下代码中转换列表时遇到问题...

问题:我有一个名为的列表:

ValidHabs: [[1] [2] [3] [4] [5] [1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [2 5] [3 4] [3 5] [4 5] [1 2 3] [1 2 4] [1 2 5] [1 3 4] [1 3 5] [1 4 5] [2 3 4] [2 3 5] [2 4 5] [3 4 5] [1 2 3 4] [1 2 3 5] [1 2 4 5] [1 3 4 5] [2 3 4 5] [1 2 3 4 5]]

我有一个 turtle-profiles-habitat 变量,它显示为 ValidHabs 列表的一项,例如:

[1]
[2]
[3]
[4]
[5]
[1 2] and so on

我需要将 turtle-profiles-habitat 变成一个从 1 到 31 的数字。例如:

profile type 1 is in these habitats: [1]
profile type 2 is in these habitats: [2]
profile type 3 is in these habitats: [3]
profile type 4 is in these habitats: [4]
profile type 5 is in these habitats: [5]
profile type 6 is in these habitats: [1 2]
profile type 7 is in these habitats: [1 3]
profile type 8 is in these habitats: [1 4]
profile type 9 is in these habitats: [1 5]
profile type 10 is in these habitats: [2 3]
profile type 11 is in these habitats: [2 4]
profile type 12 is in these habitats: [2 5]
profile type 13 is in these habitats: [3 4]
profile type 14 is in these habitats: [3 5]
profile type 15 is in these habitats: [4 5]
profile type 16 is in these habitats: [1 2 3]
profile type 17 is in these habitats: [1 2 4]
profile type 18 is in these habitats: [1 2]
profile type 19 is in these habitats: [1 3 4]
profile type 20 is in these habitats: [1 3]
profile type 21 is in these habitats: [1 4]
profile type 22 is in these habitats: [2 3 4]
profile type 23 is in these habitats: [2 3]
profile type 24 is in these habitats: [2 4 5]
profile type 25 is in these habitats: [3 4 5]
profile type 26 is in these habitats: [1 2 3 4]
profile type 27 is in these habitats: [1 3 4]
profile type 28 is in these habitats: [1 2 4 5]
profile type 29 is in these habitats: [1 3]
profile type 30 is in these habitats: [2 3 4 5]
profile type 31 is in these habitats: [1 2 3 4] 

我需要转换列表以在代码的另一部分中使用此信息。我试图创建一个效果不佳的列表 (list3),这就是为什么它在代码中被注释掉的原因

谁能帮我调整我的代码?

提前致谢:)

代码如下:

globals [  ValidHabs ]  

to setup
  set ValidHabs [ [1] [2] [3] [4] [5] [1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [2 5] [3 4] [3 5] [4 5] [1 2 3] [1 2 4] [1 2 5] [1 3 4] [1 3 5] [1 4 5] [2 3 4] [2 3 5] [2 4 5] [3 4 5] [1 2 3 4] [1 2 3 5] [1 2 4 5] [1 3 4 5] [2 3 4 5] [1 2 3 4 5] ]
  print ( word "ValidHabs: " ValidHabs )
end

您可以使用position命令。根据 NetLogo Manual 它需要输入 item list 并报告项目在列表中的位置,从 0 开始。这就是为什么你必须向它添加 1。

一个例子:

globals [ValidHabs]

to go
  set ValidHabs [ [1] [2] [3] [4] [5] [1 2] [1 3] [1 4] ]
  show get-profile [1 2] ;reports 6
end

to-report get-profile [habitats]
  report (position habitats ValidHabs) + 1
end

目前还不清楚您到底想要什么或需要什么,但我首先想到的是制作一些具有属性的某种品种的隐形海龟。然后你可以做

[profile] of one-of breedx with [profile-number] = 15

或类似的东西以获得您需要的信息。您必须手动将信息添加到这些海龟中,因为您发布的列表(包含重复项)没有算法。