编辑 NetLogo 叛乱代码 - 威胁 - ON 预期输入是海龟代理集或补丁代理集或或补丁,但得到数字 0



我正在尝试使用模型库中的叛乱模型作为联盟形成模型的模板,但仍然遇到问题 使模型运行..

breed [ agents an-agent]
breed [ threats threat ]
globals [
k                   ; factor for determining attack probability
threshold           ; by how much must D - BS > A to make a state burden share
]
agents-own [
conflict-aversion   ; R, fixed for the agent's lifetime, ranging from 0-1 (inclusive)
perceived-threat    ; T, also ranging from 0-1 (inclusive)
active?             ; if true, then the agent is actively burden-sharing
; if false, then the agent is free-riding
conflict            ; how many turns in conflict remain? (if 0, the agent is not in conflict)
]
patches-own [
neighborhood        ; surrounding patches within the vision radius
]
to setup
clear-all
; set globals
set k 2.3
set threshold 0.1
ask patches [
; make background a slightly dark gray
set pcolor gray - 1
]
if initial-threats-density + initial-agent-density > 206 [
user-message (word
"The sum of INITIAL-THREATS-DENSITY and INITIAL-AGENT-DENSITY "
"should not be greater than 206.")
stop
]
; create threats
create-threats round (initial-threats-density * .01 * count patches) [
move-to one-of patches with [ not any? turtles-here ]
display-threats
]
; create agents
create-agents round (initial-agent-density * .01 * count patches) [
move-to one-of patches with [ not any? turtles-here ]
set heading 0
set conflict-aversion random-float 1.0
set perceived-threat random-float 1.0
set active? false
set conflict 0
display-agent
]

; start clock and plot initial state of system
reset-ticks
end
to go
ask turtles [
; Rule M: Move to a random site within your vision
if (breed = agents and conflict = 0) or breed = threats [move]
;   Rule A: Determine if each agent should be active or quiet
if breed = agents and conflict = 0 [ determine-behavior ]
;  Rule C: Threats attack a random active agent within their radius
if breed = threats [ attack ]
]
; Agents engaged in conflict have the duration reduced at the end of each clock tick
ask agents [ if conflict > 0 [ set conflict conflict - 1 ] ]
; update agent display
ask agents [ display-agent ]
ask threats [ display-threats ]
; advance clock and update plots
tick
end
; AGENT AND THREAT BEHAVIOR
; move to an empty patch
to move ; turtle procedure
if movement? or breed = threats [
; move to a patch in vision; candidate patches are
; empty or contain only jailed agents
let targets neighborhood with [
not any? threats-here and all? agents-here [ conflict > 0 ]
]
if any? targets [ move-to one-of targets ]
]
end
; AGENT BEHAVIOR
to determine-behavior
set active? (burden-sharing - conflict-aversion * estimated-conflict-probability > threshold)
end
to-report burden-sharing
report perceived-threat * (1 - alliance-protection)
end

to-report estimated-conflict-probability
let t count (threats-on neighborhood)
let a 1 + count (agents-on neighborhood) with [ active? ]
; See Info tab for a discussion of the following formula
report 1 - exp (- k * floor (t / a))
end
; THREAT BEHAVIOR
to attack
if any? (agents-on neighborhood) with [ active? ] [
; arrest suspect
let suspect one-of (agents-on neighborhood) with [ active? ]
move-to suspect  ; move to patch of the jailed agent
ask suspect [
set active? false
set conflict random max conflict
]
]
end
; VISUALIZATION OF AGENTS AND COPS
to display-agent  ; agent procedure
set color cyan
set shape "triangle"
end
to display-threats
set color red
set shape "circle 2"
end


; Copyright 2004 Uri Wilensky.
; See Info tab for full copyright and license.

首先,一个建议:当您将代码块复制到 Stack Overflow 问题或答案中时,您应该将其格式化为代码块。这样阅读要容易得多

您遇到的问题是因为补丁自己的变量neighborhood尚未初始化,因此NetLogo使用数字零作为默认值。在修改图书馆的反叛代码时,您删除了第 4 行和第 5 行

ask patches [
; make background a slightly dark gray
set pcolor gray - 1
; cache patch neighborhoods
set neighborhood patches in-radius vision
]

setup中初始化每个修补程序的neighborhood变量的行。重新添加它们应该可以解决您遇到的错误。

最新更新