Oop 确定海龟群的数量

Oop 确定海龟群的数量,oop,gis,netlogo,Oop,Gis,Netlogo,我一直在尝试计算我的世界中海龟集群的数量,但我一直面临“你不能在补丁环境中使用GROUPE,因为GROUPE只是海龟”。我正在使用Schelling隔离模型中的bits并修改模型库中的补丁集群示例,但在运行模型后,我无法使用命令show max[amas]of persones获得集群数量 导致问题的线位于集团底部,是: (groupe=[groupe]我自己)] 以下是完整的代码: extensions [ GIS ; Extension GIS ] globals [ v ;v

我一直在尝试计算我的世界中海龟集群的数量,但我一直面临“你不能在补丁环境中使用GROUPE,因为GROUPE只是海龟”。我正在使用Schelling隔离模型中的bits并修改模型库中的补丁集群示例,但在运行模型后,我无法使用命令
show max[amas]of persones
获得集群数量

导致问题的线位于集团底部,是:

(groupe=[groupe]我自己)]

以下是完整的代码:

extensions
[
  GIS ; Extension GIS
]

globals
[
  v
  ;vc
  routes.data ; shapefile routes
  Usol.data ; shapefile utilisation sol
  
  average-happy ; pourcentage heureux
  amas
]

patches-own
[
  routes ; routes
  routes? ; booléenne routes
  Usol
  Usol?
  state ; état d'une patch

  val ; valeur
  
  cluster
]

turtles-own
[
  groupe
  unhappy?
  
  counter
  similar-nearby
  other-nearby
  total-nearby
  happy
]

breed ; Création d'une classe
[
  personnes
  personne
]

to setup ; Déclaration de la procédure setup
  ca ; Clear-all
  reset-ticks ; Remet le compteur de ticks à zéro
  set v 2
  initialiserGIS ; Initialisation de la procédure initialiserGIS
  creerHumains
  do-plots
end ; Fin de la procédure setup

to initialiserGIS ; Déclaration de la procédure initialiserGIS
  set Usol.data gis:load-dataset "utilisationDuSol.shp"
  gis:apply-coverage Usol.data "LANDUSE" Usol
  ask patches
  [
    set Usol? FALSE
  ]
  ask patches gis:intersecting Usol.data
  [
    set Usol? TRUE
    ifelse Usol = "residential"
    [
      set state 1
      set pcolor green
    ]
    [
      set state 0
      set pcolor grey
    ]
  ]

  set routes.data gis:load-dataset "routesMtl.shp"
  ask patches
  [
    set routes? FALSE
  ]
  ask patches gis:intersecting routes.data
  [
    set routes? TRUE
    set state 0 ; Empêche aux agents d'habiter sur les routes
    set pcolor red ; Assigne la couleur rouge aux routes
  ]
end ; Fin de la procédure initialiser GIS

to creerHumains ; Déclaration de la procédure creerHumains
  ask patches with [state = 1] ; Demande aux cellules résidentielles
  [
    set val random-float 1 ; Accorde une valeur aléatoire décimale entre 0 et 1 à la variable val
  ]
  let vide 0.1 ; Initialisation de la variable locale vide avec la valeur 0.1
  let limite1 (1 - vide) / v ; Initialisation de la variable locale limite
  let residents patches with [state = 1 and val > vide] ; Initialisation de la variable locale residents
  ask residents ; Demande aux residents
  [
    sprout-personnes 1 ; Primitive permettant à une patch de créer un agent sur toutes les patches résidentielles
  ] ; Permet de créer un nombre identique de personne de chaque groupe
  let limiteList (list (pmin * (1 - vide )) ((1 - pmin) * (1 - vide)))
  let i 0 
  let minVal vide 
  let maxVal 0 
  while [i <= v - 1] 
  [ 
    set maxVal minVal + item i limiteList 
    ask personnes with [val <= maxVal and val > minVal] 
    [
      set groupe i + 1
    ]
    set minVal maxVal 
    set i i + 1
  ]

  ask personnes ;ceci sert uniquement à attribuer une couleur différente à chaque groupe
  [ ; Assigne la couleur et la forme appropriée en fonction du groupe
    ifelse groupe = 1
    [
      set color red
      set shape "house"
    ]
    [
      ifelse groupe = 2
      [
        set color blue
        set shape "house"
      ]
      [
        ifelse groupe = 3
        [
          set color green
          set shape "house"
        ]
        [
          ifelse groupe = 4
          [
            set color orange
            set shape "house"
          ]
          [
            ifelse groupe = 5
            [
              set color black
              set shape "house"
            ]
            [
              ifelse groupe = 6
              [
                set color brown
                set shape "house"
              ]
              [
                ifelse groupe = 7
                [
                  set color pink
                  set shape "house"
                ]
                [
                  ifelse groupe = 8
                  [
                    set color white
                    set shape "house"
                  ]
                  [
                    set color magenta
                    set shape "house"
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  ]
end ; Fin de la procédure creerHumains

to move  ; Déclaration de la procédure move
  move-to one-of patches with [Usol = "residential"]
  if any? other turtles-here
  [ 
    move ;; Continue jusqu'à tant qu'une patch soit trouvée
  ]  
end

to update-variables ; Déclaration de la procédure update-variables ; permet de mettre à jour les valeurs
  update-turtles
  update-globals
end ; Fin de la procédure update-variables

to update-turtles ; Déclaration de la procédure update-turtles
  ask turtles ; demande turtles
  [ ; Test des patches voisines
    set counter 0 ; réinitialise counter
    set similar-nearby count (turtles-on neighbors) with [groupe = [groupe] of myself]
    set other-nearby count (turtles-on neighbors) with [groupe != [groupe] of myself]
    set total-nearby similar-nearby + other-nearby
    ifelse groupe = 1 
    [
      ifelse (Tmin >= similar-nearby) ; vérification si vc est supérieur ou égale aux voisins similaires
      [ ; personne unhappy + move
        set unhappy? TRUE
        set happy 0
        move
      ] 
      [  ; personne happy
        set unhappy? FALSE
        set happy 1
      ]
    ]
    [
      ifelse (Tmaj <= similar-nearby) ; vérification si vc est supérieur ou égale aux voisins similaires
      [ ; personne unhappy + move
        set unhappy? TRUE
        set happy 0
        move
      ] 
      [  ; personne happy
        set unhappy? FALSE
        set happy 1
      ]
    ]
  ]
end ; Fin de la procédure update-turtles

to update-globals ; Déclaration de la procédure update-globals
  set average-happy mean [happy] of turtles ; Average-happy = moyenne des turtles happy
end ; Fin de la procédure update-globals

to go ; Déclaration de la procédure go
  update-variables ; Vérifie l'état de chacunes des personnes et fait bouger celles nécessitant de l'être
  tick ; Incrémente la valeur de la variable tick
  if ticks >= 100 ; Si le nombre de ticks est supérieur ou égal à 100
  [
    stop ; Arrête le modèle
  ]
  if c-unhappy = 0
  [
    stop ; Arrête le modèle si personne est unhappy
  ]
end ; Fin de la procédure go

to do-plots ; Déclaration de la procédure do-plots
  plot average-happy * 100 ; Plot la moyenne des habitants étant happy
end ; Fin de la procédure do-plots

to-report c-happy ; Déclaration de la procédure de rapportage c-happy
  report sum [happy] of turtles ; Rapporte le nombre de turtles étant happy
end ; Fin de la procédure de rapportage c-happy

to-report c-unhappy ; Déclaration de la procédure de rapportage c-unhappy
  report ((count turtles) - (sum [happy] of turtles)) ; Rapporte le nombre de turtles étant unhappy
end ; Fin de la procédure de rapportage c-unhappy


;;; Q6

to find-clusters
  loop 
  [
    ;; pick a random patch that isn't in a cluster yet
    let seed one-of personnes with [cluster = nobody]
    ;; if we can't find one, then we're done!
    if seed = nobody
    [
      show-clusters
      stop 
    ]
    ;; otherwise, make the patch the "leader" of a new cluster
    ;; by assigning itself to its own cluster, then call
    ;; grow-cluster to find the rest of the cluster
    ask seed
    [ 
      set cluster self
      grow-cluster
    ]
  ]
  display
end

to grow-cluster  ;; patch procedure
  ask neighbors4 with [(cluster = nobody) and
    (groupe = [groupe] of myself)]
  [ 
    set cluster [cluster] of myself
    grow-cluster
  ]
end

;; once all the clusters have been found, this is called
;; to put numeric labels on them so the user can see
;; that the clusters were identified correctly
to show-clusters
  let counter2 0
  loop
  [ ;; pick a random patch we haven't labeled yet
    let p one-of patches with [plabel = ""]
    if p = nobody
      [
        stop
    ]
    ;; give all patches in the chosen patch's cluster
    ;; the same label
    ask p
    [ 
      ask personnes with [cluster = [cluster] of myself]
      [
        set amas counter2 
      ] 
    ]
    set counter2 counter2 + 1 
  ]
end
扩展
[
扩展GIS
]
全局变量
[
v
;vc
routes.data;形状文件管线
Usol.data;形状文件使用sol
平平淡淡的快乐
阿玛斯
]
补丁自己
[
路线
路线
Usol
Usol?
国家公园
瓦尔
簇
]
乌龟自己的
[
群体
不快乐的
柜台
附近类似
附近的其他
附近总计
幸福的
]
繁殖等级评定
[
人员
人员
]
设置;程序设置声明
钙;清除所有
重置滴答声;请记住,我的电脑是滴答作响的
第v组2
初始化器GIS;初始化程序初始化器
鱼肝菌素
搞阴谋
结束;程序设置财务
初始化GIS;初始化程序声明
设置Usol.data gis:加载数据集“UsilizationDusol.shp”
地理信息系统:应用覆盖率Usol.data“土地利用”Usol
询问补丁
[
设置Usol?错误
]
ask补丁gis:交叉Usol.data
[
设置Usol?为真
ifelse Usol=“住宅”
[
设置状态1
将颜色设置为绿色
]
[
设置状态0
设置彩色灰色
]
]
设置routes.data gis:加载数据集“RouteSTL.shp”
询问补丁
[
设置路线?错误
]
ask修补程序gis:相交路线。数据
[
设定路线?对
设置状态0;路线附近的居民
设置P颜色红色;指定红色辅助路线
]
结束;初始化程序Fin
去克里尔胡曼;克里尔胡曼过程声明
使用[state=1]询问修补程序;红细胞需求量
[
设置val随机浮动1;在0和1之间设置变量val
]
设为0.1;变量区域设置的初始化,参见avec la valeur 0.1
let limite1(1-vide)/v;变量语言环境限制的初始化
让居民使用[state=1和val>vide]进行修补;变量区域设置居民的初始化
询问居民;住户需求
[
芽苗人1;原始渗透剂是一种含铁补充剂
] ; 关于查克集团人员的名义识别
让limiteList(列表(pmin*(1-vide))((1-pmin)*(1-vide)))
让我0
让明瓦尔去吧
设maxVal为0
而[i=附近类似);vérification是类似的地方
人员不高兴+移动
设定不快乐?真的吗
设置快乐0
移动
] 
人快乐
设定不快乐?错
设定快乐1
]
]
[
ifelse(Tmaj=100;这是一个名称,表示您对100的支持
[
停下来
]
如果c-s=0
[
停下来,我的人很不高兴
]
结束;程序结束
绘图;绘图程序的声明
平均幸福地块*100;居住者幸福地块
结束;程序结束
报告c-happy;报告程序声明c-happy
报告海龟的总数[快乐];海龟的名字
结束;报告程序结束
报告c-不快乐;报告c-不快乐过程的声明
报告(数海龟)-(海龟总数[高兴]);海龟名称报告
结束;报告程序结束
第六题
寻找集群
环
[
;选择一个尚未在群集中的随机补丁
让其中一个人与[cluster=nobody]
如果我们找不到,那就完了!
如果种子=无人
[
显示群集
停止
]
;否则,使补丁成为新集群的“领导者”
通过将自身分配到自己的集群,然后调用
;增长集群以找到集群的其余部分
询问种子
[ 
自组簇
生长簇
]
]
显示
结束
增长群集;;修补程序
向邻居4询问[(集群=无人)和
(groupe=[groupe]我自己)]
[ 
设置我自己的群集[群集]
生长簇
]
结束
一旦找到了所有的簇,就称为
;将数字标签放在上面,以便用户可以看到
正确识别集群
显示群集
让我们来反击20
环
[;;选择一个我们尚未标记的随机补丁
让p使用[plabel=”“]
如果p=无人
[
停止
]
;;给出所选修补程序群集中的所有修补程序
相同的标签
问p
[ 
询问具有[cluster=[cluster]自我的人员]
[
设置amas计数器2
] 
]
设置计数器2计数器2+1
]
结束

哪一行生成错误?您应该只提供相关的代码位-生成错误的过程,可能是使用问题过程的过程。哪一行生成错误?您应该只提供相关的代码位-生成错误的过程,可能是使用问题过程的过程问题的解决过程。