How Do Ants Walk Ina Straight Line

From RichardFeynman's Surely You're Joking, Mr. Feynman. He put a crumb on the edge of the bathtub and waited. The first ant rambled around until it found the food, then dashed off, presumably laying a return trail. As ants filed back in to get bits of the food, Feynman drew their trails in pencil. At the beginning, they did NOT go straight along the first ant's trail to the food. They were pretty random, too. Over time, as they came rushing in, they straightened out the path, until there was a nice long, straight line of ants taking the shortest distance to the food.

"Many years later, when I was at Caltech and lived in a little house on Alameda Street, some ants came out around the bathtub."

To the question "What kind of fool encourages ants to come into his home?" the answer is possibly - one who thinks deeply about simple things.

Ron's description of refactoring in BridgePatternIsJustGoodFactoring reminds me of the first ants doing pretty much anything and then straightening it out over time. My question is, Do we have to go through this every time we start programming? Don't we learn anything from our previous programs? I think the answer is Yes, and the reason Bridge and those other ones make fine patterns is that they save some future ants from going through all those initial wiggles.

Just because it is possible to derive one thing from another doesn't mean it's not a good idea to learn the derived thing directly. Encapsulation can be derived from refactoring, but some of us would like to think through the encapsulation issue directly. I am hoping that ShieldPattern and its relatives help with that.

-- AlistairCockburn

If I sounded like I hate ShieldPattern, or learning derived things, I apologize. By identifying it with Encapsulation, I'm trying to drive out the essence of the idea. And I'm legitimately confused.

I can identify strongly with Alistair's hope - after all, I've spent ages learning how to do this stuff and I'd hate to think I had to forget it all.

On ChryslerComprehensiveCompensation, we have consciously used famous patterns only a few times. Our Bins are so complex with Composite, for example, that no normal person can work on them. (Kind of like the typical Window system, rife with Bridge and whatnot.)

The real trick with the technoid patterns (and I suppose with any) is to know when to apply them, and how. And in the XP context ... how gently.

-- RonJeffries (not the oldest living Smalltalk programmer)

Hmmm... people in Norway retire at 67, and I am working with a Norwegian retired-but-still-programming Smalltalk programmer who started programming Smalltalk in 1974... am surprised you are older or started earlier and can still type :-) -- AlistairCockburn


DaveSmith remembered a theory he heard about how ants use a small number of rules to achieve a straight line:

Solo ants follow the trail, and don't help straighten it. Eventually, though, traffic to and from the food increases. Ants bump into each other. Ants see ants ahead taking a (more) direct line, and help establish a new fresh trail.

Over time, the tiny straightenings contribute to the eventual straight line.

People wonder: "What if the ant ahead turns a corner?" Remember that the ants are close to each other, if following like that. And also remember: The path changes slowly, so there's probably always a trail nearby. The ants might just sync to that, or perform a random walk.

Hopefully an ant doesn't find its own trail. RichardFeynman describes in his autobiography-like book how he thought about getting the ants to loop around in a circle, didn't have the patience to try and set it up.

PeterMerel wonders if human efforts aren't basically the same thing.

I observe that this algorithm is not sufficient and doesn't always work. Put the ants' home in one corner of a room, a food source in an adjacent corner, an obstacle in the middle and a barrier cutting off the direct route.

The ants learn the obvious short route. Now remove the barrier but leave the obstacle. By the given algorithm the ants will never find the direct route.

For a while yes. But 1000 out of the million ants are wanderers: they don't follow trails, they wander out for some reason (maybe they're crazy fools). Of these 1000, 10 find the (same) food, and 1 of these gets back by a shorter path (than the above), and eventually this path get known and more travelled (by the processes already explained). I guess.

Sometimes a jump change is needed.


Just for completeness... ants don't actually worry about other ants on the trail ahead of them. Not for foraging, anyways. However, a little thought shows this is a needlessly complexifying assumption: all ants need to do is have non-zero look-ahead and cut corners when they can. This is pretty much how people make straight paths, too.

Well, it would be true if people actually made straight paths, but they don't. What I see happening is that one person makes the first path and then it is more convenient to follow that path, even with its sub-optimal non-straight course than it is to try to straighten it. Then the more people walk on the non-straight path the more there is increased resistance to changing it. Eventually you wind up with a high-quality (easy to follow), but wandering path. I guess the lesson here is to be sure you make the path straight the very first time, if that's the kind of thing you care about. -- AndyPierce

Okay, I should have added the qualifier when they do. But I think you'll find in most cases ants don't walk in straight lines either, only when there are next-to-no obstacles to interfere with straightening. Also btw, as for the ants going in circles, there is nothing to stop them and every now and then an army ant colony gets stuck in a fatal ant wheel.


Actually, it should be difficult to make ants go in a circle using food trails, since the scent trail they are following doesn't get reinforced until the ant starts coming back with food. This also gives the trail a chance to dissipate once the food is gone. Ant wheels are a somewhat different effect, and in them, you have a few ants wandering around in the middle, serving as an obstacle to all the others.

Those ants in the middle are the ones trying to reinvent the ant wheel.


Okay, well that straightens that out. Now, can someone tell me how ants pass the breath-a-lizer test? -- WaldenMathews


I remember a few years ago noticing an ant on the table. It was walking round in circles. It carried on doing this for several hours, a 5cm diameter circle. The centre of the circle slowly moved about 10cm over the hours. I was intrigued. Looking closer I noticed that the ant had one of its two antennae missing. I have no idea how the ant got there, but I presume that it thought it was walking in a straight line. -- DaveBerkeley

I think this is a good contribution to this topic...


Most of the discussion above seems to assume ants are like CellularAutomata only directly aware of a small region in front of them. In actuality they use their eyes like people and reference "landmarks" albeit in a more limited way. See http://jeb.biologists.org/cgi/content/full/207/3/385/-a. Obviously local sight/sensing is important. It would be interesting to compare the patterns with SmallWorld theory, where systems (cells, the Internet, populations) are modeled by DirectedGraphs, most nodes having few local connections but a few "long-range" connections and hubbing. In this case the edges would be sight/sense "vectors" and the nodes local cues and distant landmarks. What percentage and sequence would the ant brain allocate to local versus remote sensing? Some more details on the question of insect sight ("insects compute excellently 3D motion") are at http://www.cfar.umd.edu/~larson/dialogue/newCameraTech.html, though not specific to SmallWorlds. next question from 13-year-old Racquel Laron: if ants can't see, what species of ant carries one of its same species into a pit in their anthill that is supposed to be the colony's "graveyard" when it loses a scent secreted by this species of ant? I wish someone would answer this.


Picture of Ant


EditText of this page (last edited September 4, 2012) or FindPage with title or text search