首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编辑NetLogo Rebellion代码-威胁-预期输入是海龟代理集或补丁代理集或海龟或补丁,但得到的数字为0

编辑NetLogo Rebellion代码-威胁-预期输入是海龟代理集或补丁代理集或海龟或补丁,但得到的数字为0
EN

Stack Overflow用户
提问于 2020-03-28 19:45:27
回答 1查看 48关注 0票数 0

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

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2020-03-29 01:58:28

首先,建议:将代码块复制到Stack Overflow问题或答案中时,应将其格式化为代码块。以这种方式阅读起来要容易得多()。

您遇到的问题是因为patches-own变量neighborhood尚未初始化,因此NetLogo使用数字0作为默认值。在修改库的叛逆代码时,您删除了第4行和第5行

代码语言:javascript
复制
  ask patches [
    ; make background a slightly dark gray
    set pcolor gray - 1
    ; cache patch neighborhoods
    set neighborhood patches in-radius vision
  ]

初始化每个补丁的neighborhood变量的setup中的行。将它们添加回来应该会处理您遇到的错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60900717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档