Nice Musical Chairs

Nice 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.3.1 • Viewed 170 times • Downloaded 16 times • Run 0 times
Download the 'Nice 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.)


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

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

;;  The Nice Musical Chairs model - A model of the interaction between farming and herding, introducing explicit groups and group mechanisms
;;  Copyright (C) 2016 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 .

;;;;;;;;;;;;;;;;;
;;;;; BREEDS ;;;;
;;;;;;;;;;;;;;;;;

breed [ groups group ]

breed [ pointers pointer ]

breed [ labelpositions labelposition ]

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

globals
[
  totalPatches

  ;;; modified parameters
  initH initF
  baseIntGrowth maxExtGrowth
  initGroups
  effectivenessGr
  maxGroupChangeRate
  opt optimalGrowthIncrease

  group_management group_pasture_tenure pairing

  ;;; variables used in resolve_conflict
  defender contender

  ;;; counters and final measures
  countLandUseF countLandUseH
  numberGroups
  FFcompetitions HHcompetitions HFcompetitions FHcompetitions landUseChangeEvents managementEvents
  farmingDemand farmingGrowth farmingDeterrence farmingBalance
  herdingDemand herdingGrowth herdingDeterrence herdingBalance
  meanGroupSize bigGroupSize
  meanGroupEffectiveness bigGroupEffectiveness
  bigTargetFarmingRatio meanTargetFarmingRatio
  meanFarmingIntegration meanHerdingIntegration meanMixedIntegration
]

groups-own
[
  groupSize groupEffectiveness
  intGrowthF intGrowthH
  farmingRatio targetFarmingRatio
  ;;; helpers
  groupSizeF groupSizeH
  groupDemandF groupDemandH
  groupDemandRemain
]

patches-own [ landUse myGroup contendersF contendersH withinIntegration betweenIntegration ]

pointers-own [ value ]

labelpositions-own [ name ]

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

to setup

  ;;; This procedure initializes the model

  clear-all

  set totalPatches count patches

  ;;; setup parameters depending on the type of experiment
  if (typeOfExperiment = "random")
  [
    ; set random seed
    let aSeed new-seed
    random-seed aSeed
    set seed aSeed

    let listOfScenarios (list "Ao - open access, simple group dynamics" "Bo - open access, pairing" "Co - open access, management" "Do - open access, pairing and management" "Ar - restricted access, simple group dynamics" "Br - restricted access, pairing" "Cr - restricted access, management" "Dr - restricted access, pairing and management")
    let randomIndex random 8
    set scenario item randomIndex listOfScenarios ;;; randomly choose one scenario
    set baseIntGrowth 0.01 + random-float base_intrinsic_growth_rate
    set maxExtGrowth 0.001 + random-float max_extrinsic_growth_rate
    set opt random-float optimum
    set optimalGrowthIncrease random-float optimal_growth_increase
    set initGroups 1 + random initial_number_of_groups
    set maxGroupChangeRate random-float max_group_change_rate
    set effectivenessGr random-float totalPatches
    set initH random round ((init_herding / 100) * totalPatches)
    set initF random round ((init_farming / 100) * totalPatches)
  ]
  if (typeOfExperiment = "defined by GUI")
  [
    ; set random seed
    random-seed seed

    set baseIntGrowth base_intrinsic_growth_rate
    set maxExtGrowth max_extrinsic_growth_rate
    set opt optimum
    set optimalGrowthIncrease optimal_growth_increase
    set initGroups initial_number_of_groups
    set maxGroupChangeRate max_group_change_rate
    set effectivenessGr effectiveness_gradient
    set initH round ((init_herding / 100) * totalPatches)
    set initF round ((init_farming / 100) * totalPatches)
  ]
  if (typeOfExperiment = "defined by expNumber")
  [
    ; set random seed
    let aSeed new-seed
    random-seed aSeed
    set seed aSeed

    load-experiment
  ]

  set pairing true
  if (scenario = "Ao - open access, simple group dynamics" OR scenario = "Co - open access, management" OR scenario = "Ar - restricted access, simple group dynamics" OR scenario = "Cr - restricted access, management")
  [
    set optimalGrowthIncrease 0
    set pairing false
  ]

  set group_pasture_tenure false
  if (scenario = "Ar - restricted access, simple group dynamics" OR scenario = "Br - restricted access, pairing" OR scenario = "Cr - restricted access, management" OR scenario = "Dr - restricted access, pairing and management")
  [
    set group_pasture_tenure true
  ]

  set group_management false
  if (scenario = "Co - open access, management" OR scenario = "Do - open access, pairing and management" OR scenario = "Cr - restricted access, management" OR scenario = "Dr - restricted access, pairing and management")
  [
    set group_management true
  ]

  ask patch 0 0
  [
    sprout-groups initGroups
  ]

  ;;; set land use according to the parameter setting (position is arbitrary and has no consequence)
  ask patches [ set landUse "N" set myGroup nobody set contendersF (turtle-set) set contendersH (turtle-set) ]
  ask n-of initF patches
  [
    set landUse "F"
  ]
  ask n-of initH patches with [landUse = "N"]
  [
    set landUse "H"
  ]
  initialize-patches-and-groups

  ;;; initialize visualization

  ask patch (min-pxcor + round ((max-pxcor - min-pxcor) * 0.97) ) (min-pycor + round ((max-pycor - min-pycor) * 0.97) )
  [
    sprout-labelpositions 1 [ set name "scenario" set label scenario set shape "invisible" ]
  ]
  if (display_details = true)
  [
    ask patch (min-pxcor + round ((max-pxcor - min-pxcor) * 0.97) ) (min-pycor + round ((max-pycor - min-pycor) * 0.03) )
    [
      sprout-labelpositions 1 [ set name "time" set label "time: 0" set shape "invisible" ]
    ]
    ask patch (min-pxcor + round ((max-pxcor - min-pxcor) * 0.3) ) (min-pycor + round ((max-pycor - min-pycor) * 0.03) )
    [
      sprout-labelpositions 1 [ set name "farming" set shape "invisible" ]
    ]
    ask patch (min-pxcor + round ((max-pxcor - min-pxcor) * 0.72) ) (min-pycor + round ((max-pycor - min-pycor) * 0.03) )
    [
      sprout-labelpositions 1 [ set name "bigGroupSize" set shape "invisible" ]
    ]

  ]

  update-visualization

  reset-ticks
end 

to initialize-patches-and-groups

  ;;; This procedure initializes patch and group variables

  ask patches
  [
      if (landUse != "N") [ set myGroup (one-of groups) ]
  ]

  ask groups
  [
    set hidden? true
    move-to one-of patches with [any? groups-here = false and (pxcor > 2) and (pycor > 2) and (pxcor < max-pxcor - 2) and (pycor < max-pycor - 2)]
    set targetFarmingRatio random-float 1
    ;set targetFarmingRatio FarmingRatio ;;; alternative initialization of "targetFarmingRatio"
    update-group
  ]

  ask patches
  [
    update-landUnits
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; CYCLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go

  ;;; This procedure is the cycle of the model (what happens during one "tick").

  reset-counters

  growth

  landUse-expansion

  check-competitions

  change-groups

  if (group_management = true) [ group-management ]

  update-visualization

  tick
  if (display_details = true) [ ask labelpositions with [ name = "time" ] [ set label (word "time: " ticks) ] ]
  if ticks > endSimulation [stop]
end 

to reset-counters

  ;;; This procedure reset all counters which are used either during the cycle or summarized at the "update-visualization" procedure.

  set farmingGrowth 0
  set farmingDeterrence 0
  set herdingGrowth 0
  set herdingDeterrence 0
  set FFcompetitions 0
  set HHcompetitions 0
  set HFcompetitions 0
  set FHcompetitions 0
  set landUseChangeEvents 0
  set managementEvents 0

  ask groups [ set groupDemandF 0 set groupDemandH 0 ]
end 

to growth

  ;;; This procedure calculates the groups demands for each land use class, based on both the intrinsic and extrinsic growth rates of each of them.
  ;;; Note that growth rates are dependent on parameters, but also on the context, and may vary from one "tick" to another.

  ask groups [ set groupDemandF 0 set groupDemandH 0 ]
  ;;; FARMING
  ;;; Intrinsic Demand
  ask groups with [groupSize > 0]
  [
    let myLand count patches with [landUse = "F" and myGroup = myself]
    repeat myLand
    [
      if ( random-float 1 <= intGrowthF )
      [
        set groupDemandF groupDemandF + 1
      ]
    ]
  ]
  ;;; Extrinsic Demand
  let extF (round (maxExtGrowth * ( totalPatches - countLandUseF ) ) )
  repeat extF
  [
    ask one-of groups
    [
      set groupDemandF groupDemandF + 1
    ]
  ]
  ;;; HERDING
  ;;; Intrinsic Growth
  ask groups with [groupSize > 0]
  [
    let myLand count patches with [landUse = "H" and myGroup = myself]
    repeat myLand
    [
      if ( random-float 1 <= intGrowthH )
      [
        set groupDemandH groupDemandH + 1
      ]
    ]
  ]
  ;;; Extrinsic Growth
  let extH (round (maxExtGrowth * ( totalPatches - countLandUseH ) ) )
  repeat extH
  [
    ask one-of groups
    [
      set groupDemandH groupDemandH + 1
    ]
  ]
end 

to landUse-expansion

  ;;; This procedure calls for the expansion procedures of farming and herding, intentionally in this order.

  farming-expansion
  herding-expansion
end 

to farming-expansion

  ;;; In this procedure, groups attempt to assign patches to their new farming units.
  ;;; If there is no patch freely available, groups will randomly choose a patch, and
  ;;; if this patch belongs to another group (density-dependent growth), the group will generate a competitive situation and be accounted within "contendersF".
  ;;; In the case that the patch is used for "herding" and "group_pasture_tenure = false", the group will automatically occupy it and change its land use to farming.

  let growingGroupsF groups with [ groupDemandF > 0 ]
  ask growingGroupsF [ set groupDemandRemain groupDemandF ]

  repeat sum [groupDemandRemain] of growingGroupsF
  [
    ask one-of growingGroupsF with [groupDemandRemain > 0]
    [
      let me self
      ifelse (any? patches with [myGroup = nobody])
      [
        ;;; if the land is not saturated
        ask one-of patches with [myGroup = nobody]
        [
          if (landUse = "N") [ set landUseChangeEvents landUseChangeEvents + 1 ]
          set myGroup me set landUse "F"
        ]
      ]
      [
        ;;; if the territory is saturated
        ;;; Choose a random patch
        ask one-of patches
        [
          ;;; if the patch is used by another group
          if (myGroup != me)
          [
            ifelse (landUse = "F") [
              if ( allow_within-class_competition = true )
              [
                ;;; If the patch is used for farming, F-F competition will be called later
                set contendersF (turtle-set contendersF me)
                set FFcompetitions (FFcompetitions + 1)
              ]
            ]
            [
              ifelse (group_pasture_tenure = true)
              [
                ;;; F-H competition will be called later
                set contendersF (turtle-set contendersF me)
                set FHcompetitions (FHcompetitions + 1)
              ]
              [
                ;;; farming will start using a former pasture
                set myGroup myself
                set landUSe "F"
                set landUseChangeEvents landUseChangeEvents + 1
                set farmingGrowth farmingGrowth + 1
                set herdingDeterrence herdingDeterrence + 1
              ]
            ]
          ]
        ]
      ]
      set groupDemandRemain groupDemandRemain - 1
    ]
  ]
end 

to herding-expansion

  ;;; In this procedure, groups attempt to assign patches to all their herding units (if "group_pasture_tenure = false") or to their new herding units (group_pasture_tenure = true).
  ;;; If there is no patch freely available, groups will randomly choose a patch, and
  ;;; if this patch belongs to another group (density-dependent growth), the group will generate a competitive situation and be accounted within "contendersH"

  let groupsH nobody
  let herds 0
  ifelse (group_pasture_tenure = true)
  [
    set groupsH groups with [ groupDemandH > 0 ]
    ask groupsH [ set groupDemandRemain groupDemandH ]
    set herds sum [groupDemandRemain] of groupsH
  ]
  [
    set groupsH groups with [ farmingRatio < 1 ]
    ask groupsH
    [
      let me self
      set groupDemandRemain groupSizeH + groupDemandH
    ]
    set herds sum [ groupDemandRemain ] of groups

    ;;; reset herding positions (herds go back not necessarily to the same patch)
    ask patches with [ landUse = "H"] [ set myGroup nobody ]
  ]

  repeat herds
  [
    ask one-of groupsH with [ groupDemandRemain > 0 ]
    [
      let me self
      ifelse (any? patches with [myGroup = nobody])
      [
        ;;; if the land is not saturated
        ask one-of patches with [myGroup = nobody]
        [
          if (landUse != "H")
          [
            set landUse "H"
            set landUseChangeEvents landUseChangeEvents + 1
            set herdingGrowth herdingGrowth + 1
          ]
          set myGroup me
        ]
      ]
      [
        ;;; if the territory is saturated
        ;;; Choose a random patch
        ask one-of patches
        [
          ;;; Fit-to-maximum exclusion, Density-dependent exclusion
          if (myGroup != me)
          [
            ifelse (landUse = "F")
            [
              ;;; a H-F competition will be called later
              set contendersH (turtle-set contendersH me)
              set HFcompetitions (HFcompetitions + 1)
            ]
            [
              if (allow_within-class_competition = true)
              [
                ;;; a H-H competition will be called later
                set contendersH (turtle-set contendersH me)
                set HHcompetitions (HHcompetitions + 1)
              ]
            ]
          ]
        ]
      ]
      set groupDemandRemain groupDemandRemain - 1
    ]
  ]

  ;;; rangelands not claimed will be considered free land (no land use)
  if (any? patches with [landUse = "H" and myGroup = nobody] ) [ ask patches with [landUse = "H" and myGroup = nobody] [ set landUse "N" ] ]
end 

to check-competitions

  ;;; This procedure calls, in a particular sequence, for the resolution of all competitive situations generated by farming and herding expansions.

  ;;; Due to their sedentary condition, farming contenders will act first (F-F and F-H -> H-H and H-F)

  ;;; Farming stakeholders prefer to acquire other groups' farmlands (F-F),
  ;;; rather than investing in new infraestructures (F-H)

  check-FFcompetitions
  check-FHcompetitions

  ;;; Herding stakeholders prefer to acquire other groups' pastures (H-H),
  ;;; rather than converting farmlands by  violence or negotiation (H-F)

  check-HHcompetitions
  check-HFcompetitions

  ask groups [ update-group ]
end 

to check-FFcompetitions

  ;;; farming-farming competition

  ask patches with [ landUse = "F" and any? contendersF ]
  [
;    print "F-F"
    ;;; the center assigned is the one that is effectively using the land
    set defender myGroup
    repeat count contendersF
    [
      set contender one-of contendersF
      ;;; remove contender from the respective contenders agent-set
      set contendersF contendersF with [self != contender]
      ;print (word "contendersF after: " contendersF)
      resolve-competition "FF"
    ]
  ]
end 

to check-FHcompetitions

  ;;; farming-herding competition

  ask patches with [ landUse = "H" and any? contendersF ]
  [
;    print "F-H"
    set defender myGroup
    repeat count contendersF
    [
      set contender one-of contendersF
      ;;; remove contender from the respective contenders agent-set
      set contendersF contendersF with [self != contender]
;      print (word "contendersH after: " contendersH)
      resolve-competition "FH"
    ]
  ]
end 

to check-HHcompetitions

  ;;; herding-herding competition

  ask patches with [ landUse = "H" and any? contendersH ]
  [
;    print "H-H"
    ;;; Since their schedule may vary, a herding center is assigned randomly among the contenders to be the one arriving first (defender)
    set defender myGroup
    repeat count contendersH
    [
      set contender one-of contendersH
      ;;; remove contender from the respective contenders agent-set
      set contendersH contendersH with [self != contender]
;      print (word "contendersH after: " contendersH)
      ;;; check if any of contenders still exists. If so, then resolve competition
      if ([groupSize] of contender > 0)
      [ resolve-competition "HH"]
    ]
  ]
end 

to check-HFcompetitions

  ;;; farming-herding competition

  ask patches with [ landUse = "F" and any? contendersH ]
  [
;    print "H-F"
    set defender myGroup
    repeat count contendersH
    [
      set contender one-of contendersH
      ;;; remove contender from the respective contenders agent-set
      set contendersH contendersH with [self != contender]
;      print (word "contendersH after: " contendersH)
      resolve-competition "HF"
    ]
  ]
end 

to resolve-competition [ typeOfComp ]

  ;;; This procedure resolves the current competitive situation,
  ;;; and calculate the consequences of contenders success according to "typeOfComp" ("FF"=farming-farming, "FH"=farming-herding, "HH"=herding-herding, "HF"=herding-farming).

  ;;; set competition conditions
  ; define intensities
  let supportDef get-group-influence defender
  let supportCon get-group-influence contender
;  print (word defender " vs " contender ")
;  print (word "supportDef: " supportDef " ; supportCon: " supportCon)

  ;;; the contender is discarted if both defender and contender have zero strength at this patch
  if (supportCon + supportDef > 0)
  [
    ;;; a contender is the one attempting to expand, thus it is the one to make a informed decision
    let ratio_of_intensities  (supportCon /(supportCon + supportDef))

    ;;; Does the competitive situation evolves into land use change event?
    if ( random-float 1 < ratio_of_intensities)
    [
      ;;; extending whichever land use is encouraged
      set myGroup contender

      ;;; update landUse
      if (typeOfComp = "HF")
      [
  ;      print "herding wins"
        set landUse "H"
        ;;; Hence, there is land use change
        set landUseChangeEvents landUseChangeEvents + 1
        set herdingGrowth herdingGrowth + 1
        set farmingDeterrence farmingDeterrence + 1
      ]
      if (typeOfComp = "FH")
      [
  ;      print "farming wins"
        set landUse "F"
        ;;; Hence, there is land use change
        set landUseChangeEvents landUseChangeEvents + 1
        set farmingGrowth farmingGrowth + 1
        set herdingDeterrence herdingDeterrence + 1
      ]
    ]
  ]
end 

to change-groups

  ;;; In this procedure, every patch of every group test their particular probability of changing to another group,
  ;;; which may be an existing group or a new one collecting all the defecting patches of a group (fission).
  ;;; The criterium to leave and choose a group is the competitive strength or influence that groups have in the patch at hand (size * effectiveness)

  ask groups
  [
    ;;; each patch of a group will assess their will (maxGroupChangeRate)
    ;;; and their freedom, which is inversely related to the group effectiveness (1 - ([groupEffectiveness] of myGroup) ),
    ;;; to change groups, possibly forming a new group.
    let me self
    let myLand patches with [myGroup = me]
    let defectingPatches (patch-set nobody)
    ask myLand
    [
      if ( random-float 1 < maxGroupChangeRate * (1 - ([groupEffectiveness] of myGroup) ) )
      [
        set defectingPatches (patch-set defectingPatches self)
      ]
    ]
    if (any? defectingPatches)
    [
      ;;; if there are any patches defecting from this group...
      ;;; the viability of the possible new group is calculated for each patch and compared to the most influent group
      let newGroup nobody
      let influenceNewGroup (count defectingPatches) * e ^ ( - (count defectingPatches) / (effectivenessGr * totalPatches) )
      let mostInfluentGroup max-one-of groups [groupSize * groupEffectiveness]
      let influenceOtherGroup get-group-influence mostInfluentGroup
      ifelse (influenceOtherGroup > influenceNewGroup)
      [
        ask defectingPatches [ set myGroup mostInfluentGroup ]
      ]
      [
        if (newGroup = nobody)
        [
          ifelse (any? groups with [groupSize = 0])
          [
            ask one-of groups with [groupSize = 0]
            [
              set targetFarmingRatio ([targetFarmingRatio] of me)
              set newGroup self
            ]
          ]
          [
            hatch-groups 1
            [
            ;;; new groups inherit the traits of the original group *** or modify them given a mutation parameter
            set hidden? true
            move-to one-of patches with [any? groups-here = false and (pxcor > 2) and (pycor > 2) and (pxcor < max-pxcor - 2) and (pycor < max-pycor - 2)]
            ;;; random mutation
            ;set targetFarmingRatio min(list 1 max(list 0 (([targetFarmingRatio] of me) + (0.1 - random-float 0.2)) ) )
            ;;; following the optimal
            ;set targetFarmingRatio ([targetFarmingRatio] of me) + 0.1 * (opt - targetFarmingRatio)
            ;;; following tradition
            set targetFarmingRatio ([targetFarmingRatio] of me)
            set newGroup self
;            print (word " Group fission: " me " (groupSize=" count myLand ") splits into " me " (groupSize=" (count myLand - count defectingPatches) ") and " newGroup " (groupSize=" count defectingPatches ")")
            ]
          ]
        ]
        ask defectingPatches [ set myGroup newGroup ]
      ]
    ]
    update-group
  ]
end 

to-report get-group-influence [ theGroup ]

  report [groupSize * groupEffectiveness] of theGroup
end 

to group-management

  ;;; In this procedure, groups with more than one member calculate the difference between their "farmingRatio" and their "targetFarmingRatio",
  ;;; and attempt to change the land use of the respective number of patches (note that "floor" is used),
  ;;; with a success proportional to their "groupEffectiveness".

  ask groups
  [
    if (groupSize > 1)
      [
        let dif ((farmingRatio - targetFarmingRatio) * groupSize)
        let num floor (abs dif * groupEffectiveness)
;        print (word self " -> farmingRatio: " precision farmingRatio 4 " ¦¦ targetFarmingRatio: " precision targetFarmingRatio 4 " ¦¦ groupSize: " groupSize " ¦¦ groupEffectiveness: " precision groupEffectiveness 4 " ¦¦ dif: " dif " ¦¦ num: " num)
        if (num > 0)
        [
          ;;; if it is greater than target
          ifelse ( dif > 0 )
          [
            ask n-of num patches with [landUse ="F" and myGroup = myself]
            [
              set landUse "H"
              ;;; Hence, there is land use change
              set landUseChangeEvents landUseChangeEvents + 1
              set herdingGrowth herdingGrowth + 1
              set farmingDeterrence farmingDeterrence + 1
              set managementEvents managementEvents + 1
            ]
          ]
          [
            ;;; if it is smaller than target
            if ( dif < 0 )
            [
              ask n-of num patches with [landUse ="H" and myGroup = myself]
              [
                set landUse "F"
                ;;; Hence, there is land use change
                set landUseChangeEvents landUseChangeEvents + 1
                set farmingGrowth farmingGrowth + 1
                set herdingDeterrence herdingDeterrence + 1
                set managementEvents managementEvents + 1
              ]
            ]
          ]
        ]
      ]
      update-group
  ]
end 

to update-group

  ;;; This procedure updates group variables (groupSize, groupEffectiveness, farmingRatio, intGrowthF, intGrowthH).

  set farmingRatio 0
  set groupSize count patches with [myGroup = myself]
  set groupSizeF count patches with [myGroup = myself and landUse = "F"]
  set groupSizeH count patches with [myGroup = myself and landUse = "H"]
  if (groupSize > 0)
  [
    set farmingRatio ( count patches with [landUse = "F" and myGroup = myself] / groupSize )
  ]
  set groupEffectiveness e ^ ( - groupSize / (effectivenessGr * totalPatches) )

  ;;; calculate modified growth out of the group distance from the optimal
  let d 0
  ifelse (farmingRatio < opt)
  [
    set d (farmingRatio / opt)
    set intGrowthF baseIntGrowth * (1 + (optimalGrowthIncrease / 100))
    set intGrowthH baseIntGrowth * (1 + (optimalGrowthIncrease / 100) * d)
  ]
  [
    ifelse (opt = 1)
    [ set d 1 ]
    [ set d 1 - ((farmingRatio - opt) / (1 - opt)) ]
    set intGrowthH baseIntGrowth * (1 + (optimalGrowthIncrease / 100))
    set intGrowthF baseIntGrowth * (1 + (optimalGrowthIncrease / 100) * d)
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; VISUALIZATION ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to update-landUnits

  ;;; This procedure updates the patches' "withinIntegration" and "betweenIntegration".

  ask patches with [myGroup != nobody]
  [
    ifelse (landUse = "F")
    [
      set withinIntegration [farmingRatio] of myGroup
      set betweenIntegration 1 - [farmingRatio] of myGroup
    ]
    [
      set withinIntegration 1 - [farmingRatio] of myGroup
      set betweenIntegration [farmingRatio] of myGroup
    ]
  ]
end 

to update-visualization

  ;;; this procedure updates the display and all global output variables.

  if (display_mode = "land use proportion") [ update-patches if (display_details = true) [ ask labelpositions [set label-color black] ] ]
  if (display_mode = "groups") [ update-network if (display_details = true) [ ask labelpositions [set label-color white] ] ]

  set numberGroups count groups with [groupSize > 0]
  set countLandUseF count patches with [ landUse = "F" ]
  set countLandUseH count patches with [ landUse = "H" ]

  set farmingBalance (farmingGrowth - farmingDeterrence)
  set herdingBalance (herdingGrowth - herdingDeterrence)

  set meanGroupSize mean [[groupSize] of myGroup] of patches with [ landUse != "N" ]
  set bigGroupSize [groupSize] of max-one-of groups [groupSize]
  set meanGroupEffectiveness mean [[groupEffectiveness] of myGroup] of patches with [ landUse != "N" ]
  set bigGroupEffectiveness [groupEffectiveness] of max-one-of groups [groupSize]

  set meanTargetFarmingRatio mean [[targetFarmingRatio] of myGroup] of patches with [ landUse != "N" ]
  set bigTargetFarmingRatio [targetFarmingRatio] of max-one-of groups [groupSize]

  update-landUnits

  ifelse (any? patches with [landUse = "F"]) [ set meanFarmingIntegration mean [withinIntegration] of patches with [landUse = "F"] ] [ set meanFarmingIntegration -0.01 ]
  ifelse (any? patches with [landUse = "H"]) [ set meanHerdingIntegration mean [withinIntegration] of patches with [landUse = "H"] ] [ set meanHerdingIntegration -0.01 ]

  set meanMixedIntegration mean [betweenIntegration] of patches with [ landUse != "N" ]

  ifelse (display_details = true)
  [
    ask labelpositions with [ name = "farming" ] [ set label (word "farming(%): " (precision (100 * countLandUseF / totalPatches) 2) ) ]
    ask labelpositions with [ name = "bigGroupSize" ] [ set label (word "biGroupSize(%): " (precision (100 * bigGroupSize / totalPatches) 2) ) ]
  ]
  [
    ask labelpositions with [ name = "time" ] [ set label "" ]
    ask labelpositions with [ name = "farming" ] [ set label "" ]
    ask labelpositions with [ name = "bigGroupSize" ] [ set label "" ]
  ]
end 

to update-patches

  ;;; this procedure updates the "land use proportion" display mode.

  ask pointers [die]
  ask groups [set hidden? true]
  ask patches
  [
    set pcolor brown
    if (landUse = "F")
    [ set pcolor green ]
    if (landUse = "H")
    [ set pcolor yellow ]
  ]
end 

to update-network

  ;;; this procedure updates the "groups" display mode.

  ask pointers [die]
  ask groups
  [
    ifelse (groupSize > 0) [set hidden? false set color red set shape "circle" set size 0.5] [ set hidden? true ]
    create-links-with other groups [ set color black]
  ]

  layout-spring groups links 0.18 9 1.2
  ask links [die]
  ask patches
  [
    set pcolor black
    let thisPatch self
    if (landUse != "N" )
    [
      sprout-pointers 1 [
        set shape "circle" set size 0.2
        ifelse ([landUse] of patch-here = "F") [ set color green ] [ set color yellow ]
        create-link-with myGroup [ set color grey]
        move-to myGroup
      ]
    ]
  ]
  ask groups
  [
    let num groupSize
    repeat groupSize [
      ask one-of link-neighbors [
        rt 360 * who
        fd 0.1 * num * e ^ (- num / 60)
      ]
      set num num - 1
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;; Parametrization from file ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to load-experiment

  ;;; this procedure loads the values of each (explored) parameter from a csv file.
  ;;; Note that the setup will use the value set by the user for any other parameter (e.g. scenario).

  let FilePath "SensAnalysis//exp//" ;;; create folders in the model's directory before trying to load experiments
  let filename (word FilePath "exp_" expNumber ".csv") ;;; the parameter setting of experiments must be saved as ".csv" files named "exp_.csv"
  file-open filename
  while [not file-at-end?]
    [
      ;;; the values of the file must follow this same order

      set initH round ((file-read / 100) * totalPatches)
      set initF round ((file-read / 100) * totalPatches)
      set baseIntGrowth file-read
      set maxExtGrowth file-read
      set initGroups file-read
      set effectivenessGr file-read
      set maxGroupChangeRate file-read
      set opt file-read
      set optimalGrowthIncrease file-read

      set endSimulation file-read ;- 1500 ;; use this to cut down the time of simulation (e.g. if the file reads 2000)
    ]
  file-close
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;; movie generation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to generate-animation

  ;;; this procedure generates a video sequencing the displays of a simulation (using the current parameter configuration).

  setup
  movie-start (word scenario ".mov") ;;; you can add more information in the name of the file (here, only scenario is used)
  repeat endSimulation [ go movie-grab-view ]
  movie-close
end 

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

Attached files

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

This model does not have any ancestors.

This model does not have any descendants.