Ants Benchmark

No preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 4.1pre9 • Viewed 353 times • Downloaded 45 times • Run 4 times
Download the 'Ants Benchmark' 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

globals [result]
turtles-own [ carrying-food? drop-size ]
patches-own [ chemical food nest? nest-scent food-source-number ]

;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  ca
  setup-turtles
  setup-patches
  do-plotting
end 

to benchmark
  random-seed 337
  reset-timer
  setup
  repeat 800 [ go ]
  set result timer
end 

to setup-turtles
  set-default-shape turtles "bug"
  cro ants [
    set size 2  ;; easier to see this way
    rt random-float 360
    set color red
    set carrying-food? false
  ]
end 

to setup-patches
  ask patches [
    set chemical 0
    set food 0
    set food-source-number -1
    setup-nest
    setup-food
    update-display
  ]
end 

to setup-nest  ;; patch procedure
  ;; set nest? variable to true inside the nest
  set nest? ((distancexy 0 0) < 5)
  ;; spread a nest-scent over the whole screen -- stronger near the nest
  set nest-scent (200 - (distancexy 0 0))
end 

to setup-food  ;; patch procedure
  ;; setup food source one on the right of screen
  if ((distancexy (0.6 * max-pxcor) 0) < 5)
  [ set food-source-number 1 ]

  ;; setup food source two on the lower-left of screen
  if ((distancexy (-0.6 * max-pxcor) (-0.6 * max-pycor)) < 5)
  [ set food-source-number 2 ]

  ;; setup food source three on the upper-left of screen
  if ((distancexy (-0.8 * max-pxcor) (0.8 * max-pycor)) < 5)
  [ set food-source-number 3 ]

  ;; set "food" at sources to either 1 or 2
  if (food-source-number > 0)
  [ set food (1 + random 2) ]
end 

to update-display  ;; patch procedure
  ;; give color to nest and food sources
  ifelse nest?
  [ set pcolor violet ]
  [ ifelse (food > 0)
    [ if (food-source-number = 1) [ set pcolor cyan ]
      if (food-source-number = 2) [ set pcolor sky  ]
      if (food-source-number = 3) [ set pcolor blue ]
    ]
    [ set pcolor scale-color green chemical 0.1 5 ] ;; scale color to show chemical concentration
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Runtime Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;

to go  ;; forever button
  ask turtles [ go-turtles ]
  diffuse chemical (diffusion-rate / 100)
  ask patches [ go-patches ]
  tick
  do-plotting
end 

to go-turtles  ;; turtle procedure
  if (who < ticks) ;; delay the initial departure of ants
  [ ifelse carrying-food?
    [set color orange + 1 return-to-nest ]  ;; if ant finds food, it returns to the nest
    [set color red    look-for-food  ]  ;; otherwise it keeps looking
  ]
end 

to go-patches  ;; patch procedure
  set chemical (chemical * (100 - evaporation-rate) / 100)  ;;slowly evaporate chemical
  update-display  ;; Refresh the Display
end 

to return-to-nest  ;; turtle procedure
  ifelse nest?  ;; if ant is in the nest, it drops food and heads out again
  [ set carrying-food? false
    rt 180 fd 1
  ]
  [ set chemical (chemical + drop-size) ;; drop some chemical, but the amount decreases each time
    set drop-size (drop-size - 1.5)
    if (drop-size < 1) [set drop-size 1]
    uphill-nest-scent   ;; head toward the greatest value of nest-scent
    wiggle              ;; which is toward the nest
    fd 1]
end 

to look-for-food  ;; turtle procedure
  if (food > 0)
  [ set carrying-food? true  ;; pick up food
    set food (food - 1)      ;; and reduce the food source
    set drop-size 60
    rt 180 stop         ;; and turn around
  ]
  ifelse (chemical > 2)
  [ fd 1 ]
  [ ifelse (chemical < 0.05) ;; go in the direction where the chemical smell is strongest
    [ wiggle
      fd 1]
    [ uphill-chemical
      fd 1]
  ]
end 

to uphill-chemical  ;; turtle procedure
  wiggle
  ;; sniff left and right, and go where the strongest smell is
  let scent-ahead [chemical] of patch-ahead 1
  let scent-right chemical-scent 45
  let scent-left chemical-scent -45

  if ((scent-right > scent-ahead) or (scent-left > scent-ahead))
    [ ifelse (scent-right > scent-left)
      [ rt 45 ]
      [ lt 45 ]
  ]
end 

to uphill-nest-scent  ;; turtle procedure
  wiggle

  ;; sniff left and right, and go where the strongest smell is
  let scent-ahead [nest-scent] of patch-ahead 1
  let scent-right get-nest-scent 45
  let scent-left get-nest-scent -45

  if ((scent-right > scent-ahead) or (scent-left > scent-ahead))
  [ ifelse (scent-right > scent-left)
    [ rt 45 ]
    [ lt 45 ]
  ]
end 

to wiggle  ;; turtle procedure
  rt random 40 - random 40
  if not can-move? 1
  [ rt 180 ]
end 

to-report get-nest-scent [ angle ]
  let p patch-right-and-ahead angle 1
  if p != nobody
  [ report [nest-scent] of p ]
  report 0
end 

to-report chemical-scent [ angle ]
  let p patch-right-and-ahead angle 1
  if p != nobody
  [ report [chemical] of p ]
  report 0
end 

to do-plotting
  if not plot? [ stop ]
  set-current-plot "Food in each pile"
  set-current-plot-pen "food-in-pile1"
  plot count patches with [pcolor = cyan]
  set-current-plot-pen "food-in-pile2"
  plot count patches with [pcolor = sky]
  set-current-plot-pen "food-in-pile3"
  plot count patches with [pcolor = blue]
end 

There are 3 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Ants Benchmark Download this version
Uri Wilensky almost 14 years ago Ants Benchmark Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.