Skip to content

Commit

Permalink
Mutate now working in spatial model.
Browse files Browse the repository at this point in the history
  • Loading branch information
highperformancecoder committed Sep 11, 2024
1 parent 486c6bf commit c32d643
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions models/ecolab_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,33 @@ void PanmicticModel::mutate()
density<<=array<int>(new_sp.size(),1);
}

void SpatialModel::mutate()
{
array<double> mut_scale(sp_sep * repro_rate * mutation * (tstep - last_mut_tstep));
last_mut_tstep=tstep;
array<unsigned> new_sp;
array<unsigned> num_new_sp;
for (auto& i: *this)
{
auto new_species_in_cell=i->as<EcoLabCell>()->mutate(mut_scale);
num_new_sp<<=new_species_in_cell.size();
new_sp <<= new_species_in_cell;
}
unsigned offset=species.size(), offi=0;
// assign 1 for all new species created in this cell, 0 for the others
for (auto& i: *this)
{
auto& density=i->as<EcoLabCell>()->density;
density<<=array<int>(new_sp.size(),0);
for (size_t j=0; j<num_new_sp[offi]; ++j)
{
density[j+offset]=1;
offset+=num_new_sp[offi++];
}
}
ModelData::mutate(new_sp);
}

array<int> EcolabPoint::mutate(const array<double>& mut_scale)
{
array<int> speciations;
Expand Down
2 changes: 1 addition & 1 deletion models/ecolab_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class SpatialModel: public ModelData, public graphcode::Graph<EcoLabCell>
void generate(unsigned niter);
void generate() {generate(1);}
// void condense();
// void mutate();
void mutate();
// void migrate();
};

0 comments on commit c32d643

Please sign in to comment.