MARS

No preview image

1 collaborator

Default-person Junnan Lyu (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.4.0 • Viewed 14 times • Downloaded 0 times • Run 0 times
Download the 'MARS' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

(a general understanding of what the model is trying to show or explain)

HOW IT WORKS

(what rules the agents use to create the overall behavior of the model)

HOW TO USE IT

(how to use the model, including a description of each of the items in the Interface tab)

THINGS TO NOTICE

(suggested things for the user to notice while running the model)

THINGS TO TRY

(suggested things for the user to try to do (move sliders, switches, etc.) with the model)

EXTENDING THE MODEL

(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)

NETLOGO FEATURES

(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)

RELATED MODELS

(models in the NetLogo Models Library and elsewhere which are of related interest)

CREDITS AND REFERENCES

(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GLOBALS, PATCH, AND TURTLE VARIABLES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

globals [
  percent-believers
  percent-similar
  percent-unhappy
]

patches-own [
  region-id

]

turtles-own [
  believer?
  personal-faith
  type-id

  happy?
  similar-nearby
  other-nearby
  total-nearby
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SETUP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all

  ask patches [
    set pcolor white
  ]

  ;; 先设 region-id
  ask patches [
    ;; regions-on? = false → (region-id = 1)
    ;; regions-on? = true  → up area = 1,dlower area = 2
    ifelse regions-on? [
      if pycor > 0  [ set region-id 1 ]
      if pycor <= 0 [ set region-id 2 ]
    ] [
      set region-id 1
    ]
  ]


  ask patches with
    [ pxcor = min-pxcor or pxcor = max-pxcor
      or pycor = min-pycor or pycor = max-pycor ] [
    set pcolor gray + 2
  ]

  ;; turn onregion,the middle gray line is  region boundary
  if regions-on? [
    ask patches with [ pycor = 0 ] [
      set pcolor gray + 1
    ]
  ]


  ask patches [
    if random 100 < density [
      sprout 1 [
        set size 0.9




        let max-type num-types
        if max-type < 1 [ set max-type 1 ]
        if max-type > 4 [ set max-type 4 ]


        let all-types sublist [1 2 3 4] 0 max-type
        let religious-types filter [ t -> t <= 2 ] all-types
        let secular-types   filter [ t -> t >= 3 ] all-types

        ifelse not regions-on? [

          ifelse (random-float 1 < 0.7 and length religious-types > 0)
            [ set type-id one-of religious-types ]
            [ set type-id one-of all-types ]
        ] [

          let r region-id

          if r = 1 [
            ifelse (random-float 1 < 0.7 and length religious-types > 0)
              [ set type-id one-of religious-types ]
              [ set type-id one-of all-types ]
          ]

          if r = 2 [
            ifelse (random-float 1 < 0.7 and length secular-types > 0)
              [ set type-id one-of secular-types ]
              [ set type-id one-of all-types ]
          ]
        ]

        ;; the type-id will made the personal baseline and base on the prob generate the believer or not beliver
        if type-id = 1 [
          set personal-faith 2
          set believer? (random-float 1 < 0.6)
        ]
        if type-id = 2 [
          set personal-faith 0.5
          set believer? (random-float 1 < 0.3)
        ]
        if type-id = 3 [
          set personal-faith -0.5
          set believer? (random-float 1 < 0.2)
        ]
        if type-id = 4 [
          set personal-faith -2
          set believer? (random-float 1 < 0.1)
        ]

        recolor-self
      ]
    ]
  ]

  update-turtles
  update-globals
  reset-ticks
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MAIN LOOP  (MARS-style: move + update one agent)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  if not any? turtles [ stop ]
  if ticks > 5000 [ stop ]


  ask one-of turtles [
    mars-move-and-update
  ]

  update-turtles
  update-globals
  update-plot

  tick
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MOVE + BELIEF UPDATE FOR ONE AGENT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to mars-move-and-update  ;; turtle context

  let my-region [region-id] of patch-here
  let my-belief believer?


  let best-patch patch-here
  let best-score social-score-at patch-here my-belief

  let tries 10
  repeat tries [

    let candidate one-of patches with [
      region-id = my-region and not any? turtles-here
    ]
    if candidate != nobody [
      let score social-score-at candidate my-belief
      if score > best-score [
        set best-score score
        set best-patch candidate
      ]
    ]
  ]


  move-to best-patch

  update-belief-of-self
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; REPORTER: SOCIAL SCORE AT A PATCH FOR A GIVEN BELIEF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to-report social-score-at [ p desired-belief ]


  let nbr-patches [ ifelse-value von-neumann?
                       [ neighbors4 ]
                       [ neighbors ] ] of p

  let nbrs turtles-on nbr-patches

  if not any? nbrs [ report 0 ]

  let same count nbrs with [ believer? = desired-belief ]
  report same / count nbrs
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BELIEF UPDATING  —— utility-based
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to update-beliefs
  ask turtles [ update-belief-of-self ]
end 

to update-belief-of-self  ;; turtle context

  let nbr-patches (ifelse-value von-neumann?
                     [ neighbors4 ]
                     [ neighbors ])
  let nbrs turtles-on nbr-patches

  ;; 2. social-influence
  let social-influence 0
  if any? nbrs [
    set social-influence (count nbrs with [ believer? ]) / count nbrs
  ]


  let my-region region-id


  let u-believe personal-faith
  let u-unbelieve 0


  set u-believe   u-believe   + 0.8 * social-influence
  set u-unbelieve u-unbelieve + 0.8 * (1 - social-influence)

  if regions-on? [
    if my-region = 1 [
      set u-believe u-believe + 0.5
    ]
    if my-region = 2 [
      set u-unbelieve u-unbelieve + 0.5
    ]
  ]


  set u-believe   u-believe   + missionary-rate
  set u-unbelieve u-unbelieve + dropout-rate


  if type-id = 1 or type-id = 2 [
    set u-unbelieve u-unbelieve - 0.7
  ]
  if type-id = 3 or type-id = 4 [
    set u-believe u-believe - 0.7
  ]


  if believer? [
    set u-believe u-believe + 0.5
  ]
  if not believer? [
    set u-unbelieve u-unbelieve + 0.5
  ]


  set u-believe   u-believe   + random-float 0.0001
  set u-unbelieve u-unbelieve + random-float 0.0001


  if u-believe > u-unbelieve [
    set believer? true
  ]
  if u-unbelieve > u-believe [
    set believer? false
  ]


  recolor-self
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NEIGHBOR STATS / HAPPINESS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to update-turtles
  ask turtles [
    let nbr-patches (ifelse-value von-neumann?
                       [ neighbors4 ]
                       [ neighbors ])
    let nbrs turtles-on nbr-patches

    set similar-nearby count nbrs with [ believer? = [ believer? ] of myself ]
    set other-nearby   count nbrs with [ believer? != [ believer? ] of myself ]
    set total-nearby   similar-nearby + other-nearby

    if total-nearby = 0 [
      set happy? true
    ]
    if total-nearby > 0 [
      set happy? similar-nearby >= (%-similar-wanted * total-nearby / 100)
    ]

    set size 0.9
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; COLOR (type) + SHAPE (belief)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to recolor-self

  if type-id = 1 [ set color green  ]
  if type-id = 2 [ set color yellow ]
  if type-id = 3 [ set color orange ]
  if type-id = 4 [ set color violet ]


  if believer? [
    set shape "circle"
  ]
  if not believer? [
    set shape "X"
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GLOBAL METRICS & PLOT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to update-globals
  let total count turtles
  if total = 0 [
    set percent-believers 0
    set percent-similar 0
    set percent-unhappy 0
    stop
  ]

  set percent-believers 100 * (count turtles with [ believer? ]) / total

  let similar-neighbors sum [ similar-nearby ] of turtles
  let total-neighbors   sum [ total-nearby ] of turtles
  if total-neighbors > 0 [
    set percent-similar 100 * similar-neighbors / total-neighbors
  ]

  set percent-unhappy 100 * (count turtles with [ not happy? ]) / total
end 

to update-plot
  set-current-plot "Believer Share"
  set-plot-y-range 0 100
  set-current-plot-pen "share"
  plotxy ticks percent-believers
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; UTILITY FUNCTIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to-report clamp01 [x]
  if x < 0 [ report 0 ]
  if x > 1 [ report 1 ]
  report x
end 

to-report logistic [x]
  report 1 / (1 + exp (- x))
end 

There is only one version of this model, created 4 days ago by Junnan Lyu.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.