Netlogo 简化版Scatter 分散

turtles-own[
  nearby-classmates         ;; agentset of turtles within some specified radius
  stopped?                  ;; if the turtle hasn't moved
]

to setup
  clear-all
  set-default-shape turtles "circle"
  make-turtles
  reset-ticks
end

to make-turtles
  ;初始化时让海龟聚集在patch 0 0 周围,由于程序后续会限制每个patch 上只允许同时有一个海龟,所以初始化的这个圈内的patch 数量要大于海龟数量,否则弹框提示。
  if [count patches in-radius initial-radius] of patch 0 0 < num-open-min[ 
    user-message (word "There aren't enough patches in initial-radius to create the number "
                       "of turtles you've asked for.  Please make initial-radius larger or decrease "
                       "the number of turtles.")
    stop 
  ]
  ask patch 0 0 [
    create-initial-turtles num-open-min blue
  ]
  ask turtles[ 
    set stopped? false
  ]
end

to create-initial-turtles [n turtle-color]
  ask n-of n (patches in-radius initial-radius with [not any? turtles-here])[;从“圈”内取出n 个patch
    sprout 1[;每个patch 生成一个海龟并且为部分属性赋值
      set color turtle-color 
    ] 
  ]
end

to go
  ifelse bees-pen-down? [
    ask turtles [pen-down]
  ][
    ask turtles [pen-up]
  ]
  
  if all? turtles [stopped?] [ stop ]
  ask turtles [
    move-open-min
  ]
  tick
end

; set heading towards the largest open space, stopping when all other turtles are at least "too-close" away
to move-open-min ;; turtle procedure
  set nearby-classmates other turtles in-radius too-close
  ifelse any? nearby-classmates[ 
    facexy (mean [xcor] of nearby-classmates) (mean [ycor] of nearby-classmates)
    rt 180
    avoid-walls
    fd step-size
    set stopped? false 
  ][ 
    set stopped? true 
  ]
end

;如果乌龟遇到墙,转身
to avoid-walls ;; turtle procedure
  if not can-move? 1[ 
    rt 180 
  ]
end
 

参考自:Netlogo 库中的模型 Sample Models/Social Science/Scatter 里的open-min 算法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值