如何使用NetLogo 6.2为每种配置文件类型均匀分布海龟? [英] How to make an equal distribution of turtles for each profile type using NetLogo 6.2?
本文介绍了如何使用NetLogo 6.2为每种配置文件类型均匀分布海龟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何解决以下问题:
我有9个海龟配置文件,它们是:
配置文件1:M1R1 配置文件2:M1R2 配置文件3:M1R3 配置文件4:M2R1 配置文件5:M2R2 配置文件6:M2R3 配置文件7:M3R1 配置文件8:M3R2 配置文件9:M3R3M=新陈代谢,R=生殖。
我希望世界上每个人都有一个准确的海龟出生数量。例如:
简介1:2只乌龟 简介2:2只乌龟 简介3:2只乌龟 简介4:2只乌龟 简介5:2只乌龟 简介6:2乌龟 简介7:2只乌龟 简介8:2只乌龟 配置文件9:2只乌龟
结果是,我只是在配置文件之间使用变量编号。我可以为每个剖面分发海龟繁殖的准确数量吗?如果是,有没有人能提出一些解决方案?嗯,我想解决这个问题已经很久了!:)
提前谢谢
globals [ AvailablePatch ]
turtles-own [ metabolism reproduction code-metabolism code-reproduction all-code ]
patches-own [ turtle-count ]
to setup
clear-all
let list1 ( list 2 4 8 )
let list2 ( list 5 10 15 )
let n 2 ;; 20 meters away each turtle will be from another turtle
set AvailablePatch patches with [ ( pxcor mod ( n + 1 ) = 0 ) and ( pycor mod ( n + 1 ) = 0 ) ]
ask AvailablePatch
[
sprout 1
[
set metabolism item 0 ( n-of 1 list1 )
set reproduction item 0 ( n-of 1 list2 )
setup-turtles who
]
set turtle-count ( turtle-count + 1 )
]
end
to setup-turtles [ whichTurtle? ]
ask turtle who [
(
ifelse
metabolism = 2 [
set code-metabolism "M1"
(
ifelse
reproduction = 5 [
set code-reproduction "R1"
]
reproduction = 10 [
set code-reproduction "R2"
]
reproduction = 15 [
set code-reproduction "R3"
]
)
]
metabolism = 4 [
set code-metabolism "M2"
(
ifelse
reproduction = 5 [
set code-reproduction "R1"
]
reproduction = 10 [
set code-reproduction "R2"
]
reproduction = 15 [
set code-reproduction "R3"
]
)
]
metabolism = 8 [
set code-metabolism "M3"
(
ifelse
reproduction = 5 [
set code-reproduction "R1"
]
reproduction = 10 [
set code-reproduction "R2"
]
reproduction = 15 [
set code-reproduction "R3"
]
)
]
)
set all-code ( word code-metabolism code-reproduction )
]
end
推荐答案
您可以做的是:
- 使用2个
foreach
循环。这样,您就可以获得列表标题的所有组合:
let list1 ( list 2 4 8 )
let list2 ( list 5 10 15 )
foreach list1
[
this_metabolism ->
foreach list2
[
this_reproduction ->
show word this_metabolism this_reproduction
;... other procedures
]
]
- 现在您希望为每种组合创建一只海龟(或更多),但仅限于
AvailablePatch
:
ask one-of AvailablePatch
[
sprout 1
[
set metabolism this_metabolism
set reproduction this_reproduction
setup-turtle
]
set turtle-count turtles-here
set AvailablePatch other AvailablePatch ;this patch is no longer available
]
如果您希望每个组合有多个海龟,请使用ask one-of AvailablePatch
,而不是使用例如ask n-of 3 AvailablePatch
。
我对您的代码做了更多更改:
- 有一位记者,报道了一个包含补丁上所有海龟的代理集
set turtle-count count turtles-here
。您甚至不需要在那里更新它,只需在需要时调用count turtles-here
而不是turtle-count
。这样,您就不必在每次创建新的海龟或某些海龟死亡时都增加和减少海龟的数量。 - 内部
sprout
它已经是海龟代码了。这意味着您不必使用海龟的who
编号来调用该过程,但您可以像在ask turtle [...]
块中一样编写代码。 setup-turtles
中的ifelse
大小写是独立的,可以简化。
完整代码:
globals [ AvailablePatch ]
turtles-own [ metabolism reproduction code-metabolism code-reproduction all-code ]
patches-own [ turtle-count ]
to setup
clear-all
let list1 ( list 2 4 8 )
let list2 ( list 5 10 15 )
let n 2 ;; 20 meters away each turtle will be from another turtle
set AvailablePatch patches with [ ( pxcor mod ( n + 1 ) = 0 ) and ( pycor mod ( n + 1 ) = 0 ) ]
(
foreach list1
[
this_metabolism ->
foreach list2
[
this_reproduction ->
ask one-of AvailablePatch
[
sprout 1
[
set metabolism this_metabolism
set reproduction this_reproduction
setup-turtle
]
set turtle-count count turtles-here
set AvailablePatch other AvailablePatch
]
]
]
)
end
to setup-turtle ;turtle procedure
(
ifelse
metabolism = 2 [set code-metabolism "M1"]
metabolism = 4 [set code-metabolism "M2"]
metabolism = 8 [set code-metabolism "M3"]
)
(
ifelse
reproduction = 5 [set code-reproduction "R1"]
reproduction = 10 [set code-reproduction "R2"]
reproduction = 15 [set code-reproduction "R3"]
)
set all-code ( word code-metabolism code-reproduction )
set color reproduction
set pcolor metabolism
end
这篇关于如何使用NetLogo 6.2为每种配置文件类型均匀分布海龟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文