与邻居一起计算品种(绘制)
Counting breeds with neighbors (to plot)
我有两个品种:supras 和 subs。
我想画两条线:
- 拥有超等邻居的订阅者数量(除以总数
海龟数量)
- 邻居数量
是潜艇(除以海龟总数)
我该怎么做?我试过这个:
plot count (subs with [one-of neighbors = supras]) / num-turtles
plot count (supras with [one-of neighbors = subs]) / num-turtles
每个人口的数量总是0,不应该是这样的。这是我的代码:
breed [supras supra]
breed [subs sub]
turtles-own [age]
subs-own [status]
to setup
clear-all
;; Color the patches so they're easier to see
ask patches [ set pcolor random-float 2 ]
;; 1/2 of num-turtles patches will sprout subs
ask n-of (num-turtles / 2) patches [
if not any? turtles-on patch-set self [
sprout-subs 1
]
]
;; 1/2 of num-turtles patches will sprout supras
ask n-of (num-turtles / 2) patches [
if not any? turtles-on patch-set self [
sprout-supras 1
]
]
;; Set breed colors and own-variables
ask subs [
set color blue
set shape "dot"
set age 0
set status random 10
]
ask supras [
set color pink
set shape "dot"
set age 0
]
reset-ticks
end
to go
ask turtles [
let empty-patches neighbors with [not any? turtles-here]
if any? empty-patches[
let target one-of empty-patches
face target
move-to target
]
]
;; Mating conditions
ask supras [
if any? subs-on neighbors [
;; Mate with highest status sub
mate
]
]
tick
end
to mate
move-to max-one-of subs [status]
end
neighbors
returns patches
的代理集,所以说 neighbors = supras
不会得到你需要的东西 - 没有补丁是 supras
或subs
。相反,您想检查是否有任何邻居有 supras-here
或 subs-here
。这对我有用:
plot (count ( subs with [ any? neighbors with [ any? supras-here ] ] ) ) / ( count turtles )
plot (count ( supras with [ any? neighbors with [ any? subs-here ] ] ) ) / ( count turtles )
您可能希望将 Y 最大值缩小到 1 以便看到更多内容。
我有两个品种:supras 和 subs。
我想画两条线:
- 拥有超等邻居的订阅者数量(除以总数 海龟数量)
- 邻居数量 是潜艇(除以海龟总数)
我该怎么做?我试过这个:
plot count (subs with [one-of neighbors = supras]) / num-turtles
plot count (supras with [one-of neighbors = subs]) / num-turtles
每个人口的数量总是0,不应该是这样的。这是我的代码:
breed [supras supra]
breed [subs sub]
turtles-own [age]
subs-own [status]
to setup
clear-all
;; Color the patches so they're easier to see
ask patches [ set pcolor random-float 2 ]
;; 1/2 of num-turtles patches will sprout subs
ask n-of (num-turtles / 2) patches [
if not any? turtles-on patch-set self [
sprout-subs 1
]
]
;; 1/2 of num-turtles patches will sprout supras
ask n-of (num-turtles / 2) patches [
if not any? turtles-on patch-set self [
sprout-supras 1
]
]
;; Set breed colors and own-variables
ask subs [
set color blue
set shape "dot"
set age 0
set status random 10
]
ask supras [
set color pink
set shape "dot"
set age 0
]
reset-ticks
end
to go
ask turtles [
let empty-patches neighbors with [not any? turtles-here]
if any? empty-patches[
let target one-of empty-patches
face target
move-to target
]
]
;; Mating conditions
ask supras [
if any? subs-on neighbors [
;; Mate with highest status sub
mate
]
]
tick
end
to mate
move-to max-one-of subs [status]
end
neighbors
returns patches
的代理集,所以说 neighbors = supras
不会得到你需要的东西 - 没有补丁是 supras
或subs
。相反,您想检查是否有任何邻居有 supras-here
或 subs-here
。这对我有用:
plot (count ( subs with [ any? neighbors with [ any? supras-here ] ] ) ) / ( count turtles )
plot (count ( supras with [ any? neighbors with [ any? subs-here ] ] ) ) / ( count turtles )
您可能希望将 Y 最大值缩小到 1 以便看到更多内容。