1

I am essentially trying to combine elements of the 'Segregation' model and 'Rebellion' model to form a model that is representative of alliance forming.

Here is what I have so far- when I attempt to run it I receive the error: THREATS breed does not own variable ACTIVE? error while threat 0 running ACTIVE? called by procedure GO called by 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
Charlie Tumahai
  • 113,709
  • 12
  • 249
  • 242
Cfitzg
  • 11
  • 1

1 Answers1

2

The problem is that you have two breeds of turtles, agents and threats, and only agents "own" the variable active?. turtles is a superset of all breeds, so when the all? primitive tries to query the active? variable of literally all turtles, it tries to query active? for threats too, and can't find it. The line should be

if all? agents [ active? ] [ stop ]
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Charles
  • 3,888
  • 11
  • 13