Редактирование NetLo go Rebellion Code - THREATS-ON предполагал, что вводом будет набор агентов черепах или набор патчей, или черепаха, или патч, но вместо этого он получил число 0 - PullRequest
0 голосов
/ 28 марта 2020

Я пытаюсь использовать модель восстания из библиотеки моделей в качестве шаблона для модели формирования альянса, но все еще сталкиваюсь с проблемами при запуске модели ..

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.

1 Ответ

1 голос
/ 28 марта 2020

Во-первых, предложение: когда вы копируете блок кода в вопрос или ответ о переполнении стека, вы должны отформатировать его как блок кода. Это намного легче читать таким образом.

Проблема, с которой вы сталкиваетесь, заключается в том, что собственная переменная neighborhood для исправлений не была инициализирована, и поэтому NetLo go использует номер ноль в качестве значения по умолчанию. При изменении кода восстания библиотеки вы сбросили 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 каждого патча. Добавление их обратно должно устранить ошибку, с которой вы столкнулись.

Надеюсь, это поможет, Чарльз

...