Заставить агентов в модели Rebellion двигаться - PullRequest
0 голосов
/ 21 апреля 2020

Я работаю над финальным проектом для моего класса моделирования на основе агентов. Я пытаюсь построить модель, которая показывает, как союзы формируются в ответ на угрозы. Я собрал воедино элементы других моделей, в первую очередь используя модель Rebellion, но я бы хотел, чтобы агенты группировались или были «союзниками» в ответ на долю угроз, пожалуйста, помогите. Прямо сейчас они просто остаются на месте - я хочу, чтобы они двигались навстречу друг другу, что затем сдерживает угрозы.

breed [ agents an-agent ]
breed [ threats threat ]

globals [
  k                   ; factor for determining arrest probability
  threshold           ; by how much must T > D to make someone allyl?


]

agents-own [
  risk-aversion       ; R, fixed for the agent's lifetime, ranging from 0-1 (inclusive)
  perceived-threat  ; H, also ranging from 0-1 (inclusive)
  active?             ; if true, then the agent is actively engaging threat


]

patches-own [
  neighborhood        ; surrounding patches within the vision radius
]

to setup
  clear-all

  ; set globals
  set k 2.3


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

  if initial-threat-density + initial-agent-density > 100 [
    user-message (word
      "The sum of INITIAL-THREAT-DENSITY and INITIAL-AGENT-DENSITY "
      "should not be greater than 100.")
    stop
  ]

  ; create threats
  create-threats round (initial-threat-density * .01 * count patches) [
    move-to one-of patches with [ not any? turtles-here ]
    display-threat
  ]

  ; create agents
  create-agents round (initial-agent-density * .01 * count patches) [
    move-to one-of patches with [ any? turtles-here ]
    set heading 0
    set risk-aversion random-float 1.0
    set perceived-threat random-float 1.0
    set active? false
    set conflict-term 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-term = 0) or breed = threats [ move ]
    ;   Rule A: Determine if each agent should be active or quiet
    if breed = agents and conflict-term = 0 [ determine-behavior ]
    ;  Rule C: Threats arrest a random active agent within their radius
    if breed = threats [ enforce ]
  ]
  ; Conflicted agents get their term reduced at the end of each clock tick
  ask agents [ if conflict-term > 0 [ set conflict-term conflict-term - 1 ] ]
  ; update agent display
  ask agents [ display-agent ]
  ask threats [ display-threat ]
  ; 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 conflicted agents
    let targets neighborhood with [
      not any? threats-here and all? agents-here [ conflict-term > 0 ]
    ]
    if any? targets [ move-to one-of targets ]
  ]
end

; AGENT BEHAVIOR

to determine-behavior
  set active? (grievance - risk-aversion * estimated-arrest-probability > threshold)
end

to-report grievance
  report perceived-threat * (1 - alliance-legitimacy)
end

to-report estimated-arrest-probability
  let c 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 (c / a))
end

; THREAT BEHAVIOR

to enforce
  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 conflicted agent
    ask suspect [
      set active? false
      set conflict-term random conflict-term
    ]
  ]
end

; VISUALIZATION OF AGENTS AND THREATS

to display-agent  ; agent procedure
  ifelse visualization = "2D"
    [ display-agent-2d ]
    [ display-agent-3d ]
end

to display-agent-2d  ; agent procedure
  set shape "circle"
  ifelse active?
    [ set color red ]
    [ ifelse conflict-term > 0
        [ set color black + 3 ]
        [ set color scale-color green grievance 1.5 -0.5 ] ]
end

to display-agent-3d  ; agent procedure
  set color scale-color green grievance 1.5 -0.5
  ifelse active?
    [ set shape "face happy" ]
    [ ifelse conflict-term > 0
        [ set shape "face sad" ]
        [ set shape "face neutral" ] ]
end

to display-threat
  set color cyan
  ifelse visualization = "2D"
    [ set shape "triangle" ]
    [ set shape "circle 2" ]
end

...