Friday, 14 June 2013

An Ant Metropolis

jQuery UI Slider - Multiple sliders

The Metropolis algorithm has been used to simulate just about everything, let's try ants. We have four types of ant: red, black, green and blue. Red ants like green and blue ones but dislike black. Black ants like green and blue ones but dislike red. Green and blue like all three other types. All the ants are indifferent to ants of their own colour. "Dislike" means that if a red ant is close to a black one its "happiness" goes down. First we'll put our ants on a lattice. Then we'll give every ant a happiness that gets increased by one if an ant it likes is on the same lattice point and decreased by one for every ant it doesn't like. We can encode this in an interaction matrix: \[ H = \left( \begin{array}{cccc} 0 & -1 & 1 & 1 \\ -1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 \\ 1 & 1 & 1 & 0 \end{array} \right) \]

Then the Metropolis algorithm proceeds as before, we propose a random direction for the ant to move: north, south, east or west. If it will increase happiness or keep the happiness the same we accept it, if it decreases happiness we accept it with probability $\exp( -\Delta E \beta)$ where $\Delta E$ is the change in happiness and $\beta = 1/T$, where $T$ is something analogous to temperature. $\beta$ controls how much the ants care about their mutual attraction and repulsion. When it is low the ants don't notice each other as much, when it is high they care a lot where they live. You could call it... blindness? sociability? sensitivity? social-sensitivity? I will stick with $\beta$.

Anyway, below is a little animation of the ants running around. When $\beta$ is low they don't care about each other and run around like idiots. When it's high they get into clusters with the ants they like. You can see the red ones avoiding the black ones. The sliders are for $N$ the number of ants and $\beta$. You can also type in your own interaction matrices. How about, \[ H = \left( \begin{array}{cccc} 1 & -1 & -1 & -1 \\ -1 & 1 & -1 & -1 \\ -1 & -1 & 1 & -1 \\ -1 & -1 & -1 & 1 \end{array} \right) \] racist ants? \[ H = \left( \begin{array}{cccc} 0 & 1 & 1 & -2 \\ 1 & 0 & 1 & -2 \\ 1 & 1 & 0 & -2 \\ 1 & 1 & 1 & 0 \end{array} \right) \] or cluster bombers?




No comments:

Post a comment