Diminished F’NF

Diminished F’NF preview image

1 collaborator

Cosimo.leuci Cosimo Leuci (Author)

Tags

ecological economics 

Tagged by Cosimo Leuci about 1 year ago

efficiency 

Tagged by Cosimo Leuci about 1 year ago

el farol 

Tagged by Cosimo Leuci about 1 year ago

equity 

Tagged by Cosimo Leuci about 1 year ago

genetic algorithms 

Tagged by Cosimo Leuci about 1 year ago

Child of model Flibs'NFarol preview imageFlibs'NFarol
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.3.0 • Viewed 173 times • Downloaded 5 times • Run 0 times
Download the 'Diminished F’NF' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

;;  _________________________________________________________________________________________________________________
;;
;;  ----------------------   Diminished-F'NF   ----------------------------------------------------   Diminished-F'NF
;;  Diminished-F'NF   ------------------------------------------------   Diminished-F'NF   --------------------------
;;  _________________________________________________________________________________________________________________



breed     [flibs flib]     ;; FLiBs (finite living blobs) are the agents of the model: they are structured as
                           ;; one state finite automata. A binary input signal coming from the previous state of
                           ;; the environment (1 if the bar was crowded, 0 if not) causes it to generates binary
                           ;; signals as a decision to go or not to go. Four strategies are possible.


flibs-own [chromosome      ;; every flib owns a chromosome, that is a string codifying one of the four schema
           state           ;; the current inner state of the flib: it is always 0
           choice          ;; choice/prevision expressed by the flib regarding to go or not to go to the bar
           fitness         ;; a measure of flibs' prevision ability to forestall if the bar will be crowded or not
           ]


globals  [tot_attend        ;; total of attendances during one season to "El Farol" bar (i.e. 100 cycles tournement)
          sigma_attend      ;; an accumulator for the previous variable
          crowded           ;; a switch recording the state of the bar: 1 if crowded, 0 if not
          lorenz-points     ;; list of the Lorenz curve ordinates
          gini-index-reserve;; counter functional to the calculation of the Gini index
          sigma-gini        ;; an accumulator for the previous variable
          best              ;; the best flibs fitness value
          worst             ;; the worst flibs fitness value
          ]


;;  ----------   SETUP PROCEDURES   ----------------------------------------------------------------------------------
;;  ------------------------------------------------------------------------------------------------------------------

to setup           ;; initializing the model
  clear-all
  ;; create the bar area (yellow) and an elsewhere (blue)
  ask patches  [set pcolor blue - 3]
  ask patches with [abs pxcor < 10 and abs pycor < 7] [set pcolor yellow]
  ask patches with [pxcor = 9 and pycor = 7] [set plabel ["El Farol Bar"]]
  ask patches with [pxcor = 21 and pycor = -21] [set plabel ["Elsewhere"]]

  ;; create the flibs and give them a random chromosome
  ask n-of num-flibs patches [sprout-flibs 1 [
    set shape "flib"
    set color white
    set size 2

    set chromosome one-of chrom-couple
    ]
  ]
  reset-ticks
end 



;;  ----------   RUNTIME PROCEDURES   --------------------------------------------------------------------------------
;;  ------------------------------------------------------------------------------------------------------------------

to go
  set tot_attend 0
  ask flibs [set fitness 0 set state 0]

  repeat 100 [el-farol] ;; a 100 cycles tournament could be seen as a season to "El Farol" bar (i.e. 100 evenings)

  if sum [fitness] of flibs = 0 [  ;; no fitness no progress
    show "fitness null for every flibs"
    stop
  ]
  analyse   ;; some relevant "El Farol" seasonal results are picked and processed
  ask flibs [move] ;; the world displays a snapshot of the bar after the last evening of the season

  if best != worst[ ;; after every season, one cloning event can occur: the process is partly selective
    ask one-of flibs with [fitness = worst]
      [set chromosome one-of chrom-couple
    ]
  ]
  tick
end 


;; ONE SEASON TO EL FAROL BAR
;; -------------------------------------------------------------------------------------------------------------------

to el-farol
  let attendance 0    ;; the variable records the fraction of agents attending the bar during one evening
  flibs-behaviour
  ;; bar attendance is the sum of every flibs' choices
  set attendance sum [choice] of flibs / num-flibs
  ;; comparing the attendance and the threshold value, the (over)crowded state of the bar is determined
  if attendance >= threshold [set crowded 1    ;; if the bar is crowded, reward the flibs that are elsewhere
    ask flibs with [choice = 0] [set fitness fitness + EW_reward] ]
  if attendance < threshold [set crowded 0  ;; if the bar is not crowded, reward the flibs that are attending
    ask flibs with [choice = 1] [set fitness fitness + 1] ]
  set tot_attend tot_attend + attendance ;; the results of every evening of a season is added up
end 

to flibs-behaviour
  ask flibs [
    ;; each flib processes its choice (to go or not to go)
    set choice read-from-string item (2 * crowded) chromosome
  ]
end 

to analyse
  set best max [fitness] of flibs
  set worst min [fitness] of flibs
  ask flibs [set color scale-color red fitness 100 0]
  set sigma_attend sigma_attend + tot_attend / 100
  update-lorenz-and-gini
end 

to update-lorenz-and-gini  ;; borrowed from Wilensky's model "Wealth Distribution"
  let sorted-comfort sort [fitness] of flibs
  let total-comfort sum sorted-comfort
  let comfort-sum-so-far 0
  let index 0
  set gini-index-reserve 0
  set lorenz-points []
  repeat num-flibs [
    set comfort-sum-so-far (comfort-sum-so-far + item index sorted-comfort)
    set lorenz-points lput ((comfort-sum-so-far / total-comfort) * 100) lorenz-points
    set index (index + 1)
    set gini-index-reserve
      gini-index-reserve +
      (index / num-flibs) -
      (comfort-sum-so-far / total-comfort)
    ]
  set sigma-gini sigma-gini + ((gini-index-reserve / num-flibs) * 2)
end 

to move
  ifelse choice = 0
      [move-to one-of patches with [pcolor = blue - 3]]
    [move-to one-of patches with [pcolor = yellow]]
end 



; Copyright 2023 Cosimo Leuci.
; See Info tab for full copyright and license.

There is only one version of this model, created about 1 year ago by Cosimo Leuci.

Attached files

File Type Description Last updated
Diminished F’NF.png preview preview_image about 1 year ago, by Cosimo Leuci Download

Parent: Flibs'NFarol

This model does not have any descendants.

Graph of models related to 'Diminished F’NF'