我如何使模型运行?

问题描述 投票:0回答:1

我本质上是试图将“隔离”模型和“叛乱”模型的元素结合起来,以形成代表联盟形成的模型。

这里是到目前为止,我尝试运行它时收到错误消息:THREATS品种不拥有变量ACTIVE?威胁0运行为活动时出错?通过过程GO调用由Button'go'调用]

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
  percent-similar  ; on the average, what percent of a turtle's neighbors
                   ; are the same color as that turtle? Likely to ally
  percent-unhappy  ; what percent of the turtles are unhappy? Or percieve threats?
visualization 
]



agents-own [
  allied-states   ; R, fixed for the agent's lifetime, ranging from 0-1 (inclusive)- for each turtle, indicates whether at least %-similar-wanted percent of
                   ;   that turtle's neighbors are the same color as the turtle

  perceived-threat    ; T, also ranging from 0-1 (inclusive)- how many have a turtle of another color?
  active?             ; if true, then the agent is actively allied 
                      ; if false, then the agent is free-riding
  conflict            ; how many turns in conflict remain? (if 0, the agent is not in conflict)- sum of previous two variables
total-nearby            ; sum of previous two variables
]

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
    ; cache patch neighborhoods
    set neighborhood patches in-radius vision
  ]

  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 allied-states 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
  if all? turtles [ active? ] [ stop ]
  move-unhappy-turtles
  update-turtles
  update-globals
  tick
end

; unhappy turtles try a new spot
to move-unhappy-turtles
  ask turtles with [ not active? ]
    [ find-new-spot ]
end

; move until we find an unoccupied spot
to find-new-spot
  rt random-float 360
  fd random-float 10
  if any? other turtles-here [ find-new-spot ] ; keep going until we find an unoccupied patch
  move-to patch-here  ; move to center of patch
end

to update-turtles
  ask turtles [
    ; in next two lines, we use "neighbors" to test the eight patches
    ; surrounding the current patch
    set allied-states count (turtles-on neighbors)  with [ color = [ color ] of myself ]
    set perceived-threat count (turtles-on neighbors) with [ color != [ color ] of myself ]
    set total-nearby allied-states + perceived-threat
    set active? allied-states >= (percent-similar * total-nearby / 100)
    ; add visualization here
    if visualization = "old" [ set shape "default" set size 1.3 ]
    if visualization = "square-x" [
      ifelse active? [ set shape "square" ] [ set shape "X" ]
    ]
  ]
end

to update-globals 
  let similar-neighbors sum [ allied-states ] of turtles
  let total-neighbors sum [ total-nearby ] of turtles
  set percent-similar (similar-neighbors / total-neighbors) * 100
  set percent-unhappy (count turtles with [ not active? ]) / (count turtles) * 100

  ; 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 - allied-states * 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

to alliance
  if any? threats [attack]
  set active? true
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 conflict-term
      set color pink
    ]
  ]
end

; VISUALIZATION OF AGENTS AND COPS

to display-agent  ; agent procedure
 set color cyan
    set shape "triangle"
end

to display-active?
  set color pink
  set shape "triangle"
end

to display-threats
  set color red
  set shape "circle 2"
end
go netlogo modeling agent agent-based-modeling
1个回答
0
投票

问题是您有两种乌龟,agentsthreats,只有agents“拥有”变量activeturtles是所有品种的超集,因此,当all?原语尝试查询字面上所有乌龟的active?变量时,它也会尝试在active?中查询threats,但找不到它。该行应为

if all? agents [ active? ] [ stop ]

希望这会有所帮助,查尔斯

© www.soinside.com 2019 - 2024. All rights reserved.