Netlogo 模型运行太慢了。网络标志
我的模型过去可以在10个小时左右完成,但现在需要几个星期。有人能看一下我的代码并提出建议吗 我是新的网络标志和现实主义,而模型正在做什么,我希望它做。它的编码可能不是很有效。如能提供任何建议,将不胜感激 奇怪的是,每天有86400个滴答声。在第1天和第2天,每天跑步需要2:30分钟,在第3天,这一时间跳到14分钟,随着时间的推移,速度越来越慢。我不知道为什么Netlogo 模型运行太慢了。网络标志,netlogo,Netlogo,我的模型过去可以在10个小时左右完成,但现在需要几个星期。有人能看一下我的代码并提出建议吗 我是新的网络标志和现实主义,而模型正在做什么,我希望它做。它的编码可能不是很有效。如能提供任何建议,将不胜感激 奇怪的是,每天有86400个滴答声。在第1天和第2天,每天跑步需要2:30分钟,在第3天,这一时间跳到14分钟,随着时间的推移,速度越来越慢。我不知道为什么 ;;-------------------------------------------------------------;; ;;-
;;-------------------------------------------------------------;;
;;------------Kilians Wolf dispersion Model------------------- ;;
;;-------------------------------------------------------------;;
; http://jasss.soc.surrey.ac.uk/20/1/3.html tips for speeding up model
breed [adults adult]
breed [subadults subadult]
breed [juveniles juvenile]
breed [prey a-prey] ; prey is its own plural, so we use "a-prey" as the singular.
breed [livestock a-livestock]
breed [commons a-common]
breed [carcasses carcass]
adults-own [ete energy target-patch]
subadults-own [energy x0 y0 xcar ycar target-patch]
juveniles-own [energy x0 y0 xcar ycar target-patch]
prey-own [energy x0]
livestock-own [energy x0]
carcasses-own [mass decay]
commons-own [energy]
globals [ete-hour day week]
;;-------------------------------------------------------------;;
;;----------------------- SETUP COMMANDS---------------------- ;;
;;-------------------------------------------------------------;;
to setup
clear-all
ask patches [set pcolor green - 1]
ask patch 50 50
[
set pcolor white
ask patches in-radius 4.5 [set pcolor white]
ask patches in-radius 30 with [pcolor != white] [set pcolor green - 3]
ask patches in-radius 50 with [pcolor != white and pcolor != green - 3] [set pcolor green]
]
ask patch 50 54 [set pcolor 85]
ask patch 50 50 [set pcolor black]
create-adults 1
ask adults [ set color black set shape "wolf" setxy 50 50 set energy 53760 set size 1]
ask n-of n-parkprey patches with [pcolor = 52] [sprout-prey 1 [
set color brown
set shape "deer"
set size 2
set energy 5
]
]
ask n-of n-commonsprey patches with [pcolor = 55] [sprout-prey 1 [
;
set color brown
set shape "deer"
set size 2
set energy 172800
]
]
ask n-of n-livestock patches with [pcolor = 54] [sprout-livestock 1 [
;
set color white
set shape "cow"
set size 2
set energy 172800
]
]
ask n-of n-commonstock patches with [pcolor = 55] [sprout-commons 1 [
;
set color white
set shape "sheep"
set size 1
set energy 172800
]
]
ask adults [set ete 0]
reset-ticks
end
;;-------------------------------------------------------------;;
;;----------------------- GO COMMANDS--------------------------;;
;;-------------------------------------------------------------;;
to go
if ticks = day-length [set day day + 1 create-next-day]
if not any? turtles [ stop ]
if not any? adults [ user-message "your wolves have gone extinct" stop ]
if day = 365 [stop]
if management
[if count carcasses < 1 [
if day = 0 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 7 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 14[ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 21 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 28 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 35 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 42 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 49 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 56 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 63 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 70 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 77 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 84 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 91 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 98 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 105 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 112 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 119 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 126 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 133 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 140 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 147 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 154 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 161 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 168[ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 175 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 182 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 189 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 196 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 203 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 210 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 217 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 224 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 231 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 238 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 245 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 252 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 259 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 266 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 273 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 280 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 287 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 294 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 301 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 308 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 315 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 322 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 329 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 336 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 343 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 350 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 357 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
if day = 364 [ ask patches with [pcolor = 85] [sprout-carcasses 1 [
set shape "carcass"
set size 2
set mass 172800]]]
]]
if day = 150 [ask prey [reproduce]] ;day 150 of the year is in May which is the start of fawning season for deer
if day = 180 [ask prey [reproduce]] ;day 180 of the year is in June which is the end of fawning season for deer
ask adults [collar]
ask adults [be-active]
ask prey [graze]
ask commons [browse]
ask livestock [farm]
ask carcasses [decompose]
tick
end
;;-------------------------------------------------------------;;
;;------------------- WOLF COMMANDS----------------------------;;
;;-------------------------------------------------------------;;
to collar
if pcolor = 55 [set ete ete + 1]
if pcolor = 54 [set ete ete + 1]
if ete = ete-hour-length [set ete-hour ete-hour + 1 track]
if pen-mode-down [set pen-mode "down"]
end
To be-active ;when wolf is full
if energy < 40000 [ask adults [search hunt scavange take-oppurtunity invade-farm]]
if energy > 40000 [ask adults [go-home den]]
end
to den
if pcolor = black [set energy energy - 0.0012]
end
to search ;when wolf is hungry
set energy energy - 0.06
fd v-wolf
if random 600 = 1 ;; frequency of turn
[ ifelse random 2 = 0 ;; 50:50 chance of left or right
[ rt 10 ] ;; could add some variation to this with random-normal 45 5
[ lt 10 ]] ;; so that it samples from a dist with mean 45 SD 5
if any? prey in-radius smell [set heading towards one-of prey in-radius smell]
if any? livestock in-radius smell [set heading towards one-of livestock in-radius smell]
if any? commons in-radius smell [set heading towards one-of commons in-radius smell]
if any? carcasses in-radius smell [set heading towards one-of carcasses in-radius smell]
if energy < 0 [die]
end
To hunt ;to kill prey and eat it
if random-float 1 < hunt-success
[let kill one-of prey-here in-radius smell
if kill != nobody
[ask kill [ die ]
set energy energy + 6000 ]]
end
To scavange ;to kill prey and eat it
if random-float 1 < carrion-quality
[let carrion one-of carcasses-here in-radius smell
if carrion != nobody
[ask carrion [ die ]
set energy energy + 7500 ]]
end
To invade-farm ;to kill prey and eat it
let predation one-of livestock-here in-radius smell
if predation != nobody
[ ask predation [ die ]
set energy energy + 11400 ]
end
To take-oppurtunity ;to kill prey and eat it
let oppurtunity one-of commons-here in-radius smell
if oppurtunity != nobody
[ ask oppurtunity [ die ]
set energy energy + 10059 ]
end
to go-home ;to head home after they've eaten and den until they need to feed again
set target-patch min-one-of (patches with [pcolor = black]) [distance myself]
face target-patch
fd v-wolf
set energy energy - 0.036
end
;;-------------------------------------------------------------;;
;;------------------- COMMONS COMMANDS-------------------------;;
;;-------------------------------------------------------------;;
to browse
fd v-domestic
if random 600 = 1 ;; frequency of turn
[ ifelse random 2 = 0 ;; 50:50 chance of left or right
[ rt 20 ] ;; could add some variation to this with random-normal 45 5
[ lt 20 ]] ;; so that it samples from a dist with mean 45 SD 5
if pcolor = 54 [fd -3]
if pcolor = 52 [fd -3]
end
;;-------------------------------------------------------------;;
;;------------------- LIVESTOCK COMMANDS-----------------------;;
;;-------------------------------------------------------------;;
to farm
fd v-domestic
if random 600 = 1 ;; frequency of turn
[ ifelse random 2 = 0 ;; 50:50 chance of left or right
[ rt 20 ] ;; could add some variation to this with random-normal 45 5
[ lt 20 ]] ;; so that it samples from a dist with mean 45 SD 5
if pcolor = 55 [fd -5]
if pcolor = 52 [fd -50]
end
;;-------------------------------------------------------------;;
;;------------------- PREY COMMANDS----------------------------;;
;;-------------------------------------------------------------;;
to graze
fd v-prey
if random 600 = 1 ;; frequency of turn
[ ifelse random 2 = 0 ;; 50:50 chance of left or right
[ rt 20 ] ;; could add some variation to this with random-normal 45 5
[ lt 20 ]] ;; so that it samples from a dist with mean 45 SD 5
if pcolor = 54 [fd -5]
end
to reproduce ; prey procedure
if count prey < K
[hatch 1 [ rt random-float 360 fd v-prey ]] ; hatch an offspring and move it forward 1 step
end
;;-------------------------------------------------------------;;
;;------------------- PREY COMMANDS----------------------------;;
;;-------------------------------------------------------------;;
to decompose
set mass mass - 1
if mass = 0 [die]
end
;;-------------------------------------------------------------;;
;;------------------- GENERAL COMMANDS-------------------------;;
;;-------------------------------------------------------------;;
to create-next-day
reset-ticks
end
to track
set ete 0
end
;;-----------------------------------------------------------------------------------------;;
;;------------基里安-沃尔夫扩散模型----------------;;
;;-------------------------------------------------------------;;
; http://jasss.soc.surrey.ac.uk/20/1/3.html 加速模型的技巧
品种[成年]
繁殖[亚成体亚成体]
繁殖[少年]
繁殖[一个猎物一个猎物];猎物本身是复数,所以我们用“a-prey”作为单数。
品种[家畜a-家畜]
品种[公地a-公地]
品种[胴体]
成人拥有[ete能量目标贴片]
子成体拥有[能量x0 y0 xcar ycar目标补丁]
青少年拥有[能量x0 y0 xcar ycar目标贴片]
猎物自身[能量x0]
牲畜自有[能源x0]
尸体本身[大量腐烂]
公地自有[能源]
全球[每周工作小时]
;;-------------------------------------------------------------;;
;;----------------------- 设置命令----------------;;
;;-------------------------------------------------------------;;
设置
清除所有
询问修补程序[将pcolor设置为绿色-1]
询问补丁50
[
将颜色设置为白色
询问半径为4.5的补片[设置pcolor白色]
使用[pcolor!=白色][将pcolor设置为绿色-3]询问半径为30的面片
使用[pcolor!=白色和pcolor!=绿色-3][set pcolor green]询问半径为50的面片
]
询问补丁50 54[设置pcolor 85]
询问补丁50[设置颜色为黑色]
创建成人1
询问成年人[设置颜色黑色设置形状“狼”设置XY 50设置能量53760设置大小1]
用[pcolor=52][sprout prey 1]询问n-of n-parkprey斑块[
设置颜色为棕色
定形“鹿”
2号套餐
设置能量5
]
]
用[pcolor=55][sprout prey 1]询问n-of n-commonsprey斑块[
;
设置颜色为棕色
定形“鹿”
2号套餐
设置能量172800
]
]
用[pcolor=54][发芽牲畜1]询问n-of n-牲畜贴片[
;
将颜色设置为白色
定形“奶牛”
2号套餐
设置能量172800
]
]
使用[pcolor=55][sprout commons 1]询问n-of n-commonstock补丁[
;
将颜色设置为白色
定形“羊”
1号套餐
设置能量172800
]
]
询问成年人[设置为0]
重置滴答声
结束
;;-------------------------------------------------------------;;
;;----------------------- GO命令-----------------------------------------;;
;;-------------------------------------------------------------;;
外带
如果刻度=日长[设置日+1创建第二天]
如果没有?乌龟[停]
如果没有?成年人[用户信息“你的狼已经灭绝”停止]
如果日期=365[停止]
如果管理
[如果屠体计数<1[
如果day=0[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果第7天[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果第14天[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果第21天[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果第28天[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果日数=35[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果day=42[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果day=49[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果天=56[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果day=63[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果天=70[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果day=77[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果day=84[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果day=91[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果day=98[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果天=105[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果天=112[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果day=119[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果天=126[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果day=133[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]
如果天=140[询问带有[pcolor=85]的补丁][发芽尸体1[
定形“胴体”
2号套餐
设置质量172800]]]