Lascaux ABM

No preview image

1 collaborator

Default-person MAURIZIO FORTE (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 3D 7.0.0 • Viewed 2 times • Downloaded 1 time • Run 0 times
Download the 'Lascaux ABM' 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

; === Lascaux Cave ABM — NetLogo 3D Stable Version ===
; Agents move inside the cave corridors and paint motifs on walls.
; Plots update dynamically and all data export safely to CSV.

globals [
  motif-types
  motif-colors
  encounter-totals
  zones
  zone-paint-bias
  log-file
  logging?
]

patches-own [
  walkable?
  wall?
  motif
  zone
]

turtles-own [
  memory
]

; ------------------------------------------------------
; SETUP
; ------------------------------------------------------

to setup
  clear-all
  clear-drawing
  clear-all-plots
  setup-world3d
  setup-agents3d
  set logging? false         ;; ensures NOT error never happens
  reset-ticks
end 

to setup-world3d
  import-pcolors "lascaux-mask.png"   ;; black = corridor, white = rock

  ask patches [
    set walkable? false
    set wall? false
    set motif ""
    set zone "Other"

    if pcolor = white [ set walkable? false set pcolor brown + 2 ]
    if pcolor = black [ set walkable? true  set pcolor gray + 1 ]
  ]

  ask patches with [pzcor = 0 and walkable?] [
    set wall? any? neighbors4 with [pzcor = 0 and not walkable?]
  ]

  set motif-types  ["bison" "horse" "deer" "sign" "hand"]
  set motif-colors [red     blue    green  violet orange]
  set encounter-totals n-values length motif-types [0]

  ask patches with [pzcor = 0 and walkable?] [
    if pxcor <  -30 and pycor >  20 [ set zone "Entrance" ]
    if pxcor <  -10 and pycor <   0 [ set zone "Apse" ]
    if pxcor <   10 and pycor >  20 [ set zone "Hall of Bulls" ]
    if pxcor >   30 and pycor >  20 [ set zone "Axial Gallery" ]
    if pxcor >   15 and pycor <   5 [ set zone "Passageway" ]
    if pxcor >    5 and pycor < -15 [ set zone "Nave" ]
    if pxcor >   10 and pycor < -35 [ set zone "Mondmilch Gallery" ]
    if pxcor >   25 and pycor < -55 [ set zone "Chamber of Felines" ]
  ]

  set zones ["Entrance" "Hall of Bulls" "Apse" "Axial Gallery"
             "Passageway" "Nave" "Mondmilch Gallery" "Chamber of Felines" "Other"]

  set zone-paint-bias [
    ["Entrance"           0.005]
    ["Hall of Bulls"      0.05]
    ["Apse"               0.08]
    ["Axial Gallery"      0.04]
    ["Passageway"         0.01]
    ["Nave"               0.03]
    ["Mondmilch Gallery"  0.015]
    ["Chamber of Felines" 0.02]
    ["Other"              0.005]
  ]
end 

to setup-agents3d
  create-turtles num-agents [
    set color yellow
    set size 3
    set shape "person"
    set memory []
    set pitch 0
    set roll 0
    let start one-of patches with [pzcor = 0 and walkable? and not any? neighbors4 with [not walkable?]]
    if start = nobody [ set start one-of patches with [pzcor = 0 and walkable?] ]
    setxy [pxcor] of start [pycor] of start
    set zcor 0.2
    set heading random 360
  ]
end 

; ------------------------------------------------------
; GO LOOP
; ------------------------------------------------------

to go
  if not is-list? motif-types [ user-message "Click setup first." stop ]
  if not is-list? zones [ user-message "Click setup first." stop ]

  ask turtles [
    wander3d
    look-around3d
    maybe-paint3d
  ]

  update-plots3d
  log-data
  tick
end 

; ------------------------------------------------------
; MOVEMENT + BEHAVIOR
; ------------------------------------------------------

to wander3d
  rt (random 60 - random 60)
  if [pzcor] of patch-here != 0 [ set zcor 0.2 ]
  if not [walkable?] of patch-ahead 1 [ rt 180 fd 0.5 ]
  fd 1
  if not [walkable?] of patch-here [
    let nearest one-of patches in-radius 3 with [walkable?]
    if nearest != nobody [ move-to nearest set zcor 0.2 ]
  ]
  set zcor 0.2
end 

to look-around3d
  let seen (patches in-cone torch-range vision-angle) with [pzcor = 0]
  let seen-motifs [motif] of (seen with [motif != ""])
  if not empty? seen-motifs [
    foreach motif-types [ m ->
      let count-seen length filter [x -> x = m] seen-motifs
      if count-seen > 0 [
        let idx position m motif-types
        if idx != false [
          set encounter-totals replace-item idx encounter-totals ((item idx encounter-totals) + count-seen)
        ]
      ]
    ]
    if random-float 1 < 0.3 [ set memory lput one-of seen-motifs memory ]
  ]
end 

to maybe-paint3d
  if ([pzcor] of patch-here = 0) and ([wall?] of patch-here) and ([motif] of patch-here = "") [
    let my-zone [zone] of patch-here
    let base-rate paint-prob-base
    let zone-bias 0
    let found filter [pair -> item 0 pair = my-zone] zone-paint-bias
    if not empty? found [ set zone-bias item 1 first found ]
    let final-prob base-rate + zone-bias
    if random-float 1 < final-prob [
      let m ""
      if (not empty? memory) and random-float 1 < copy-bias [ set m one-of memory ]
      if random-float 1 < innovation-rate [ set m one-of motif-types ]
      if m != "" [
        ask patch-here [
          set motif m
          set pcolor motif-color3d m
        ]
      ]
    ]
  ]
end 

to-report motif-color3d [m]
  let i position m motif-types
  if i = false [ report yellow ]
  report item i motif-colors
end 

; ------------------------------------------------------
; DATA LOGGING
; ------------------------------------------------------

to start-logging [filename]
  file-close-all
  set log-file filename
  file-open log-file
  set logging? true
  file-print (word "tick,"
                    "num-agents,"
                    "paint-prob-base,"
                    "innovation-rate,"
                    "copy-bias,"
                    "agents-inside,"
                    "agents-outside,"
                    "motifs-painted,"
                    "diversity")
end 

to log-data
  ;; Safe guard: only run when logging? is true
  if (not is-boolean? logging?) [ set logging? false ]
  if not logging? [ stop ]

  let inside count turtles with [[walkable?] of patch-here]
  let outside count turtles with [not [walkable?] of patch-here]
  let motifs-painted count patches with [pzcor = 0 and motif != ""]
  let diversity shannon-diversity

  file-print (word ticks "," count turtles "," paint-prob-base "," innovation-rate "," copy-bias ","
                   inside "," outside "," motifs-painted "," diversity)
end 

to stop-logging
  if logging? [
    file-close
    set logging? false
    export-my-plots
    export-metadata
  ]
end 

to-report shannon-diversity
  let n count patches with [pzcor = 0 and motif != ""]
  if n = 0 [ report 0 ]
  let motifs [motif] of patches with [pzcor = 0 and motif != ""]
  let H 0
  foreach motif-types [m ->
    let p (length filter [x -> x = m] motifs) / n
    if p > 0 [ set H H - (p * ln p) ]
  ]
  report H
end 

; ------------------------------------------------------
; PLOTTING
; ------------------------------------------------------

to plot-safe [plot-title pen-title pen-color value]
  carefully [
    set-current-plot plot-title
    carefully [
      set-current-plot-pen pen-title
    ] [
      create-temporary-plot-pen pen-title
      set-current-plot-pen pen-title
    ]
    set-plot-pen-color pen-color
    plot value
  ] []
end 

to update-plots3d
  let motif-pairs [["bison" red] ["horse" blue] ["deer" green] ["sign" violet] ["hand" orange]]

  foreach motif-pairs [ mp ->
    let m item 0 mp
    let c item 1 mp
    plot-safe "Motif Frequencies" m c (count patches with [pzcor = 0 and motif = m])
  ]

  plot-safe "Motifs Painted Over Time" "total" red (count patches with [pzcor = 0 and motif != ""])

  let i 0
  foreach motif-pairs [ mp ->
    let m item 0 mp
    let c item 1 mp
    plot-safe "Encounter Rates" m c (item i encounter-totals)
    set i i + 1
  ]

  let chambers ["Entrance" "Hall of Bulls" "Apse" "Axial Gallery"
                "Passageway" "Nave" "Mondmilch Gallery" "Chamber of Felines" "Other"]
  let chamber-colors [red blue green violet orange cyan sky gray pink]
  let j 0
  foreach chambers [ z ->
    plot-safe "Motifs by Chamber" z (item (j mod length chamber-colors) chamber-colors)
      (count patches with [pzcor = 0 and zone = z and motif != ""])
    set j j + 1
  ]

  plot-safe "Agent Count" "count" black (count turtles)
end 

; ------------------------------------------------------
; CUSTOM CSV EXPORT HELPERS
; ------------------------------------------------------

to export-my-plots
  let tag (word "t" ticks)

  carefully [ export-plot "Motif Frequencies"        (word "plot_motif_frequencies_"        tag ".csv") ] []
  carefully [ export-plot "Motifs Painted Over Time" (word "plot_motifs_painted_"           tag ".csv") ] []
  carefully [ export-plot "Encounter Rates"          (word "plot_encounter_rates_"          tag ".csv") ] []
  carefully [ export-plot "Motifs by Chamber"        (word "plot_motifs_by_chamber_"        tag ".csv") ] []
  carefully [ export-plot "Agent Count"              (word "plot_agent_count_"              tag ".csv") ] []
end 

to export-metadata
  let tag (word "t" ticks)
  file-open (word "run_metadata_" tag ".csv")
  file-print "key,value"
  file-print (word "ticks," ticks)
  file-print (word "num-agents," count turtles)
  file-print (word "paint-prob-base," paint-prob-base)
  file-print (word "innovation-rate," innovation-rate)
  file-print (word "copy-bias," copy-bias)
  file-close
end 

There is only one version of this model, created 2 days ago by MAURIZIO FORTE.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.