Friday, April 1, 2011

Signaling implementation in Avida

The code is, for the most part, done. Here's how we've implemented things:

The short version:

Organisms can both signal and receive signals. Signals are sent to everybody around them, and the best mate is chosen from all the received signals.

When organisms divide, their reproductive materials are preserved on a shelf labeled by the cell the organism was in; when another organism wants to mate with that organism, it retrieves a copy of most recent reproductive materials stored in that cell's shelf.

Initially, we require that signals be received to mate; later, we turn it off, and anyone who doesn't receive a signal (either doesn't try or didn't get a signal) just chooses a random shelf.

The long version:

We added two new instructions -- mate-signal and mate-receive. Organisms can do either or both, as often as they want.

When mate-signal is executed, a message (piggybacking off of the existing messaging code) is broadcast to all organisms within a certain radius of the sender. Only a certain number (default 8) of signals are 'remembered', the oldest signal is forgotten first. The message contains the cell ID of the signaler.

When mate-receive is executed, a message is selected from among all those received. Currently it's selected at random, I'm going to change that to by merit this weekend. The message -- the cell ID of the signaler -- is stored as mateID in the receiver's phenotype. During this procedure, all received signals are 'forgotten' (mostly for coding convenience, as the only code I dug deep enough to find for that datatype was a pop). With pure random selection this forgetfulness seemed like it might become an interesting analogue for attention, but if we switch to choosing by merit it shouldn't make any difference. I'm still a little worried that choosing by merit may have unintended consequences, I haven't fully thought out where that pressure will be applied.

If the organism has received no signals, mateID is instead set to -2 to indicate a failed receive. (I need to change this slightly, as it will currently overwrite any previous successful receives!)

When an organism divides via divide-sex, it goes into the birth chamber and checks in with our new (and awkwardly named) cBirthMateSelectHandler_GameteStorage. This mate selection class first stores the offspring created by the divide -- the gamete, more or less -- in an array indexed by the parent's cell ID. Gametes are stored until overwritten by another entry for that cell ID.

If the organism has received a signal, it checks to see if a gamete is available for the cell ID stored in its mateID: if yes, it's used to generate offspring; if not, mating fails. (Note that here, organisms that have signaled but not yet divided will not have stored their gametes; in this case, very early in the sim the spot will be empty, and for the rest of the sim will contain the gamete of a dead organism. This should be rare enough to not cause problems.)

If the organism has not received a signal, we check the new SIGNAL_RECV_NECESSARY_TO_MATE configuration parameter. If it's true, mating fails. If it's false, this organism chooses a random cell ID; if a gamete is stored for this cell ID, it's used to generate offspring; if not, mating fails (and this case should be pretty rare).

And that's it. Now (well, after I make the above mentioned small changes) we have to get it running on something, make sure we can get the data we need out of Avida without further modification (we may need to set signaling to a task, for example), and then see if Avida can find any holes in our model that need to be patched up.

No comments:

Post a Comment