Musical Chairs

Musical Chairs preview image

1 collaborator

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.2.0 • Viewed 202 times • Downloaded 19 times • Run 0 times
Download the 'Musical Chairs' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; GNU GENERAL PUBLIC LICENSE ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;  The Musical Chairs model - A model of the interaction between farming and herding
;;  Copyright (C) 2013 Andreas Angourakis (andros.spica@gmail.com)
;;
;;  This program is free software: you can redistribute it and/or modify
;;  it under the terms of the GNU General Public License as published by
;;  the Free Software Foundation, either version 3 of the License, or
;;  (at your option) any later version.
;;
;;  This program is distributed in the hope that it will be useful,
;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;  GNU General Public License for more details.
;;
;;  You should have received a copy of the GNU General Public License
;;  along with this program.  If not, see .

;;;;;;;;;;;;;;;;;
;;; VARIABLES ;;;
;;;;;;;;;;;;;;;;;

globals
[  
  ;;; modified parameters
  intGrowthF intGrowthH extGrowthF extGrowthH 
  initH initF
  h_r_m_i intgH intgF
  
  ;;; sets of agents that exists at the end of each run
  settledFarmingAgents stableHerdingAgents
  
  ;;; unlucky agents, their respective number of helpers and their intensity
  unluckyF farmingSupport farmingIntensity
  unluckyH herdingSupport herdingIntensity
  
  ;;; variables used in resolve_conflict
  index_of_opportunity ratio_of_intensities 
  incentives_to_relinquish
  
  ;;; counters and final measures
  AREA
  dilemmaEvents oasisDegressionEvents herdingSuccessRatio
  farmingGrowth farmingDeterrence herdingGrowth herdingDeterrence farmingBalance herdingBalance
  farming_histo_intensity_0_025 farming_histo_intensity_025_05 farming_histo_intensity_05_075 farming_histo_intensity_075_1
  farming_histo_independence_0_025 farming_histo_independence_025_05 farming_histo_independence_05_075 farming_histo_independence_075_1
  herding_histo_intensity_0_025 herding_histo_intensity_025_05 herding_histo_intensity_05_075 herding_histo_intensity_075_1
  herding_histo_independence_0_025 herding_histo_independence_025_05 herding_histo_independence_05_075 herding_histo_independence_075_1
  mean_fint mean_find mean_hint mean_hind
]

;;; establishes the classes of agents and their variables

breed [ farming_agents farming_agent ]

breed [ herding_agents herder_agent ]

farming_agents-own [ intensity independence ]

herding_agents-own [ intensity independence ]

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

to setup
  
  clear-all
  
  ;;; setup parameters depending on the type of experiment
  ifelse (random_exp? = true) 
  [
    set intGrowthF random-float farming_intrinsic_growth_rate
    set extGrowthF random-float farming_extrinsic_growth_rate
    set intgF random-float farming_integration
    set intGrowthH random-float herding_intrinsic_growth_rate
    set extGrowthH random-float herding_extrinsic_growth_rate
    set intgH random-float herding_integration
    set initH random init_herding
    set initF random init_farming
    set h_r_m_i ((1 + (random-float 10) ) / (1 + (random-float 10) )) ;; set a random value between 0.1 and 10 (around 1)
  ]
  [ 
    set intGrowthF farming_intrinsic_growth_rate
    set extGrowthF farming_extrinsic_growth_rate
    set intgF farming_integration
    set intGrowthH herding_intrinsic_growth_rate
    set extGrowthH herding_extrinsic_growth_rate
    set intgH herding_integration
    set initH init_herding
    set initF init_farming
    set h_r_m_i herding_relative_max_intensity
  ]

  ;;; create agents according to the parameter setting (position is arbitrary and has no consequence)
  ask patch 0 0
  [
    sprout-herding_agents initH [ initialize-an-agent ]
  ]
  ask patch max-pxcor 0
  [ 
    sprout-farming_agents initF [ initialize-an-agent ]
  ]
  
  ;;; initialize visualization
  ask patches [ set pcolor yellow ]
  
  update_visualization
  
  set dilemmaEvents 0 ;reset dilemma_events counter
  set oasisDegressionEvents 0 ;reset oasis_degression_events counter
  
  reset-ticks
end 

to initialize-an-agent
  
  set hidden? true
  ifelse (breed = farming_agents)
  [ set intensity random-float farming_max_intensity ]
  [ set intensity random-float (farming_max_intensity * h_r_m_i) ]
  set independence (random-float 1)
end 

to go
  
  farming_expansion
  
  herding_expansion
  
  ;reset dilemma_events and oasis_degression_events counters
  set dilemmaEvents 0 
  set oasisDegressionEvents 0
  
  check_competition
  
  update_visualization
  
  tick
end 

to farming_expansion
  
    ;;; set of farming_agents currently present
  set settledFarmingAgents turtle-set farming_agents
  
  ;;; reset counters
  set farmingGrowth 0
  set farmingDeterrence 0
  
  ;;; Intrinsic growth
  ask settledFarmingAgents
  [ if ( random-float 1 <= intGrowthF )
    [ 
      hatch 1
      set farmingGrowth farmingGrowth + 1
    ]
  ]
  
  ;;; Extrinsic growth
  ask patch max-pxcor 0
  [ sprout-farming_agents (round (extGrowthF * ( (count patches) - (count settledFarmingAgents) ) ) )
    [
      initialize-an-agent
      set farmingGrowth farmingGrowth + 1
    ]
  ]
  let notSettledFarmingAgents farming_agents with [not member? self settledFarmingAgents]
  
  ;;; Fit-to-maximum exclusion
  ask notSettledFarmingAgents
  [
    ;new farming_agents exit the territory in a random order whenever there is no more land to use
    if (count farming_agents > count patches) [ set farmingDeterrence farmingDeterrence + 1 die ]
  ]
  
  ;;; Density-dependent exclusion
  ask notSettledFarmingAgents
  [ 
    ;new farming_agents exit the territory with a probability proportional to the density of land currently used for agriculture (i.e. proxy of the quality of the remaining land)
    if (random-float 1 < ((count farming_agents) / (count patches) ) ) [ set farmingDeterrence farmingDeterrence + 1 die ]
  ]
  
  ;;; Volition-opportunity exclusion
  ask notSettledFarmingAgents
  [
    ;;; if the territory is saturated...
    if (count patches - count herding_agents < count farming_agents)
    [
      initialize-an-agent
      ;;; if its not possible to extend farming over herding of another group 
      if ( ( (count herding_agents) / (count patches) ) > independence)
      [ set farmingDeterrence farmingDeterrence + 1 die ]
    ]
  ]
end 

to herding_expansion
  
  ;;; set of herding_agents currently present
  set stableHerdingAgents turtle-set herding_agents
  
  ;;; reset counters
  set herdingGrowth 0
  set herdingDeterrence 0
  
  ;;; Intrinsic growth
  ask stableHerdingAgents
  [ if ( random-float 1 <= intGrowthH )
    [ 
      hatch 1
      set herdingGrowth herdingGrowth + 1
    ]
  ]
  
  ;;; Extrinsic growth
  ask patch 0 0
  [ sprout-herding_agents (round (extGrowthH * ( (count patches) - (count stableHerdingAgents) ) ) )
    [ 
      initialize-an-agent
      set herdingGrowth herdingGrowth + 1
    ]
  ]
  
  let notStableHerdingAgents herding_agents with [not member? self stableHerdingAgents]
  
  ;;; Fit-to-maximum exclusion
  ask notStableHerdingAgents
  [ 
    ;new herding_agents exit the territory in a random order whenever there is no more land to use
    if (count herding_agents > count patches) [ set herdingDeterrence herdingDeterrence + 1 die ]
  ]
  
  ;;; Density-dependent exclusion
  ask notStableHerdingAgents
  [ 
    ;new herding_agents exit the territory with a probability proportional to the density of pastures currently in use (i.e. proxy of the quality of the remaining land)
    if (random-float 1 < ( (count herding_agents) / (count patches) ) ) [ set herdingDeterrence herdingDeterrence + 1 die ]
  ] 
end 

to check_competition
  
  if ((count patches) - (count farming_agents) < count herding_agents) [ resolve_competition ]
end 

to resolve_competition

  ;;; set competition conditions
  
  ;;;;; select one farming agent and its supporters, calculate the intensity of the farming land use involved in a land use unit
  set unluckyF one-of farming_agents
  set farmingSupport round (intgF * ((count farming_agents) - 1))
  let p 0
  if (farmingSupport > 0) [ set p sum [intensity] of n-of farmingSupport farming_agents with [self != unluckyF] ]
  set farmingIntensity ([intensity] of unluckyF + p )
  
  ;;;;; select one herding agent and its supporters, calculate the intensity of the herding land use to be involved in the same land use unit
  set unluckyH one-of herding_agents
  set herdingSupport round (intgH * ((count herding_agents) - 1))
  let q 0
  if (herdingSupport > 0) [ set q sum [intensity] of n-of herdingSupport herding_agents with [self != unluckyH] ]
  set herdingIntensity ([intensity] of unluckyH + q )

  ;;;;; calculate the ratio of intensities, the index of opportunity and the incentives for relinquish, all taken from the perspective of herding land use
  set ratio_of_intensities  (herdingIntensity /(farmingIntensity + herdingIntensity))
  set index_of_opportunity ((count farming_agents) / (count patches))
  set incentives_to_relinquish (1 - (ratio_of_intensities * index_of_opportunity))
  
  ;;; resolve the competitive situation
  ask unluckyH
  [
    ;;; Does the competitive situation evolves into a dilemma event?
    ifelse ( independence < incentives_to_relinquish)
    
    ;;; No. The herding agent exit the territory.
    [ set herdingDeterrence herdingDeterrence + 1 die ]
    
    ;;; Yes. A dilemma event is produced for there are two variants to be realized in a single land use unit.
    [ 
      set dilemmaEvents (dilemmaEvents + 1)
      
      ;;; Does the dilemma event evolves into a oasis degression event?
      ifelse (random-float 1 < ratio_of_intensities)
      
      ;;; Yes. The unlucky farming agent exits the territory.
      [
        ask unluckyF [ set farmingDeterrence farmingDeterrence + 1 die ]
        set oasisDegressionEvents (oasisDegressionEvents + 1)
      ]
      
      ;;; No. The unlucky herding agent exits the territory.
      [ set herdingDeterrence herdingDeterrence + 1 die ]
    ]    
  ]
  
  ;;; re-check the presence of competitive situations
  check_competition
end 

to update_visualization
  
  update_patches
  
  set AREA count patches
  
  set farmingBalance (farmingGrowth - farmingDeterrence)
  set herdingBalance (herdingGrowth - herdingDeterrence)
  
  ifelse (dilemmaEvents > 0) [ set herdingSuccessRatio (oasisDegressionEvents / dilemmaEvents) ] [ set herdingSuccessRatio 0 ]

  set farming_histo_intensity_0_025 (count farming_agents with [intensity <= ( 0.25 * farming_max_intensity)])
  set farming_histo_intensity_025_05 (count farming_agents with [intensity <= ( 0.5 * farming_max_intensity)])
  set farming_histo_intensity_025_05 (farming_histo_intensity_025_05 - farming_histo_intensity_0_025)
  set farming_histo_intensity_05_075 (count farming_agents with [intensity <= ( 0.75 * farming_max_intensity)])
  set farming_histo_intensity_05_075 (farming_histo_intensity_05_075 - farming_histo_intensity_0_025 - farming_histo_intensity_025_05)
  set farming_histo_intensity_075_1 ((count farming_agents) - farming_histo_intensity_0_025 - farming_histo_intensity_025_05 - farming_histo_intensity_05_075)
  ifelse (count farming_agents > 0)
  [ set mean_fint ((farming_histo_intensity_0_025 * 1 / (count farming_agents)) + (farming_histo_intensity_025_05 * 2 / (count farming_agents)) + (farming_histo_intensity_05_075 * 3 / (count farming_agents)) + (farming_histo_intensity_075_1 * 4 / (count farming_agents))) ]
  [ set mean_fint 0 ]
  
  set farming_histo_independence_0_025 (count farming_agents with [independence <= 0.25])
  set farming_histo_independence_025_05 (count farming_agents with [independence <= 0.5])
  set farming_histo_independence_025_05 (farming_histo_independence_025_05 - farming_histo_independence_0_025)
  set farming_histo_independence_05_075 (count farming_agents with [independence <= 0.75])
  set farming_histo_independence_05_075 (farming_histo_independence_05_075 - farming_histo_independence_0_025 - farming_histo_independence_025_05)
  set farming_histo_independence_075_1 ((count farming_agents) - farming_histo_independence_0_025 - farming_histo_independence_025_05 - farming_histo_independence_05_075)  
  ifelse (count farming_agents > 0)
  [ set mean_find ((farming_histo_independence_0_025 * 1 / (count farming_agents)) + (farming_histo_independence_025_05 * 2 / (count farming_agents)) + (farming_histo_independence_05_075 * 3 / (count farming_agents)) + (farming_histo_independence_075_1 * 4 / (count farming_agents))) ] 
  [ set mean_find 0 ]
  
  set herding_histo_intensity_0_025 (count herding_agents with [intensity <= (0.25 * (h_r_m_i * farming_max_intensity))])
  set herding_histo_intensity_025_05 (count herding_agents with [intensity <= (0.5 * (h_r_m_i * farming_max_intensity))])
  set herding_histo_intensity_025_05 (herding_histo_intensity_025_05 - herding_histo_intensity_0_025)
  set herding_histo_intensity_05_075 (count herding_agents with [intensity <= (0.75 * (h_r_m_i * farming_max_intensity))])
  set herding_histo_intensity_05_075 (herding_histo_intensity_05_075 - herding_histo_intensity_0_025 - herding_histo_intensity_025_05)
  set herding_histo_intensity_075_1 ((count herding_agents) - herding_histo_intensity_0_025 - herding_histo_intensity_025_05 - herding_histo_intensity_05_075)
  ifelse (count herding_agents > 0)
  [ set mean_hint ((herding_histo_intensity_0_025 * 1 / (count herding_agents)) + (herding_histo_intensity_025_05 * 2 / (count herding_agents)) + (herding_histo_intensity_05_075 * 3 / (count herding_agents)) + (herding_histo_intensity_075_1 * 4 / (count herding_agents))) ]
  [ set mean_hint 0 ]
  
  set herding_histo_independence_0_025 (count herding_agents with [independence <= 0.25])
  set herding_histo_independence_025_05 (count herding_agents with [independence <= 0.5])
  set herding_histo_independence_025_05 (herding_histo_independence_025_05 - herding_histo_independence_0_025)
  set herding_histo_independence_05_075 (count herding_agents with [independence <= 0.75])
  set herding_histo_independence_05_075 (herding_histo_independence_05_075 - herding_histo_independence_0_025 - herding_histo_independence_025_05)
  set herding_histo_independence_075_1 ((count herding_agents) - herding_histo_independence_0_025 - herding_histo_independence_025_05 - herding_histo_independence_05_075)
  ifelse (count herding_agents > 0)
  [ set mean_hind ((herding_histo_independence_0_025 * 1 / (count herding_agents)) + (herding_histo_independence_025_05 * 2 / (count herding_agents)) + (herding_histo_independence_05_075 * 3 / (count herding_agents)) + (herding_histo_independence_075_1 * 4 / (count herding_agents))) ]
  [ set mean_hind 0 ]
end 

to update_patches
  
  ifelse ( count farming_agents > (count patches with [pcolor = green]) )
  [
    let to-paint (count farming_agents - (count patches with [pcolor = green]))
    repeat to-paint
    [
      ifelse (count patches with [pcolor = green] < (max-pycor + 1) )
      [ ask one-of patches with [pxcor = max-pxcor] [ set pcolor green] ]
      [ ask one-of patches with [(pcolor = yellow) and (count neighbors with [pcolor = green] > 2)] [ set pcolor green ] ]
    ]
  ] 
  [
    let to-paint ((count patches with [pcolor = green]) - count farming_agents)
    repeat to-paint
    [
      ifelse (any? patches with [(pcolor = green) and (count neighbors with [pcolor = yellow] > 2)])
      [
        ask one-of patches with [(pcolor = green) and (count neighbors with [pcolor = yellow] > 2)]
        [ set pcolor yellow ]
      ]
      [ ask one-of patches with [pxcor = min-pxcor] [set pcolor yellow] ]
    ]
  ]    
end 

There is only one version of this model, created over 8 years ago by Andreas Angourakis.

Attached files

File Type Description Last updated
Musical Chairs.png preview Preview for 'Musical Chairs' over 8 years ago, by Andreas Angourakis Download

This model does not have any ancestors.

This model does not have any descendants.