Netlogo笔记05:火灾扩散模型样例

学习Netlogo的内部fires模型样例流程: 

  1. turtle的类别标记分为:燃烧和灰烬。都由green tree发展而来
  2. 将左边界作为燃烧起始线,开始扩散
  3. 定义了density作为tree的分布密度,滑动控制
  4. 从初始化green tree、fires line到以fires line扩散引燃周围green tree
  5. 引燃所有fire tree的冯诺依曼邻居,再让fire tree变成ember灰烬
  6. 计算出当前燃烧覆盖率:fired/ember tree number / tree_total  *  100
  7. ember会fade color褪色,由红变黑
  8. 直到所有fire tree的breed个体都消失,结束迭代,否则继续step5
globals [
  initial-trees   ;; how many trees (green patches) we started with
  burned-trees    ;; how many have burned so far
]

breed [fires fire]    ;; bright red turtles -- the leading edge of the fire
breed [embers ember]  ;; turtles gradually fading from red to near black

to setup
  clear-all
  set-default-shape turtles "square"
  ;; make some green trees
  ask patches with [(random-float 100) < density]
    [ set pcolor green ]
  ;; make a column of burning trees
  ask patches with [pxcor = min-pxcor]
    [ ignite ]
  ;; set tree counts
  set initial-trees count patches with [pcolor = green]
  set burned-trees 0
  reset-ticks
end

to go
  if not any? turtles  ;; either fires or embers
    [ stop ]
  ask fires
    [ ask neighbors4 with [pcolor = green]
        [ ignite ]
      set breed embers ]
  fade-embers
  tick
end

;; creates the fire turtles
to ignite  ;; patch procedure
  sprout-fires 1
    [ set color red ]
  set pcolor black
  set burned-trees burned-trees + 1
end

;; achieve fading color effect for the fire as it burns
to fade-embers
  ask embers
    [ set color color - 0.3  ;; make red darker
      if color < red - 3.5     ;; are we almost at black?
        [ set pcolor color
          die ] ]
end


; Copyright 1997 Uri Wilensky.
; See Info tab for full copyright and license.
  1. global [ aaa bbb ...]:定义全局变量
  2. breed [fires fire]:定义种类
  3. if not any? turtles:如果没有绘图的agent,就结束迭代
  4. neighbor4:冯诺依曼邻居
  5. sprout-fries 1:在当前的patch创建一个turtle拥有随机的方向、颜色,种类是fires
  6. ask embers/fires:遍历这种种类的turtle
  7. color、pcolor:turtle、patch的颜色属性
  8. die:turtle被解析,将此turtle的turtle breed连接断裂

Netlogo笔记05:火灾扩散模型样例_第1张图片

你可能感兴趣的:(netlogo与元胞自动机)