BehaviorSpace在第0步冻结

时间:2014-07-24 12:59:20

标签: netlogo behaviorspace

对不起,如果这很明显,我已经搜索了我能想到的一切,并问了一位同事,我们都被卡住了。

我想要运行行为空间(下面的输入),我有一些代码(下面 - 对狼羊的捕食略有不同)。但是,它永远不会完成。它似乎总是停留在跑步的第0步(跑步#它被卡住了变化)。如果它们是孤立运行的话,它坚持运行的工作正常(因此所有变量似乎都很好)。它似乎只是冻结(不产生错误信息,也不会崩溃)。

任何想法是什么造成的?

谢谢,

西蒙

代码:

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.

行为空间输入:

变量:

["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

记者:

count wolves
count sheep
count patches with [pcolor = green]

测量在每个步骤运行

设置:setup

去:go

停止(我已尝试使用和不使用此功能):count wolves = 0 and count sheep = 0 and ((count patches with [pcolor = green]) = (count patches - (count patches with [pcolor = blue])))

时间限制:5000

1 个答案:

答案 0 :(得分:0)

我很难想象这可能是由内存不足引起的。在内存上运行非常低会导致JVM慢慢爬行。

“关于NetLogo”的系统标签中的内存使用情况统计信息是什么?您可以在那里验证您实际获得了所要求的堆大小。