Boids in Swarm

Original code: Eric Werk
Obtained from Glen Ropella 2/26/2000
Revisions by Steve Jackson (jackson3@humboldt1.com) and Steve Railsback (LRA@Northcoast.com), October 2000.

CODE NOTES:

1. We eliminated a number of serious memory leaks. If the display canvas is used (see below), there is still a minor memory leak but it is now safe to run this application for demos, etc. (It used to have leaks severe enough to crash a laptop in a few minutes.)

2. One of the original data structures (object PriorityQueue, apparently originally intended as a list of boids visible to the boid making its movement calculations) was not working correctly and was not necessary. This structure is no longer used and the error was corrected. Consequently, this new version of Boids does not behave exactly as Eric Werk's original does.

3. The original Canvas display object was retained but it (a) has a memory leak and (b) does not currently function reliably in Windows. The Windows problem may be because of this problem reported (along with a fix) by Glen Ropella:

"To get it to run, you need access to
globalTkInterp, which Marcus disabled in 2.0.1.  If you're using
2.0.1, then follow Marcus' instructions:

 >Change "extern id <TkExtra> globalTkInterp"
 >to "externvar <TkExtra> globalTkInterp" in 
Swarm-2.0.1/include/tkobjc/global.h
 >and then "#import <tkobjc/global.h>".

Then compile the app."

We added an alternative display object, a zoom raster that lacks the fancy display capabilities of the Canvas. Users can select one or both displays at run time using the probe display window. (The zoom raster is the default.)

This code was originally written for Swarm 1.4.1. We revised it in 2.0.1 but it seems to work in 2.1.1.

MODEL NOTES:

This version of Boids uses a movement formulation that is fairly elaborate and difficult to explain. There are actually up to six criteria for determining movement. The order in which the different movement criteria are applied (collision avoidance, maintaining speed, flock centering, velocity matching, etc.) is important, and the methods for calculating and applying the acceleration vector are counterintuitive. (This is all in Boid.m) Expect to spend several hours in the code before attempting to understand exactly what it is doing. In this version, we made no attempt to improve or document the formulation. 

The code does include a very complete and useful vector math object. 

Steve Railsback 
30 October, 2000
