如何使用 NetLogo 6.2 为每种配置文件类型平均分配海龟?
How to make an equal distribution of turtles for each profile type using NetLogo 6.2?
我不知道如何解决以下问题:
我有 9 个海龟档案,它们是:
配置文件 1:M1R1
配置文件 2:M1R2
配置文件 3:M1R3
配置文件 4:M2R1
配置文件 5:M2R2
配置文件 6:M2R3
配置文件 7:M3R1
配置文件 8:M3R2
配置文件 9:M3R3
M= 新陈代谢,R = 繁殖。
我希望世界上的每个配置文件中都有确切数量的海龟出生。例如:
个人资料 1:2 只海龟
配置文件 2:2 只乌龟
配置文件 3:2 只乌龟
配置文件 4:2 只乌龟
配置文件 5:2 只乌龟
profile6: 2 只乌龟
profile7: 2 只海龟
profile8: 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 n-of 3 AvailablePatch
.
而不是 ask one-of AvailablePatch
我对你的代码做了一些修改:
- 有一个报告者报告了一个包含补丁
set turtle-count count turtles-here
上所有海龟的代理集。您甚至不必在那里更新它,只需在需要时调用 count turtles-here
而不是 turtle-count
。这样您就不必在每次创建新海龟或死亡时都添加和减去海龟。
- 在
sprout
里面它已经是“海龟代码”了。这意味着您不必使用乌龟的 who
编号调用该过程,但您可以像在 ask turtle [...]
块中一样编写代码。
setup-turtles
里面的ifelse
个case是独立的,可以简化
完整代码:
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
我不知道如何解决以下问题:
我有 9 个海龟档案,它们是:
配置文件 1:M1R1 配置文件 2:M1R2 配置文件 3:M1R3 配置文件 4:M2R1 配置文件 5:M2R2 配置文件 6:M2R3 配置文件 7:M3R1 配置文件 8:M3R2 配置文件 9:M3R3
M= 新陈代谢,R = 繁殖。
我希望世界上的每个配置文件中都有确切数量的海龟出生。例如:
个人资料 1:2 只海龟 配置文件 2:2 只乌龟 配置文件 3:2 只乌龟 配置文件 4:2 只乌龟 配置文件 5:2 只乌龟 profile6: 2 只乌龟 profile7: 2 只海龟 profile8: 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 n-of 3 AvailablePatch
.
ask one-of AvailablePatch
我对你的代码做了一些修改:
- 有一个报告者报告了一个包含补丁
set turtle-count count turtles-here
上所有海龟的代理集。您甚至不必在那里更新它,只需在需要时调用count turtles-here
而不是turtle-count
。这样您就不必在每次创建新海龟或死亡时都添加和减去海龟。 - 在
sprout
里面它已经是“海龟代码”了。这意味着您不必使用乌龟的who
编号调用该过程,但您可以像在ask turtle [...]
块中一样编写代码。 setup-turtles
里面的ifelse
个case是独立的,可以简化
完整代码:
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