Ant sort

Authors: Alex Tee Neng Heng, David G. Green

Ant colonies emerge from activity of many individuals behaving according to simple rules. This model has been adapted as a heuristic sorting algorithm for open-ended sorting.

Here an “ant” picks up any object they come across and drop it again when they find other objects of the same type (colour). Order emerges by positive feedback: large piles of objects grow at the expense of small ones.

How to use the simulation

You need to have Java version 1.5 installed for your browser in order to run the simulation applet.

In the main simulation window you can see a 2-dimensional area with the objects scattered randomly across. Some of the objects are moving – they are being carried by an ant.

  • Use the + and buttons to control the speed of the simulation.
  • Use a drop-down menu to net the Number of Ants in the simulation.
  • Use a drop-down menu to control the Number of Objects to be sorted by the simulated ants.
  • Use a drop-down menu to set the Number of different object types (colours) to which the sorted objects belong.
  • With the slider at the bottom of the options panel you can control how often the ants change direction when moving across the area.


  • Use the control panel to the set the simulation speed to a small value and watch how particular ants go about doing their job.
  • Set the simulation speed to a high value and observe the landscape from a bird’s eye view watching how the area slowly becomes ordered.
  • Try varying the number of ant and the number of objects and their types and observe how this affects the sorting performance.
  • Try changing the frequency with which the ants change the direction of their walking. How does this affect the outcome?

Demo screenshot