如何在NetLogo中转换每个项目都是从1到31的数字的列表? [英] How to transform a list where each item is a number from 1 to 31 in NetLogo?
本文介绍了如何在NetLogo中转换每个项目都是从1到31的数字的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在转换下面代码中的列表时遇到问题...
问题:我有一个名为:
的列表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]]
我有一个海龟配置文件-栖息地变量,它显示为ValidHabs列表中的一项,例如:
[1]
[2]
[3]
[4]
[5]
[1 2] and so on
我需要将海龟配置文件-栖息地转换为从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]
我需要转换一个列表,以便在代码的另一部分中使用此信息。我试图创建一个List(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
这篇关于如何在NetLogo中转换每个项目都是从1到31的数字的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文