Skip to content

How to create a deme replication event

David Bryson edited this page Jan 17, 2014 · 1 revision

This tutorial will walk you through the steps involved in creating a deme replication event. It assumes that you have basic familiarity with C++ and Avida-ish stuff. There are several different deme replication events. Currently, they include events such as replicate when the deme is full, when the corners are occupied, when a set number of resources has been amassed (the consume-res event). For this tutorial, we'll be using 'consume-res' as an example. To add your new event: 

  1. Come up with a few definitions for your deme replication trigger. These need to include the name of the trigger (e.g., consume-res), which will be seen externally, and a deme trigger event constant name used for an enumeration (e.g., DEME_TRIGGER_CONSUME_RESOURCES). The enumeration allows you to refer to your trigger by name, rather than an integer.
  2. Add your deme trigger event constant name to the enumerated triggers. To do so, go to Definitions.h and search for enum eDEME_TRIGGERS. Add your item right before DEME_TRIGGER_UNKNOWN. For example, 

      DEME_TRIGGER_CONSUME_RESOURCES,   // 10

  3. Define your 'trigger' event as part of the Replicate Demes action. To do that, in PopulationActions.cc go to the class cActionReplicateDemes : public Action. Add the name of your trigger and a brief description to the comment: 

    'consume-res' ...demes that have consumed a sufficienct amount of resources

    Then, add the same trigger to the end of the list of else if statements  

     else if (in_trigger == "consume-res") m_rep_trigger = DEME_TRIGGER_CONSUME_RESOURCES

  4. Next, add the code that describes when your replication event will occur. In cPopulation.cc, locate the ReplicateDemes function: 

    void cPopulation::ReplicateDemes(int rep_trigger, cAvidaContext& ctx) 

    Within this function, add your new trigger both to the comments and to the switch statement. For example, for the 'consume-res' event the following line was added to the comment: 

     10:'consume-res' ...demes that have consumed a sufficienct amount of resources

     And this case statement was added to the switch statement: 

    case DEME_TRIGGER_CONSUME_RESOURCES: {

            // check how many resources have been consumed by the deme

            if (source_deme.GetTotalResourceAmountConsumed() <

                m_world->GetConfig().RES_FOR_DEME_REP.Get()) {

              continue;

     }

    Note that this code is using information about the deme. Clearly, if your method needs information from the deme and that information doesn't exist, you'll also need to write some code to do that... 

     

  5. Last, add your new fangled event to the events file (generally events.cfg) and make sure it works.  For example:  

    u 1:1:end ReplicateDemes consume-res

Clone this wiki locally