Beehive Migration

Beehive Migration preview image

2 collaborators

Default-person Vidushi Patel (Author)
Bryan Boruff (Advisor)

Tags

beekeeping 

Tagged by Vidushi Patel almost 3 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.2.0 • Viewed 211 times • Downloaded 22 times • Run 0 times
Download the 'Beehive Migration' 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

globals [ num_months harvest_rate harvest_rate_premium harvest_rate_high_rich harvest_rate_low_rich]
breed [ beekeepers beekeeper]
breed [ loads load ]

patches-own [ harvest_count
  high_rich?
  premium?
  available_forage
  sp_rich
  availability
  richness
  favorite_sp
  favorite_sp?
  my_agentid
]
beekeepers-own [
  potential_targets
  my_targets
  split_number
  reftarget
  my_home
  num_loads
  my_loads
  distance_this_tick
  total_distance_travelled
  num_moved
  used_targets
  No_target_found
  full_time?
  want_move?
]

loads-own [
  load_id
  my_forage_cell
  visited?
  move_count
  used_forage_cells]


;;;Setup Commands

to setup
  ca
  random-seed 0
  set num_months 12
  grow_forest
  make_beekeepers
  make_loads
  reset-ticks
end 

to grow_forest
  ask patches [
    if random 2 = 1 [ set pcolor 57 ]
  ]

  setup_monthly_forage_availability
end 

to setup_monthly_forage_availability

  ifelse forage_availability_setup = "baseline" [

    ask patches [
      set harvest_count 0
      set my_agentid [ ]
      set availability [ ]
      set sp_rich [ ]
      set favorite_sp [ ]

      repeat num_months [
        set availability lput random 2 availability
        set sp_rich lput random 9 sp_rich
        ;set favorite_sp lput random 2 favorite_sp - use this line instead of the following line for random distribution of favorite species across the region
        ifelse pxcor < -15  [ set favorite_sp lput random (2 + 1) favorite_sp ][ set favorite_sp lput random 1 favorite_sp ]
      ]
    ]
  ]
  [  ask patches [
    set harvest_count 0
    set my_agentid [ ]
    set availability [ ]
    set sp_rich [ ]
    set favorite_sp [ ]

    repeat num_months [
      set availability lput random 2 availability
      set sp_rich lput random 9 sp_rich
      ;set favorite_sp lput random 2 favorite_sp - use this line instead of the following line for random distribution of favorite species across the region
      ifelse pxcor < -17  [ set favorite_sp lput random (2 + 1) favorite_sp ][ set favorite_sp lput random 1 favorite_sp ]
    ]
    ]
  ]
end 

to make_beekeepers
  let beekeeper_home up-to-n-of (beekeeper_population) patches with [ pcolor = black]
  ask beekeeper_home [ sprout-beekeepers 1 ]
  ask beekeepers [
    set shape "person"
    set size 2
    set my_home patch-here

  ]
  ifelse beekeeper_proportion = "baseline" [ ask n-of ((beekeeper_population) * 0.1) beekeepers [ set full_time? true ] ]
  [ifelse beekeeper_proportion = "equal" [ ask n-of ((beekeeper_population) * 0.5) beekeepers [ set full_time? true ] ]
    [ ask n-of ((beekeeper_population) * 0.9) beekeepers [ set full_time? true ] ] ]


  ; ask n-of ((beekeeper_population) * 0.5) beekeepers [ set full_time? true ]
  ask beekeepers [ ifelse full_time? = true [ set num_loads random 14 + 5  set color blue ] [ set num_loads random 4 + 1 set full_time? false set color red ] ]
  ;    ;set num_loads random 15 + 1
  ;    if num_loads > 5 [ set full_time? false set color red]
  ;    ;set label num_loads
  ;
  ;   ; pen-down
  ; ]
end 

to make_loads
  ask beekeepers [

    hatch-loads num_loads [
      set shape "box"
      set size 1
      pen-up

      set load_id [ who ] of myself
      set my_forage_cell [my_home] of myself
      set label ""
      set move_count 0
      set used_forage_cells [ ]

    ]

    set my_loads loads with [ load_id = [who] of myself ]
  ]
end 

;;;On Tick

to clear_labels ; global command
  ask patches [ set plabel ""]
end 

to go
   clear_labels
  ;clear-drawing
  if (ticks < 1) [ reset-timer]

  if ticks = num_months
  [
    ask beekeepers [
      move-to my_home
      ask my_loads [ move-to [my_home] of myself ]
    ]


    ask patches with [ harvest_count > 0 ] [
    ;set plabel my_agentid
    set pcolor yellow
    ]
    show (word "execution finished in "timer" seconds" )
    stop
  ]

  ask beekeepers [
    set split_number 0
    set num_moved 0
    if available_forage = 0 [ set want_move? true
      pick_new_target ]
  ]

  update_availability
  update_targets

  relocate
  set harvest_rate ((count patches with [ harvest_count > 0]) / count patches ) * 100
  set harvest_rate_premium ((count patches with [ harvest_count > 0 AND premium? = true ]) / (count patches with [premium? = true]))* 100
  set harvest_rate_high_rich ((count patches with [ harvest_count > 0 AND high_rich? = true ]) / (count patches with [high_rich? = true])) * 100
  set harvest_rate_low_rich (count patches with [ harvest_count > 0 AND high_rich? = false ]) / (count patches with [high_rich? = false])* 100
  wait .5


  tick
end 

to update_availability ; global command
  ask patches [
    set available_forage item ticks availability
    set richness item ticks sp_rich
    set favorite_sp? item ticks favorite_sp

    ifelse available_forage = 0 [
      set pcolor black
    ] [
      set pcolor 57
    ]

    ifelse favorite_sp? = 0 [
      set premium? false
    ] [
      set premium? true
      set pcolor 125
    ]

    ifelse richness > defined_richness [
      set high_rich? true
    ] [
      set high_rich? false
    ]
  ]
end 

to update_targets
  ask beekeepers  [ if available_forage = 0 [ pick_new_target ]]
end 

to pick_new_target ; Beekeeper chooses nearby patch, prioritizing premium and rich patches
  ifelse full_time? = false [ set  potential_targets patches with [(available self) and (distance myself < proximity)]] [ set potential_targets patches with [(available self)] ]
  ;;;;;;;;;;;;;;;;;;;;;;;;;;  decision criteria ;;;;;;;;;;;;;;

  ifelse any? potential_targets[
    ( ifelse

      any? potential_targets with [ premium? = true] [
        set my_targets potential_targets with [ premium? = true]
      ]

      any? potential_targets with [ high_rich? = true] [
        set my_targets potential_targets with [ high_rich? = true]
      ]

      [ set my_targets potential_targets ]
  )] [ move-to my_home
    set No_target_found No_target_found + 1
    set color red
    ask my_loads [ move-to [my_home] of myself] ]

  set reftarget one-of my_targets
  set split_number split_number + 1
end 

to relocate
  ask loads [ migrate ]
  ; wait .5
  ask beekeepers [ travel ]
end 

to migrate ; load command
  let bkpr beekeeper load_id
  let target [reftarget] of bkpr

  let open_spots patches with [ (patch_distance self target < spread) AND (available self) ]

  ( ifelse
    any? open_spots with [ premium? = true ] [
      set open_spots open_spots with [ premium? = true ]
    ]

    any? open_spots with [ high_rich? = true ] [
      set open_spots open_spots with [ high_rich? = true ]
    ]

  )


  if [available_forage] of patch-here = 0  [

    ifelse (any? open_spots) [
      set my_forage_cell one-of open_spots
    ] [
      ifelse [split_number] of bkpr < 2
      [
        ask bkpr [ pick_new_target ]
        migrate
      ] [
        set my_forage_cell [my_home] of bkpr
      ]
    ]
    move-to my_forage_cell
    set move_count move_count + 1
    set used_forage_cells lput patch-here used_forage_cells
  ]



  ask my_forage_cell [
    set harvest_count harvest_count + 1
    set my_agentid lput [who] of bkpr my_agentid
    ;set pcolor red
  ]
  ; wait .1
end 

to travel ;Travels to loads one at a time, uses the nearest-neighbor algorithm
  set distance_this_tick 0
  ask my_loads [ set visited? FALSE ]
  let unvisited_loads my_loads with [ visited? = FALSE ]

  while [any? unvisited_loads] [
    let closest_load min-one-of unvisited_loads [ distance myself ]
    set distance_this_tick distance_this_tick + patch_distance patch-here closest_load
    move-to closest_load
    set num_moved num_moved + 1

    ask closest_load [ set visited? TRUE ]
    set unvisited_loads unvisited_loads with [ visited? = FALSE ]
  ]

  set distance_this_tick distance_this_tick + distance my_home
  set total_distance_travelled total_distance_travelled + distance_this_tick
end 

;;;reporters

to-report available [pch]
  ifelse ([pcolor] of pch = 57 or [pcolor] of pch = 125) AND (not any? loads-here)
  [report true]
  [report false]
end 

to-report patch_distance [ pch1 pch2 ]
  let x1 [pxcor] of pch1
  let y1 [pycor] of pch1

  let x2 [pxcor] of pch2
  let y2 [pycor] of pch2

  let xdiff x1 - x2
  let ydiff y1 - y2

  report sqrt (xdiff ^ 2 + ydiff ^ 2)
end 

;;;;;;;;;;;;;;;;;;; output reporters ;;;;;;;;;;;;;;;;;;;;;;;;;

to-report initial_forage
  report count patches with [ harvest_count = 0] * 100  / count patches
end 

to-report premium_cells
  report count patches with [premium? = true]
end 

to-report rich_cells
  report count patches with [premium? = true]
end 

to-report percent_harvested
  report (count patches with [ harvest_count > 0 ] / count patches ) * 100
end 

to-report percent_harvested_premium
  report (count patches with [ harvest_count > 0 AND premium? = true] / count patches with [ premium? = true]  ) * 100
end 

to-report percent_harvested_rich
  report (count patches with [ harvest_count > 0 AND high_rich? = true] / count patches with [ high_rich? = true]  ) * 100
end 

to-report beekeepers_with_no_target
  report count beekeepers with [ No_target_found > 0 ]
end 

to-report distance_commercial
  report mean [total_distance_travelled] of beekeepers with [full_time? = true]
end 

to-report distance_semi_commercial
  report mean [total_distance_travelled] of beekeepers with [full_time? = false]
end 

There are 5 versions of this model.

Uploaded by When Description Download
Vidushi Patel over 2 years ago Visualization updated Download this version
Vidushi Patel over 2 years ago Improved visualization Download this version
Vidushi Patel almost 3 years ago Updated for better visualization of harvested patches Download this version
Vidushi Patel almost 3 years ago Cleaned code Download this version
Vidushi Patel almost 3 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Beehive Migration.png preview Preview for 'Beehive Migration' almost 3 years ago, by Vidushi Patel Download

This model does not have any ancestors.

This model does not have any descendants.