Path Finding ants

No preview image

1 collaborator

Avatar_black Leo B (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.2.2 • Viewed 42 times • Downloaded 4 times • Run 0 times
Download the 'Path Finding ants' 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

breed [ants ant]
ants-own [
  distance_to_home
  distance_to_target
  mode
  speed
]

breed [houses house]
breed [sugars sugar]

directed-link-breed [connections connection]
connections-own [
  death-time
]

to setup
  clear-all

  add_house
  add_sugar

  create-ants number_of_turtles [
    set distance_to_home 0
    set distance_to_target 10000
    set speed random-float 1.5
    set mode "hunt"
    set color red
    set shape "bug"
    set size 0.5
    move-to one-of houses
  ]
  reset-ticks
end 

to go
  ask ants [
    update_position

    check_target_reached

    move_max_distance

    emit_info
  ]

  ask connections [
    if ticks >= death-time [die]
  ]

  tick
end 

to add_sugar
  create-sugars 1 [
    setxy random-xcor random-ycor 
    move-to one-of patches with [not any? other houses in-radius distance_locations]
    move-to one-of patches with [not any? other sugars in-radius distance_locations]
    set color yellow
    set shape "circle"
    set size 4
  ]
end 

to add_house
  create-houses 1 [ 
    setxy random-xcor random-ycor 
    move-to one-of patches with [not any? other houses in-radius distance_locations]
    move-to one-of patches with [not any? other sugars in-radius distance_locations]
    set color blue
    set shape "circle"
    set size 4
  ]
end 

to update_position
  rt random 10
  lt random 10
  fd speed
  set distance_to_home distance_to_home + 1
  set distance_to_target distance_to_target + 1
end 

to check_target_reached
  ifelse (mode = "hunt" and any? sugars-here) [
    set distance_to_target 0
    set mode "home"
    set color blue
    rt 180
  ] [if (mode = "home" and any? houses-here) [
    set distance_to_home 0
    set mode "hunt"
    set color red
    rt 180
  ]]
end 

to move_max_distance
  ; check that not lost
  if (distance_to_home >= max_search_distance and mode = "home") or
  (distance_to_target >= max_search_distance and mode = "hunt") [
    rt random 90
    lt random 90
  ] 
end 

to emit_info 
  let emiter self
  let clue_distance_home distance_to_home + max_emit_radius
  let clue_distance_target distance_to_target + max_emit_radius

  ask ants in-radius max_emit_radius [
    ifelse mode = "hunt" and clue_distance_target <= distance_to_target [
      set distance_to_target clue_distance_target
      face emiter
      if display_links? [
        create-connection-from emiter [
          set color red
          set death-time ticks + 5]]
    ] 
    [if mode = "home" and clue_distance_home <= distance_to_home [
      set distance_to_home clue_distance_home
      face emiter
      if display_links? [
        create-connection-from emiter [
          set color blue
          set death-time ticks + 5]]
    ]]
  ]
end 

to setup_avg_plots
  clear-all-plots
end 

to plot_avg_home
  let avg-distance-to-home mean [distance_to_home] of ants

  ; plot the average distance to A
  plotxy ticks avg-distance-to-home
end 

to plot_avg_target
  let avg-distance-to-target mean [distance_to_target] of ants

  ; plot the average distance to B
  plotxy ticks avg-distance-to-target
end 

to plot_mode_home
  plotxy ticks count ants with [mode = "home"]
end 

to plot_mode_target
  plotxy ticks count ants with [mode = "hunt"]
end 



There is only one version of this model, created 12 months ago by Leo B.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.