Ant Colony

No preview image

1 collaborator

Default-person Tina Conis (Author)


(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.3 • Viewed 1557 times • Downloaded 91 times • Run 0 times
Download the 'Ant Colony' 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

Some feedback on your model

Hi Tina, First off - I think this is a neat idea for solving the traveling salesman problem and starting from the existing ants model is a great way to start, but I'll need a little more info from you to understand exactly how you want this to work. Can you explain to me your overall idea of how you wan to use the ant logic to help with the traveling salesman problem? Using the ant model, you have a way for ants to locate the food sources, and leave trails so others can find them. If you think of the food sources as 'homes' for the traveling salesmen - what is the next step for finding the best (or at least a good) route for all the homes? One quick comment about the model as it exists: In the setup method - the crt command creates turtles, but what you is ants, so you can replace 'crt' (which is short for create-turtles) with 'create-ants', which will create ants for your model. Send along your response to my above questions and I can give more directed feedback. Happy coding!

Posted over 11 years ago

Summary of my model

I haven't worked out my model completely yet, but I have an idea of how I want it to work. I want to start off with each food source being the nest for several ants but I don't know how to write the code to make that happen. I want the ants to travel from their original food sources to all of the other food sources and back, traveling to each food source (other than their nest), one exactly once. After that, they should travel around to each of the other food-sources, based on the pheromone trails, but not go back to their nests until the end of that cycle. This should repeat until a majority of the ants are following the same path. I want to be able to keep track of the paths and the path lengths somehow. Thank you for your advice

Posted over 11 years ago

Some thoughts on how to design your model

Hi Tina, I think your description makes sense to me. Here is what I am thinking for how you could about implementing this. 1 - each ant will need to know how many stops it needs to make in total, as well as keep track of where it has been and where it needs to go. 2 - after an ant leaves a food source, it leaves a phermone trail specific to that food source (so an ant leaving food source 2 leaves a different trail than an ant leaving food source 3). 3 - if the ant has not hit all the food sources yet, it wanders until it finds a phermone trail leading to a source it hasn't yet been to - so if the ant finds the pheramone trail for food source 3 but has already been there, it keeps walking; if it his the pheramone trail for food soruce 5 and hasn't visited it yet, it will then follow that trail. 4 - the ant continues wondering until it finds the last food source then returns back to the nest. How does all that sound? Does that make sense? Let me know and happy coding!

Posted over 11 years ago

That sounds great

Hi, That all makes sense. I like your idea of having different pheromone trails for each of the food sources. I was also thinking that (at least after the first cycle) the ants would determine which path to take depending on the strength of the pheromone trails. I'm fairly new to coding so I'm not exactly sure how I would go about writing the code for all of this. If you could give me any tips on that, that would be great. Thank you!

Posted over 11 years ago

Click to Run Model

breed [food-source
breed [ants]
ants-own [original_x_location 
patches-own [
  chemical             ;; amount of chemical on this patch
  ground               ;; color of ground                 ;; amount of food on this patch (1 or 2)
  food                ;; true on nest patches, false elsewhere
  nest-scent]           ;; number that is higher closer to the nest

;;; Setup procedures ;;;

to setup
  ;; (for this model to work with NetLogo's new plotting features,
  ;; __clear-all-and-reset-ticks should be replaced with clear-all at
  ;; the beginning of your setup procedure and reset-ticks at the end
  ;; of the procedure.)
  set-default-shape turtles "ant"  ;; makes them look like ants
  resize-world -40 40 -40 40
  ;;resize-world -30 30 -30 30

;;; Go procedures ;;;

to setup-food-sources
   set-default-shape food-source "circle"
  create-food-source number-of-food-sources [setxy random-xcor random-ycor] 
  ask food-source [set food number-of-food-sources]
  ask food-source [hatch-ants 1]
    ask ants[set size 3         ;; easier to see
    set color red 
    set original_x_location xcor
    set original_y_location ycor]    ;; red = not carrying food

to go  ;; forever button
  ask ants
  [  look-for-food         ;; not carrying food? look for it
     return-to-nest        ;; carrying food? take it back to nest
    fd 1 ]
  diffuse chemical (diffusion-rate / 100)
  ask patches
  [ set chemical chemical * (100 - evaporation-rate) / 100  ;; slowly evaporate chemical

to return-to-nest  ;; turtle procedure
  ask ants [setxy original_x_location original_y_location]
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; get from original code
   set chemical chemical + 60  ;; drop some chemical
    uphill-nest-scent        ;; head toward the greatest value of nest-scent

to look-for-food  ;; turtle procedure
  if not can-move? 1 [ rt 180 ] 
  if xcor = original_x_location and ycor = original_y_location [fd 2] ;;;;;;;;;;;;;;;;;;;;;;;;;;;get ants to ignore food on original food-source
  if food > 0
  [         ;; pick up food
    set food food - 1        ;; and reduce the food source
    rt 180                   ;; and turn around
    stop ]
  ;; go in the direction where the chemical smell is strongest
  if (chemical >= Chem-Low-Threshold) and (chemical < Chem-Upper-Threshold)
  [ uphill-chemical ]

;; sniff forward, left, and right, and go where the strongest smell is

to uphill-chemical  ;; turtle procedure
  let scent-ahead chemical-scent-at-angle   0
  let scent-right chemical-scent-at-angle  LoS
  let scent-left  chemical-scent-at-angle  (LoS * -1)
  if (scent-right > scent-ahead) or (scent-left > scent-ahead)
  [ ifelse scent-right > scent-left
    [ rt LoS ]
    [ lt LoS ] ]

;; sniff left and right, and go where the strongest smell is

to uphill-nest-scent  ;; turtle procedure
  let scent-ahead nest-scent-at-angle   0
  let scent-right nest-scent-at-angle  LoS
  let scent-left  nest-scent-at-angle  (LoS * -1)
  if (scent-right > scent-ahead) or (scent-left > scent-ahead)
  [ ifelse scent-right > scent-left
    [ rt LoS ]
    [ lt LoS ] ]

to wiggle  ;; turtle procedure
  rt random-normal 0 amount-of-wiggle
  ;; lt random-normal 0 amount-of-wiggle
  ;; if not can-move? 1 [ rt 180 ]

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

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

;; Credit to 1997 Uri Wilensky for frame of program

There are 2 versions of this model.

Uploaded by When Description Download
Tina Conis over 11 years ago updated model Download this version
Tina Conis over 11 years ago Initial upload Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.