我的模型过去可以在大约10小时内完成,但现在需要数周时间。有人能看看我的代码并提出建议吗?
我不熟悉网络标志和现实主义,因为模特们正在做我想做的事情。它的编码可能不是很有效。如能提供任何建议,将不胜感激。
奇怪的是,每天有86400个滴答声。对于第一天和第二天,一天需要2:30分钟,在第三天,这个时间跃升到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
您的问题是激活程序。首先,您要求所有成年人(狼)运行程序
保持活动状态
,但该程序也要求所有成年人做一些事情。你可能在其他地方也犯了同样的错误。
此外,你应该查看
mod
操作符,如果管理代码,它会大大缩短你的
。它还将稍微加快运行速度,因为代码只需检查一次当天是否是7的倍数,而不是现在检查多少次。
自从我安装了android studio,它从来没有Eclipse快。每当我开始调试时,在设备上开始调试和运行应用程序通常需要1-2分钟。 问题:我想知道如何解决这个问题(安装windows 64位或安装其他类型的android studion或...) 我的系统配置如下所示: 配备Core i5 cpu的笔记本电脑, Windows 8.1 32位 3GB可用RAM Android Studio
我有一个带有API的网站,我用它来获取JSON数据。我有一个类,每次发送请求时都会创建该类的一个实例。创建的实例时,将创建一个新的对象,ed和ed: 然而,我需要在一个循环中发送10个这样的请求。每个请求大约需要1.3秒,而所有10个请求加起来不应超过1-2秒。我发现大部分时间都花在获取输入流和处理它上:
我知道这是一个常见的问题,但我觉得我已经试过了所有的解决方案,所以我不知道该怎么做了。 已安装Intel x86 HAXM 尝试在SDK管理器中重新安装仿真程序 尝试使用不同API级别的各种AVD 我不明白是怎么回事,在过去的两天里,我对这种情况感到非常沮丧,任何帮助或提示都将不胜感激!
问题内容: 我正在构建JavaFX应用程序,我想知道是否有关于如何尽快加载当前新内容的建议(最佳实践)。 当前我正在做的(或多或少)是这样的: 对于加载简单的s,es等的复杂场景而言,上面的方法对于简单的s BUT 来说足够好且快速。 我在的方法中进行的所有初始化。 在那里,我将项目添加到框中,进行初始化等,但是正如我所说的,这花费了太多时间。 难道我做错了什么?我应该在其他地方初始化吗? 谢谢。
我在新的spring boot应用程序中遇到了一个奇怪的缓慢现象,当我获取一个表用于报告时。 这是一个简单的表,没有对其他表的引用,它有5列。行数为50k。因此,我使用了简单的findAll()方法,该方法在JpaRepository中提供。 当“目标”结果是实体时,findAll()执行需要5分钟。当我设置DTO类投影或接口投影时,执行需要1-2分钟。 我相信对于那么多的数据来说,这仍然太多了。
tomcat启动太慢(启动要起半个小时没有打断点)