如何导出 NetLogo 6.2 的世界,只对出生的海龟着色?
How to export the world of NetLogo 6.2 coloring only the patches that were born turtles?
我真的不知道如何导出以下输出...
我有 16 个海龟资料,指的是栖息地覆盖类型的非重复组合(参见 ValidHabs 变量)
在模型中,它从 10 只可以繁殖或死亡的海龟开始。
我想生成一个输出,其中整个世界变成白色并仅在海龟出生的地方涂上洋红色,即开始世界的 10 只海龟,然后是通过繁殖过程出现的新海龟。而且这是通过海龟剖面得出的。我查了 NetLogo 字典,我相信我应该使用 export-view 命令
但是,我仍然无法在一个简单的代码中执行,该代码只能以图像形式导出所有刻度结束时仅存在乌龟(以洋红色绘制)的补丁(即所有有乌龟的补丁)考虑到该海龟剖面的所有刻度线。
我目前所做的如下。
非常欢迎任何形式的帮助:)
提前致谢!
globals [ ValidHabs ValidHabsItem HotPatchSet CurrentHotPatchSet PatchAvailable ListProfiles Death ]
patches-own [ habitatcover resources turtle-count ]
turtles-own [ turtle-profiles-habitat metabolism reproduction all-code code-metabolism code-reproduction energy my-patches x ]
to setup
clear-all
random-seed 1
set ValidHabs [[1] [2] [3] [4] [5] [6] [1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [2 5] [3 4] [3 5] [4 5] ]
set Death 0
set ListProfiles [ ]
setup-world
setup-patches
reset-ticks
foreach sort turtles
[
t ->
ask t
[
print ( word "I am:" " " who )
]
]
print ""
end
to setup-world
let pcolors []
set pcolors [ 25 65 23 53 105 45 ]
ask patches [
set pcolor item (random 6) pcolors
]
ask patches [
if pcolor = 25 [ set habitatcover 1 ]
if pcolor = 65 [ set habitatcover 2 ]
if pcolor = 23 [ set habitatcover 3 ]
if pcolor = 53 [ set habitatcover 4 ]
if pcolor = 105 [ set habitatcover 5 ]
if pcolor = 45 [ set habitatcover 6 ]
]
ask patches [ set resources random 100 ]
end
to setup-patches
set HotPatchSet patches with [ ( habitatcover != 6 ) ]
let list1 ( list 2 )
let list2 ( list 5 )
let n0 count turtles
set CurrentHotPatchSet HotPatchSet with [ habitatcover = one-of item ValidHabsItem ValidHabs ]
while [ n0 < ( length list1 ) * ( length list2 ) * 10 ]
[
(
foreach list1
[
this-metabolism ->
foreach list2
[
this-reproduction ->
let c count CurrentHotPatchSet
if c = 0 [ stop ]
ask one-of CurrentHotPatchSet
[
sprout 1
[
set turtle-profiles-habitat item ValidHabsItem ValidHabs
set metabolism this-metabolism
set reproduction this-reproduction
setup-turtles who
]
set CurrentHotPatchSet CurrentHotPatchSet with [ not any? turtles in-radius 2 ]
]
]
]
)
set n0 count turtles
]
end
to setup-turtles [ WhichColony? ]
set color black
set energy 0
ask turtle who [
(
ifelse
metabolism = 2 [set code-metabolism "M1"]
)
(
ifelse
reproduction = 5 [set code-reproduction "R1"]
)
set all-code ( word code-metabolism code-reproduction )
]
set x turtle-profiles-habitat
ask turtle who
[
if length x = 1
[
let a 1
while [ a < 7 ]
[
if member? a x
[
set my-patches patches with [ habitatcover = a ]
]
set a a + 1
]
]
if length x = 2
[
let a 1
while [ a < 7 ]
[
let b 1
while [ b < 7 ]
[
if a = item 0 x and b = item 1 x
[
set my-patches patches with [ habitatcover = a or habitatcover = b ]
]
set b b + 1
]
set a a + 1
]
]
]
end
to go
metabolic
print ( word "TICK: " ticks )
ask turtles [ print ( word "I am: " who ) ]
tick
let n count turtles
if n = 0 or ticks = 10 and ExportView? = true [ output ] ;; ExportView? is a switch in the interface
end
to metabolic
ask turtles
[
let z [ resources ] of patch-here
if
metabolism = 2 [
set energy ( ceiling ( z ) - 2 )
if energy <= 1.7 [ die-turtles ]
if
reproduction = 5 [
if energy >= 5 [ dispersion ]
]
]
]
end
to dispersion
let p 0
while [ p < 1 ] [
let available-patch my-patches with [ distance myself > 3 and distance myself < 5 and count turtles-here = 0 and not any? other turtles in-radius 3 ]
set PatchAvailable count available-patch
if PatchAvailable = 0 [ stop ]
let choose-patch one-of available-patch
let coordx [ pxcor ] of choose-patch
let coordy [ pycor ] of choose-patch
hatch 1 [
setxy coordx coordy
set turtle-count count turtles-here
set color white
set energy 0
set p p + 1
]
]
end
to die-turtles
foreach ListProfiles [ lp ->
set Death 0
set Death Death + 1
]
die
end
to color_patches
ask patches [ set pcolor white ]
ask turtles [
ask patch-here [ set pcolor magenta ]
]
end
to output
export-view ( word "View.png" )
end
;; in the interface go button, I put the following:
;if ExportView? = true
;[
; color_patches
;]
;go
我认为最好的跟踪方法是 patches-own
变量来跟踪乌龟是否 曾经 出生在 patch
。在这个示例代码中,我调用了 turtle-born-here
,在设置中将变量设置为 false
,然后在 turtle
为 'born' 时更新变量(无论是在设置中,或在 go
).
期间
patches-own [ turtle-born-here ]
to setup
ca
ask patches [ set turtle-born-here false ]
ask n-of 5 patches [
sprout 1
set turtle-born-here true
]
reset-ticks
end
to go
ask turtles [
rt random 60 - 30
fd 1
if random-float 1 < 0.05 [
hatch 1
ask patch-here [ set turtle-born-here true]
]
]
end
to example-export-image
setup
; Some example go runs
repeat 50 [ go ]
; This is the export-view component
cd
ask turtles [
ht
]
ask patches [
ifelse turtle-born-here
[ set pcolor magenta ]
[ set pcolor white ]
]
export-view "example_view_export.png"
end
运行 这会吐出像这样的图像:
我真的不知道如何导出以下输出...
我有 16 个海龟资料,指的是栖息地覆盖类型的非重复组合(参见 ValidHabs 变量)
在模型中,它从 10 只可以繁殖或死亡的海龟开始。
我想生成一个输出,其中整个世界变成白色并仅在海龟出生的地方涂上洋红色,即开始世界的 10 只海龟,然后是通过繁殖过程出现的新海龟。而且这是通过海龟剖面得出的。我查了 NetLogo 字典,我相信我应该使用 export-view 命令
但是,我仍然无法在一个简单的代码中执行,该代码只能以图像形式导出所有刻度结束时仅存在乌龟(以洋红色绘制)的补丁(即所有有乌龟的补丁)考虑到该海龟剖面的所有刻度线。
我目前所做的如下。
非常欢迎任何形式的帮助:)
提前致谢!
globals [ ValidHabs ValidHabsItem HotPatchSet CurrentHotPatchSet PatchAvailable ListProfiles Death ]
patches-own [ habitatcover resources turtle-count ]
turtles-own [ turtle-profiles-habitat metabolism reproduction all-code code-metabolism code-reproduction energy my-patches x ]
to setup
clear-all
random-seed 1
set ValidHabs [[1] [2] [3] [4] [5] [6] [1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [2 5] [3 4] [3 5] [4 5] ]
set Death 0
set ListProfiles [ ]
setup-world
setup-patches
reset-ticks
foreach sort turtles
[
t ->
ask t
[
print ( word "I am:" " " who )
]
]
print ""
end
to setup-world
let pcolors []
set pcolors [ 25 65 23 53 105 45 ]
ask patches [
set pcolor item (random 6) pcolors
]
ask patches [
if pcolor = 25 [ set habitatcover 1 ]
if pcolor = 65 [ set habitatcover 2 ]
if pcolor = 23 [ set habitatcover 3 ]
if pcolor = 53 [ set habitatcover 4 ]
if pcolor = 105 [ set habitatcover 5 ]
if pcolor = 45 [ set habitatcover 6 ]
]
ask patches [ set resources random 100 ]
end
to setup-patches
set HotPatchSet patches with [ ( habitatcover != 6 ) ]
let list1 ( list 2 )
let list2 ( list 5 )
let n0 count turtles
set CurrentHotPatchSet HotPatchSet with [ habitatcover = one-of item ValidHabsItem ValidHabs ]
while [ n0 < ( length list1 ) * ( length list2 ) * 10 ]
[
(
foreach list1
[
this-metabolism ->
foreach list2
[
this-reproduction ->
let c count CurrentHotPatchSet
if c = 0 [ stop ]
ask one-of CurrentHotPatchSet
[
sprout 1
[
set turtle-profiles-habitat item ValidHabsItem ValidHabs
set metabolism this-metabolism
set reproduction this-reproduction
setup-turtles who
]
set CurrentHotPatchSet CurrentHotPatchSet with [ not any? turtles in-radius 2 ]
]
]
]
)
set n0 count turtles
]
end
to setup-turtles [ WhichColony? ]
set color black
set energy 0
ask turtle who [
(
ifelse
metabolism = 2 [set code-metabolism "M1"]
)
(
ifelse
reproduction = 5 [set code-reproduction "R1"]
)
set all-code ( word code-metabolism code-reproduction )
]
set x turtle-profiles-habitat
ask turtle who
[
if length x = 1
[
let a 1
while [ a < 7 ]
[
if member? a x
[
set my-patches patches with [ habitatcover = a ]
]
set a a + 1
]
]
if length x = 2
[
let a 1
while [ a < 7 ]
[
let b 1
while [ b < 7 ]
[
if a = item 0 x and b = item 1 x
[
set my-patches patches with [ habitatcover = a or habitatcover = b ]
]
set b b + 1
]
set a a + 1
]
]
]
end
to go
metabolic
print ( word "TICK: " ticks )
ask turtles [ print ( word "I am: " who ) ]
tick
let n count turtles
if n = 0 or ticks = 10 and ExportView? = true [ output ] ;; ExportView? is a switch in the interface
end
to metabolic
ask turtles
[
let z [ resources ] of patch-here
if
metabolism = 2 [
set energy ( ceiling ( z ) - 2 )
if energy <= 1.7 [ die-turtles ]
if
reproduction = 5 [
if energy >= 5 [ dispersion ]
]
]
]
end
to dispersion
let p 0
while [ p < 1 ] [
let available-patch my-patches with [ distance myself > 3 and distance myself < 5 and count turtles-here = 0 and not any? other turtles in-radius 3 ]
set PatchAvailable count available-patch
if PatchAvailable = 0 [ stop ]
let choose-patch one-of available-patch
let coordx [ pxcor ] of choose-patch
let coordy [ pycor ] of choose-patch
hatch 1 [
setxy coordx coordy
set turtle-count count turtles-here
set color white
set energy 0
set p p + 1
]
]
end
to die-turtles
foreach ListProfiles [ lp ->
set Death 0
set Death Death + 1
]
die
end
to color_patches
ask patches [ set pcolor white ]
ask turtles [
ask patch-here [ set pcolor magenta ]
]
end
to output
export-view ( word "View.png" )
end
;; in the interface go button, I put the following:
;if ExportView? = true
;[
; color_patches
;]
;go
我认为最好的跟踪方法是 patches-own
变量来跟踪乌龟是否 曾经 出生在 patch
。在这个示例代码中,我调用了 turtle-born-here
,在设置中将变量设置为 false
,然后在 turtle
为 'born' 时更新变量(无论是在设置中,或在 go
).
patches-own [ turtle-born-here ]
to setup
ca
ask patches [ set turtle-born-here false ]
ask n-of 5 patches [
sprout 1
set turtle-born-here true
]
reset-ticks
end
to go
ask turtles [
rt random 60 - 30
fd 1
if random-float 1 < 0.05 [
hatch 1
ask patch-here [ set turtle-born-here true]
]
]
end
to example-export-image
setup
; Some example go runs
repeat 50 [ go ]
; This is the export-view component
cd
ask turtles [
ht
]
ask patches [
ifelse turtle-born-here
[ set pcolor magenta ]
[ set pcolor white ]
]
export-view "example_view_export.png"
end
运行 这会吐出像这样的图像: