MCPcopy Create free account
hub / github.com/devosoft/avida / Process

Method Process

avida-core/source/actions/PopulationActions.cc:5297–5357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5295 }
5296
5297 void Process(cAvidaContext& ctx)
5298 {
5299 int src_cellid, dest_cellid;
5300
5301 for (int d = 0; d < m_world->GetPopulation().GetNumDemes(); d++) {
5302 cDeme& deme = m_world->GetPopulation().GetDeme(d);
5303 int deme_size = deme.GetWidth() * deme.GetHeight();
5304
5305 const cResourceCount &res = deme.GetDemeResourceCount();
5306 const int resid = res.GetResourceByName(m_res);
5307
5308 if(resid == -1) {
5309 //Resource doesn't exist for this deme. This is a bad situation, but just go to next deme.
5310 cerr << "Error: Resource \"" << m_res << "\" not defined for this deme" << endl;
5311 continue;
5312 }
5313
5314 if(res.Get(ctx, resid) >= m_thresh) {
5315 //Set the resource to zero
5316 deme.AdjustResource(ctx, resid, (-1 * res.Get(ctx, resid)));
5317
5318 //Pick a deme to move to
5319 int target_demeid = ctx.GetRandom().GetInt(0, m_world->GetConfig().NUM_DEMES.Get()-1);
5320 cDeme& target_deme = m_world->GetPopulation().GetDeme(target_demeid);
5321 int target_deme_size = target_deme.GetWidth() * target_deme.GetHeight();
5322
5323 //Migrate up to m_numorgs orgs
5324 for(int i = 0; i < m_numorgs; i++) {
5325 src_cellid = -1;
5326 dest_cellid = -1;
5327
5328 int counter = 0;
5329 do {
5330 src_cellid = ctx.GetRandom().GetInt(0, (deme.GetWidth() * deme.GetHeight())-1);
5331 counter++;
5332 } while((counter < deme_size) && (!deme.GetCell(src_cellid).IsOccupied()));
5333
5334 counter = 0;
5335 do {
5336 dest_cellid = ctx.GetRandom().GetInt(0, target_deme_size - 1);
5337 counter++;
5338 } while((counter < target_deme_size) && (target_deme.GetCell(dest_cellid).IsOccupied()));
5339
5340 if( (src_cellid != -1) && (dest_cellid != -1) ) {
5341
5342 m_world->GetPopulation().MoveOrganisms(ctx, src_cellid, dest_cellid, -1);
5343
5344 deme.DecOrgCount();
5345 target_deme.IncOrgCount();
5346 }
5347
5348 //migrate the organism from src_cell to dest cell
5349 }
5350
5351 m_world->GetStats().IncNumMigrations();
5352
5353 }
5354

Callers

nothing calls this directly

Calls 15

GetNumDemesMethod · 0.80
GetResourceByNameMethod · 0.80
AdjustResourceMethod · 0.80
GetIntMethod · 0.80
GetConfigMethod · 0.80
IsOccupiedMethod · 0.80
MoveOrganismsMethod · 0.80
DecOrgCountMethod · 0.80
IncOrgCountMethod · 0.80
IncNumMigrationsMethod · 0.80
GetDemeMethod · 0.45
GetWidthMethod · 0.45

Tested by

no test coverage detected