Avida

 

Changeset 3632

Show
Ignore:
Timestamp:
02/08/10 11:03:19 (7 months ago)
Author:
dk
Message:

Added neighborhood-based HGT conjugation.

Location:
development/source
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • development/source/actions/PopulationActions.cc

    r3631 r3632  
    44604460 would be... complications... to runtime changes to an organism's genome... 
    44614461 */ 
    4462 class cActionConjugate : public cAction { 
     4462class cActionAvidianConjugation : public cAction { 
    44634463public: 
    44644464        static const cString GetDescription() { return "Arguments: (prob. of donation)"; } 
    44654465   
    44664466        //! Constructor. 
    4467   cActionConjugate(cWorld* world, const cString& args) : cAction(world, args), m_donation_p(-1.0) { 
     4467  cActionAvidianConjugation(cWorld* world, const cString& args) : cAction(world, args), m_donation_p(-1.0) { 
    44684468                cString largs(args); 
    44694469                if(largs.GetSize()) { 
     
    46884688         
    46894689        action_lib->Register<cActionDiffuseHGTGenomeFragments>("DiffuseHGTGenomeFragments"); 
     4690        action_lib->Register<cActionAvidianConjugation>("AvidianConjugation"); 
    46904691         
    46914692  // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7. 
  • development/source/main/cPopulationCell.cc

    r3629 r3632  
    159159} 
    160160 
     161/*! Recursively build a set of occupied cells that neighbor this one, out to the given depth. 
     162*/ 
     163void cPopulationCell::GetOccupiedNeighboringCells(std::set<cPopulationCell*>& occupied_cell_set, int depth) const { 
     164        // we'll do this the easy way, and just filter the neighbor set. 
     165        std::set<cPopulationCell*> cell_set; 
     166        GetNeighboringCells(cell_set, depth); 
     167        for(std::set<cPopulationCell*>::iterator i=cell_set.begin(); i!=cell_set.end(); ++i) { 
     168                if((*i)->IsOccupied()) { 
     169                        occupied_cell_set.insert(*i); 
     170                } 
     171        } 
     172} 
     173 
    161174/*! These values are chosen so as to make loops on the facing 'easy'. 
    162175 111 = NE 
  • development/source/main/cPopulationCell.h

    r3629 r3632  
    104104        //! Recursively build a set of cells that neighbor this one, out to the given depth. 
    105105  void GetNeighboringCells(std::set<cPopulationCell*>& cell_set, int depth) const; 
     106        //! Recursively build a set of occupied cells that neighbor this one, out to the given depth. 
     107  void GetOccupiedNeighboringCells(std::set<cPopulationCell*>& occupied_cell_set, int depth) const; 
    106108  inline cPopulationCell& GetCellFaced() { return *(m_connections.GetFirst()); } 
    107109  int GetFacing();  // Returns the facing of this cell. 
  • development/source/main/cPopulationInterface.cc

    r3629 r3632  
    222222  switch(m_world->GetConfig().NET_STYLE.Get()) 
    223223  { 
    224                         case 1: // Receiver Facing 
     224                case 1: // Receiver Facing 
    225225    { 
    226226      cOrganism* cur_neighbor = cell.ConnectionList().GetFirst()->GetOrganism(); 
     
    228228      if (cur_neighbor != NULL && (msg = cur_neighbor->NetPop()) != NULL) return msg; 
    229229    } 
    230                                 break; 
    231                                  
    232                         case 0: // Random Next - First Available 
    233                         default: 
     230                        break; 
     231                         
     232                case 0: // Random Next - First Available 
     233                default: 
    234234    { 
    235235      const int num_neighbors = cell.ConnectionList().GetSize(); 
     
    242242      } 
    243243    } 
    244                                 break; 
     244                        break; 
    245245  } 
    246246   
     
    648648 */ 
    649649void cPopulationInterface::DoHGTDonation(cAvidaContext& ctx) { 
     650        cPopulationCell* target=0; 
     651         
    650652        switch(m_world->GetConfig().HGT_CONJUGATION_METHOD.Get()) { 
    651                         case 0: { // faced individual 
    652                                 cPopulationCell* faced = GetCellFaced(); 
    653                                 if(faced->IsOccupied()) { 
    654                                         fragment_list_type fragments; 
    655                                         cGenomeUtil::RandomSplit(ctx,  
    656                                                                                                                                          m_world->GetConfig().HGT_FRAGMENT_SIZE_MEAN.Get(), 
    657                                                                                                                                          m_world->GetConfig().HGT_FRAGMENT_SIZE_VARIANCE.Get(), 
    658                                                                                                                                          GetOrganism()->GetGenome(), 
    659                                                                                                                                          fragments); 
    660                                         faced->GetOrganism()->GetOrgInterface().ReceiveHGTDonation(fragments[ctx.GetRandom().GetInt(fragments.size())]); 
    661                                 } 
    662                                 break; 
    663                         } 
    664                         default: { 
    665                                 m_world->GetDriver().RaiseFatalException(1, "HGT_CONJUGATION_RECV_METHOD is set to an invalid value."); 
    666                                 break; 
    667                         } 
    668         } 
     653                case 0: { // faced individual 
     654                        target = GetCellFaced(); 
     655                        if(!target->IsOccupied()) { 
     656                                // nothing to do, we're facing an empty cell. 
     657                                return; 
     658                        } 
     659                        break; 
     660                } 
     661                case 1: { // selected at random from neighborhood 
     662                        std::set<cPopulationCell*> occupied_cell_set; 
     663                        GetCell()->GetOccupiedNeighboringCells(occupied_cell_set, 1); 
     664                        if(occupied_cell_set.size()==0) { 
     665                                // nothing to do here, there are no neighbors 
     666                                return; 
     667                        } 
     668                        std::set<cPopulationCell*>::iterator selected=occupied_cell_set.begin(); 
     669                        std::advance(selected, ctx.GetRandom().GetInt(occupied_cell_set.size())); 
     670                        target = *selected; 
     671                        break; 
     672                } 
     673                default: { 
     674                        m_world->GetDriver().RaiseFatalException(1, "HGT_CONJUGATION_METHOD is set to an invalid value."); 
     675                        break; 
     676                } 
     677        } 
     678        assert(target != 0); 
     679        fragment_list_type fragments; 
     680        cGenomeUtil::RandomSplit(ctx,  
     681                                                                                                         m_world->GetConfig().HGT_FRAGMENT_SIZE_MEAN.Get(), 
     682                                                                                                         m_world->GetConfig().HGT_FRAGMENT_SIZE_VARIANCE.Get(), 
     683                                                                                                         GetOrganism()->GetGenome(), 
     684                                                                                                         fragments); 
     685        target->GetOrganism()->GetOrgInterface().ReceiveHGTDonation(fragments[ctx.GetRandom().GetInt(fragments.size())]); 
    669686} 
    670687 
     
    695712                // the hgt source controls where the genetic material for HGT comes from. 
    696713                switch(m_world->GetConfig().HGT_SOURCE.Get()) { 
    697                                 case 0: { // source is other genomes, nothing to do here (default) 
    698                                         break; 
    699                                 } 
    700                                 case 1: { // source is the parent (a control) 
    701                                         // this is a little hackish, but this is the cleanest way to make sure 
    702                                         // that all downstream stuff works right. 
    703                                         cell.ClearFragments(); 
    704                                         cell.AddGenomeFragments(cell.GetOrganism()->GetGenome()); 
    705                                         break; 
    706                                 } 
    707                                 default: { // error 
    708                                         m_world->GetDriver().RaiseFatalException(1, "HGT_SOURCE is set to an invalid value."); 
    709                                         break; 
    710                                 } 
     714                        case 0: { // source is other genomes, nothing to do here (default) 
     715                                break; 
     716                        } 
     717                        case 1: { // source is the parent (a control) 
     718                                // this is a little hackish, but this is the cleanest way to make sure 
     719                                // that all downstream stuff works right. 
     720                                cell.ClearFragments(); 
     721                                cell.AddGenomeFragments(cell.GetOrganism()->GetGenome()); 
     722                                break; 
     723                        } 
     724                        default: { // error 
     725                                m_world->GetDriver().RaiseFatalException(1, "HGT_SOURCE is set to an invalid value."); 
     726                                break; 
     727                        } 
    711728                } 
    712729                 
     
    727744                cGenomeUtil::substring_match location; 
    728745                switch(m_world->GetConfig().HGT_FRAGMENT_SELECTION.Get()) { 
    729                                 case 0: { // random selection 
    730                                         HGTRandomFragmentSelection(ctx, offspring, i, location); 
    731                                         break; 
    732                                 } 
    733                                 case 1: { // random selection with redundant instruction trimming 
    734                                         HGTTrimmedFragmentSelection(ctx, offspring, i, location); 
    735                                         break; 
    736                                 } 
    737                                 case 2: { // random selection and random placement 
    738                                         HGTRandomFragmentPlacement(ctx, offspring, i, location); 
    739                                         break; 
    740                                 } 
    741                                 default: { // error 
    742                                         m_world->GetDriver().RaiseFatalException(1, "HGT_FRAGMENT_SELECTION is set to an invalid value."); 
    743                                         break; 
    744                                 } 
     746                        case 0: { // random selection 
     747                                HGTRandomFragmentSelection(ctx, offspring, i, location); 
     748                                break; 
     749                        } 
     750                        case 1: { // random selection with redundant instruction trimming 
     751                                HGTTrimmedFragmentSelection(ctx, offspring, i, location); 
     752                                break; 
     753                        } 
     754                        case 2: { // random selection and random placement 
     755                                HGTRandomFragmentPlacement(ctx, offspring, i, location); 
     756                                break; 
     757                        } 
     758                        default: { // error 
     759                                m_world->GetDriver().RaiseFatalException(1, "HGT_FRAGMENT_SELECTION is set to an invalid value."); 
     760                                break; 
     761                        } 
    745762                } 
    746763