首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BehaviorSpace冻结步骤#0

BehaviorSpace冻结步骤#0
EN

Stack Overflow用户
提问于 2014-07-24 12:59:19
回答 1查看 217关注 0票数 1

对不起,如果这是显而易见的,我已经搜索了所有我能想到的,问了一个同事,我们都被困住了。

我有一些代码(下面是关于狼羊捕食的一点转折),我想运行行为空间(也是下面的输入)。然而,它从来没有完成。它似乎总是停留在运行的步骤#0上(它所坚持的运行#是不同的)。如果它们是孤立运行的(因此所有变量看起来都很好),那么它就可以很好地运行它们。它似乎只是冻结了(没有产生错误消息,也没有崩溃)。

有什么原因吗?

谢谢,

西蒙

代码:

代码语言:javascript
复制
globals [grass]  ;; keep track of how much grass there is
;; Sheep and wolves are both breeds of turtle.
breed [sheep a-sheep]  ;; sheep is its own plural, so we use "a-sheep" as the singular.
breed [wolves wolf]
turtles-own [energy]       ;; both wolves and sheep have energy
patches-own [countdown]

to setup
  clear-all
  ask patches [ set pcolor green ]
  ;; check GRASS? switch.
  ;; if it is true, then grass grows and the sheep eat it
  ;; if it false, then the sheep don't need to eat
  if grass? [
    ask patches [
      set countdown random grass-regrowth-time ;; initialize grass grow clocks randomly
      set pcolor one-of [green brown]
    ]
  ]
  if fences?[ ; this code adds in blue fences to create patches of various size (if fences are turned on). Turtles cannot pass over fences
      ask patches with [pxcor mod connectivity2 = 0]
          [ set pcolor blue ]
      ask patches with [pycor mod connectivity = 0]
          [ set pcolor blue ]
   ]
  set-default-shape sheep "sheep"
  create-sheep ((count patches - (count patches with [pcolor = blue])) / 25)  ;; create the sheep, then initialize their variables. The starting density always remains constant despite a varying world size
  [
    set color white
    set size 1.5  ;; easier to see
    set label-color blue - 2
    set energy random (2 * sheep-gain-from-food)
    setxy random-xcor random-ycor
  ]
  set-default-shape wolves "wolf"
  create-wolves ((count patches - (count patches with [pcolor = blue])) / 50)   ;; create the wolves, then initialize their variables. The starting density always remains constant despite a varying world size
  [
    set color black
    set size 2  ;; easier to see
    set energy random (2 * wolf-gain-from-food)
    setxy random-xcor random-ycor
  ]
  display-labels
  set grass count patches with [pcolor = green]
  reset-ticks
end

to go
  if count wolves = 0 and count sheep = 0 and ((count patches with [pcolor = green]) = (count patches - (count patches with [pcolor = blue]))) [ stop ] ; stop model when the whole world has flipped to grass
  ask sheep [
    move
    if grass? [
      set energy energy - 1  ;; deduct energy for sheep only if grass? switch is on
      eat-grass
    ]
    death
    reproduce-sheep
  ]
  ask wolves [
    move
    set energy energy - 1  ;; wolves lose energy as they move
    catch-sheep
    death
    reproduce-wolves
  ]
  if grass? [ ask patches [ grow-grass ] ]
  set grass count patches with [pcolor = green]
  tick
  display-labels
end

to move  ;; turtle procedure
  rt random 50
  lt random 50
    ifelse [pcolor] of patch-ahead 1 = blue
      [ move]   ;; If there is a blue patch ahead of you, choose another random direction
      [ fd 1 ]                  ;; Otherwise, it is safe to move forward.
end

to eat-grass  ;; sheep procedure
  ;; sheep eat grass, turn the patch brown
  if pcolor = green [
    set pcolor brown
    set energy energy + sheep-gain-from-food  ;; sheep gain energy by eating
  ]
end

to reproduce-sheep  ;; sheep procedure
  if random-float 100 < sheep-reproduce [  ;; throw "dice" to see if you will reproduce
    set energy (energy / 2)                ;; divide energy between parent and offspring
    hatch 1 [ ifelse [pcolor] of patch-ahead 1 = blue ;; hatch an offspring
      [ move]   ;; If there is a blue patch ahead of the offspring, it chooses another random direction
      [ fd 1 ]  ;;If not, offspring move forward 1 step
    ]]
end

to reproduce-wolves  ;; wolf procedure
  if random-float 100 < wolf-reproduce [  ;; throw "dice" to see if you will reproduce
    set energy (energy / 2)               ;; divide energy between parent and offspring
    hatch 1 [ ifelse [pcolor] of patch-ahead 1 = blue ;; hatch an offspring
      [ move  ] ;; If there is a blue patch ahead of the offspring, it chooses another random direction
      [ fd 1 ] ;;If not, offspring move forward 1 step
      ] ]
end

to catch-sheep  ;; wolf procedure
  let prey one-of sheep-here                    ;; grab a random sheep
  if prey != nobody                             ;; did we get one?  if so,
    [ ask prey [ die ]                          ;; kill it
      set energy energy + wolf-gain-from-food ] ;; get energy from eating
end

to death  ;; turtle procedure
  ;; when energy dips below zero, die
  if energy < 0 [ die ]
end

to grow-grass  ;; patch procedure
  ;; countdown on brown patches: if reach 0, grow some grass
  if pcolor = brown [
    ifelse countdown <= 0
      [ set pcolor green
        set countdown grass-regrowth-time ]
      [ set countdown countdown - 1 ]
  ]
end

to display-labels
  ask turtles [ set label "" ]
  if show-energy? [
    ask wolves [ set label round energy ]
    if grass? [ ask sheep [ set label round energy ] ]
  ]
end

; Copyright 1997 Uri Wilensky.
; See Info tab for full copyright and license.

行为空间输入:

变量:

代码语言:javascript
复制
["world-width" 51]
["fences?" true]
["wolf-gain-from-food" 20]
["sheep-reproduce" 7]
["show-energy?" false]
["grass?" true]
["connectivity" 10 25 50]
["wolf-reproduce" 5]
["grass-regrowth-time" [1 1 100]]
["sheep-gain-from-food" 4]

重复:1

记者:

代码语言:javascript
复制
count wolves
count sheep
count patches with [pcolor = green]

度量在每一步运行。

设置:setup

Go:go

停止(我已经尝试过了,不管有没有这个):count wolves = 0 and count sheep = 0 and ((count patches with [pcolor = green]) = (count patches - (count patches with [pcolor = blue])))

时限:5000

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-25 16:24:05

对于我来说,很难想象这可能是由内存不足以外的其他原因造成的。内存不足会导致JVM慢到爬行。

“关于NetLogo”的系统选项卡中的内存使用统计数据显示了什么?您可以在那里验证您是否得到了所要求的堆大小。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24934403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档