This page was automatically generated by NetLogo 5.0.1.
The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.
In order for this to work, this file, your model file (antV5.nlogo), and the files NetLogoLite.jar and NetLogoLite.jar.pack.gz must all be in the same directory. (You can copy NetLogoLite.jar and NetLogoLite.jar.pack.gz from the directory where you installed NetLogo.)
On some systems, you can test the applet locally on your computer before uploading it to a web server. It doesn't work on all systems, though, so if it doesn't work from your hard drive, please try uploading it to a web server.
You don't need to include everything in this file in your page. If you want, you can just take the HTML code beginning with <applet> and ending with </applet>, and paste it into any HTML file you want. It's even OK to put multiple <applet> tags on a single page.
If the NetLogoLite files and your model are in different directories, you must modify the archive= and value= lines in the HTML code to point to their actual locations. (For example, if you have multiple applets in different directories on the same web server, you may want to put a single copy of the NetLogoLite files in one central place and change the archive= lines of all the HTML files to point to that one central copy. This will save disk space for you and download time for your users.)
powered by NetLogo
view/download model file: antV5.nlogo
This is a very simple model of some ants on a random walkabout starting at a nest. After the chosen number of steps (called start-energy), the ants will change color, and return to the nest following the outbound pathways, but by finding a shorter route.
As the ants proceeds on their walkabout, they deposit a smell at each step. On their return journey, when they cross a path, they sense the smell intensity to determine which direction is closest to the nest.
Use the “start-energy” slider to select how many outbound steps the ants will go before turning around and returning to the nest.
Use the “number-of-ants” slider to select how many ants you want to go walkabout.
Clicking on the “setup” button draws the nest and ants, and initializes all variables.
Clicking on the “go” button starts the ants on their journey.
At the top is a slider named “normal speed”. This slider speeds up the program, or slows it down. If it set to slow, the setup period can get long. You can always slide the “normal speed” slider towrds a faster selection for the setup, the move it to a slower setting before clicking the “go” button
An ant smells only in 8 different directions. If it is in the corner of one of the patches, then he may move diagonaly, and still end up in the same patch. The next step can then divert him off the return path at a steep angle.
Vary the speed to see the results quicker.
The next addition will be to have the ant search for, and find food, then return to the nest via the shortest route.
I didn’t use the “uphill” command because the ant stops if a surrounding patch is not of a higher value than where he is. I wanted him to chose a path regardless.
;;this is version 4
;;version 1--learn breeds
;;version 2--does energy level of ants
;;version 3--lays a trail of smells on the patches
;;version 4--To walk random for start-energy ticks, then find a shorter route home
;;version 5--more than one ant on walkabout and returning on a shorter path, but using other ant smells.
breed [ants ant]
breed [holes hole]
;;;breed [foods food]
ants-own [energy
smell-ahead
smell-right
smell-left
smell-ahead-right
smell-ahead-left
smell-behind-right
smell-behind-left
smell-behind
smell-here
smell-of-food
]
patches-own [
smell
food-taste
]
globals
[ stop-the-program
number-of-ants-in-hole
tk ;replacing ticks
]
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.)
;;__clear-all-and-reset-ticks
clear-all
create-ants number-of-ants
create-holes 1
set tk 0
;; create-foods 1
ask patches
[
set smell 0
ask patch 0 0 [ set smell start-energy ]
ask patch 45 40 [ set food-taste 100 ]
;;set plabel food-taste
]
;;;diffuse food-taste .99
ask ants
[
set color red
set shape "bug"
set size 5
setxy 0 0
set energy start-energy
]
ask holes
[
setxy 0 0
set pcolor black
set color brown
set shape "circle"
set size 6
stamp
;;die
]
;; ask foods
;; [
;; setxy 45 40
;;set pcolor black
;;set color blue
;;set shape "circle"
;;set size 4
;;stamp
;; ]
reset-ticks
end
to go
set tk (tk + 1)
if (stop-the-program = 1)
[
stop
]
ask ants
[ ;;Checks the energy level and decides what to do depending on it
pen-down
if (who > TK ) [stop] ;;this releases ants one at a time
if energy > 0 ;;ant is still on walk about
[
right random 90
left random 90
forward 1
set energy energy - 1
;; set label energy
if energy > smell
[
set smell energy
;; ifelse show-smells?
;; [ set plabel smell ]
;; [ set plabel "" ]
;; set plabel smell
]
]
if energy = 0 ;;and has reached the end of his walkabout
[
set color blue
rt 180
set energy energy - 1
]
if energy < 0 ;; ant is on his way back to the nest
[
set energy energy - 1
set smell-here sh
set smell-ahead sa
set smell-ahead-right sar
set smell-right sr
set smell-ahead-left sal
set smell-left sl
set smell-behind-left sbl
set smell-behind-right sbr
set smell-behind sb
if (sh = start-energy)
[
set number-of-ants-in-hole (number-of-ants-in-hole + 1)
if (number-of-ants-in-hole = number-of-ants)
[set stop-the-program 1]
die
stop
]
if (sh >= sa) and (sh >= sr) and (sh >= sl) and (sh >= sal) and (sh >= sar) and (sh >= sbl) and (sh >= sbr) and (sh >= sb)
[
right random 80
left random 80
;; set label "R"
forward 1
stop
]
if (sh <= sa) and (sa >= sr) and (sa >= sl) and (sa >= sal) and (sa >= sar) and (sa >= sbl) and (sa >= sbr) and (sa >= sb)
[
;; set label "S"
forward 1
stop
]
if (sh <= sar) and (sar >= sr) and (sar >= sl) and (sar >= sal) and (sar >= sa) and (sar >= sbl) and (sar >= sbr) and (sar >= sb)
[
;; set label "RA"
rt 45
forward 1
stop
]
if (sh <= sal) and (sal >= sr) and (sal >= sl) and (sal >= sa) and (sal >= sar) and (sal >= sbl) and (sal >= sbr) and (sal >= sb)
[
;; set label "LA"
left 45
forward 1
stop
]
if (sh <= sr) and (sr >= sa) and (sr >= sl) and (sr >= sal) and (sr >= sar) and (sr >= sbl) and (sr >= sbr) and (sr >= sb)
[
;; set label "R"
rt 90
forward 1
stop
]
if (sh <= sl) and (sl >= sr) and (sl >= sa) and (sl >= sal) and (sl >= sar) and (sl >= sbl) and (sl >= sbr) and (sl >= sb)
[
;; set label "L"
left 90
forward 1
stop
]
if (sh <= sbr) and (sbr >= sr) and (sbr >= sl) and (sbr >= sal) and (sbr >= sar) and (sbr >= sbl) and (sbr >= sa) and (sbr >= sb)
[
;; set label "RB"
rt 135
forward 1
stop
]
if (sh <= sbl) and (sbl >= sr) and (sbl >= sl) and (sbl >= sal) and (sbl >= sar) and (sbl >= sa) and (sbl >= sbr) and (sbl >= sb)
[
;; set label "LB"
left 135
forward 1
stop
]
if (sh <= sb) and (sb >= sr) and (sb >= sl) and (sb >= sal) and (sb >= sar) and (sb >= sbl) and (sb >= sbr) and (sb >= sa)
[
;; set label "B"
left 180
forward 1
stop
]
]
]
end
to-report this-taste
let p patch-here
report [food-taste] of p
end
to-report sh
let p patch-here
report [smell] of p
end
to-report sa
let p patch-ahead 1
report [smell] of p
end
to-report sar
let q patch-right-and-ahead 45 1
report [smell] of q
end
to-report sal
let r patch-left-and-ahead 45 1
report [smell] of r
end
to-report sr
let s patch-right-and-ahead 90 1
report [smell] of s
end
to-report sl
let t patch-left-and-ahead 90 1
report [smell] of t
end
to-report sbr
let q patch-right-and-ahead 135 1
report [smell] of q
end
to-report sbl
let r patch-left-and-ahead 135 1
report [smell] of r
end
to-report sb
let r patch-left-and-ahead 180 1
report [smell] of r
end