如何使用 NetLogo 6.2 在世界的某些区域快速创建多只海龟?
How to create multiple turtles in certain patches of the world quickly using NetLogo 6.2?
我正在尝试解决在 NetLogo 世界中创建海龟的速度问题。
我有一个模型,它有一个大小为 600X600 的世界。我也有 31 个海龟资料(每只海龟只能出生在特定的栖息地覆盖类型或栖息地覆盖集中(请参阅代码中的 ValidHabs 变量)。在代码中,也有 2 个变量是具有 2 个级别的新陈代谢(list1 in代码)和2个级别的复制(代码中的list2)。另外,我希望至少有200只海龟在这个世界上出生或更多。
问题是海龟在世界上诞生需要很长时间。我是否已经创建了一个名为 Display 的开关?加速海龟的创建。速度我也调的比较快,还是需要很长时间来制作海龟
有谁知道如何根据我的代码加快海龟的创建速度?
我不知道还能做什么来加快代码速度...感谢任何帮助:)
提前致谢
代码如下:
globals [ ValidHabs ValidHabsItem HotPatchSet CurrentHotPatchSet ]
patches-own [ habitatcover ]
turtles-own [ turtle-profiles-habitat metabolism reproduction all-code code-metabolism code-reproduction ]
to setup
clear-all
random-seed 1
;; ValidHabs are the habitat profiles of the turtles are all combinations of 5 types of habitatcover without repetition
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]]
ifelse ( Display? = true ) [ display ] [ no-display ] ;; display is a switch in interface
resize-world 599 * 0 ( 599 * 1 ) ( 599 * -1 ) 599 * 0 ;; the world is 600X600 in size
setup-world
setup-patches
reset-ticks
print ( word "That setup took " timer " seconds" )
end
to setup-world
let pcolors []
set pcolors [ 25 65 23 53 105 10 ]
ask patches [
set pcolor item (random 5) 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 = 10 [ set habitatcover 6 ]
]
end
to setup-patches
set-patch-size 0.6 ;; view patch size
set HotPatchSet patches with [ ( habitatcover != 6 ) ]
let list1 ( list 2 4 )
let list2 ( list 5 10 )
let n0 count turtles
set CurrentHotPatchSet HotPatchSet with [ habitatcover = one-of item ValidHabsItem ValidHabs ]
while [ n0 < ( length list1 ) * ( length list2 ) * 200 ] ;; I want 200 ou more turtles in the word. Here I put 200
[
(
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 [ whichTurtle? ]
set color black
ask turtle who [
(
ifelse
metabolism = 2 [set code-metabolism "M1"]
metabolism = 4 [set code-metabolism "M2"]
)
(
ifelse
reproduction = 5 [set code-reproduction "R1"]
reproduction = 10 [set code-reproduction "R2"]
)
set all-code ( word code-metabolism code-reproduction )
]
end
恐怕我没有在您的代码中查找特定问题,但这里有关于加速模型的一般建议:
http://jasss.soc.surrey.ac.uk/20/1/3.html
更新在这里:
http://www.railsback-grimm-abm-book.com/jasss-models/
我很确定其中一些建议适用于您的代码。
我正在尝试解决在 NetLogo 世界中创建海龟的速度问题。
我有一个模型,它有一个大小为 600X600 的世界。我也有 31 个海龟资料(每只海龟只能出生在特定的栖息地覆盖类型或栖息地覆盖集中(请参阅代码中的 ValidHabs 变量)。在代码中,也有 2 个变量是具有 2 个级别的新陈代谢(list1 in代码)和2个级别的复制(代码中的list2)。另外,我希望至少有200只海龟在这个世界上出生或更多。
问题是海龟在世界上诞生需要很长时间。我是否已经创建了一个名为 Display 的开关?加速海龟的创建。速度我也调的比较快,还是需要很长时间来制作海龟
有谁知道如何根据我的代码加快海龟的创建速度?
我不知道还能做什么来加快代码速度...感谢任何帮助:)
提前致谢
代码如下:
globals [ ValidHabs ValidHabsItem HotPatchSet CurrentHotPatchSet ]
patches-own [ habitatcover ]
turtles-own [ turtle-profiles-habitat metabolism reproduction all-code code-metabolism code-reproduction ]
to setup
clear-all
random-seed 1
;; ValidHabs are the habitat profiles of the turtles are all combinations of 5 types of habitatcover without repetition
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]]
ifelse ( Display? = true ) [ display ] [ no-display ] ;; display is a switch in interface
resize-world 599 * 0 ( 599 * 1 ) ( 599 * -1 ) 599 * 0 ;; the world is 600X600 in size
setup-world
setup-patches
reset-ticks
print ( word "That setup took " timer " seconds" )
end
to setup-world
let pcolors []
set pcolors [ 25 65 23 53 105 10 ]
ask patches [
set pcolor item (random 5) 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 = 10 [ set habitatcover 6 ]
]
end
to setup-patches
set-patch-size 0.6 ;; view patch size
set HotPatchSet patches with [ ( habitatcover != 6 ) ]
let list1 ( list 2 4 )
let list2 ( list 5 10 )
let n0 count turtles
set CurrentHotPatchSet HotPatchSet with [ habitatcover = one-of item ValidHabsItem ValidHabs ]
while [ n0 < ( length list1 ) * ( length list2 ) * 200 ] ;; I want 200 ou more turtles in the word. Here I put 200
[
(
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 [ whichTurtle? ]
set color black
ask turtle who [
(
ifelse
metabolism = 2 [set code-metabolism "M1"]
metabolism = 4 [set code-metabolism "M2"]
)
(
ifelse
reproduction = 5 [set code-reproduction "R1"]
reproduction = 10 [set code-reproduction "R2"]
)
set all-code ( word code-metabolism code-reproduction )
]
end
恐怕我没有在您的代码中查找特定问题,但这里有关于加速模型的一般建议: http://jasss.soc.surrey.ac.uk/20/1/3.html 更新在这里: http://www.railsback-grimm-abm-book.com/jasss-models/
我很确定其中一些建议适用于您的代码。