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

  • 相关阅读:
    手写一个泛型双向链表
    基础-符号表(一)-数据结构和算法(Java)
    读写锁ReentrantReadWriteLock&StampLock详解
    缓存穿透、缓存击穿、缓存雪崩以及解决方法
    2023-10-09 LeetCode每日一题(最小和分割)
    正则提取字符串中的年龄对大于50的求和
    docker系列持续更新中
    10.请介绍一下cookie
    Linux 内存管理 pt.3
    计算机网络-TCP协议
  • 原文地址:https://blog.csdn.net/Jerry_liu20080504/article/details/126539555