• 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 算法

  • 相关阅读:
    Flutter Inspector无法显示完整的Widget树
    海外住宅IP如何助力国外问卷调查?
    GBase8s数据库FOR READ ONLY 子句
    java集合框架
    Linux开发讲课14--- CPU100%该如何处理
    Mysql修改密码
    neo4j数据库导出
    简单介绍二分类问题评价指标
    【计算机专业浅谈】为什么我不建议你选择计算机专业?
    从Axure制作网站引出的网站设计要求
  • 原文地址:https://blog.csdn.net/Jerry_liu20080504/article/details/126539555