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

Method ProcessUpdate

avida-core/source/main/cDeme.cc:340–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338}
339
340void cDeme::ProcessUpdate(cAvidaContext& ctx)
341{
342 // test deme predicate
343 for (int i = 0; i < deme_pred_list.GetSize(); i++) {
344 if (deme_pred_list[i]->GetName() == "cDemeResourceThreshold") {
345 (*deme_pred_list[i])(ctx, &deme_resource_count);
346 }
347 }
348
349 energyUsage.Clear();
350
351 if(IsEmpty()) { // deme is not processed if no organisms are present
352 total_energy_testament = 0.0;
353 return;
354 }
355
356 if (m_world->GetConfig().ENERGY_ENABLED.Get()) {
357 for(int i = 0; i < GetSize(); i++) {
358 cPopulationCell& cell = GetCell(i);
359 if(cell.IsOccupied()) {
360 energyUsage.Add(cell.GetOrganism()->GetPhenotype().GetEnergyUsageRatio());
361 }
362 }
363 }
364
365 for(int i = 0; i < cell_events.GetSize(); i++) {
366 cDemeCellEvent& event = cell_events[i];
367
368 if(event.IsActive() && event.GetDelay() < _age && _age <= event.GetDelay()+event.GetDuration()) {
369 //remove energy from cells (should be done with outflow, but this will work for now)
370 int eventCell = event.GetNextEventCellID();
371 cResource* res = m_world->GetEnvironment().GetResourceLib().GetResource("CELL_ENERGY");
372
373 while(eventCell != -1) {
374 cPopulationCell& cell = m_world->GetPopulation().GetCell(GetCellID(eventCell));
375 if(event.GetEventID() == cell.GetCellData()){
376 if(cell.IsOccupied()) {
377 // remove energy from organism
378 cPhenotype& orgPhenotype = cell.GetOrganism()->GetPhenotype();
379 orgPhenotype.ReduceEnergy(orgPhenotype.GetStoredEnergy()*m_world->GetConfig().ATTACK_DECAY_RATE.Get());
380 }
381 //remove energy from cell... organism might not takeup all of a cell's energy
382 Apto::Array<double> cell_resources = deme_resource_count.GetCellResources(eventCell, ctx); // uses global cell_id; is this a problem
383 cell_resources[res->GetID()] *= m_world->GetConfig().ATTACK_DECAY_RATE.Get();
384 deme_resource_count.ModifyCell(ctx, cell_resources, eventCell);
385 }
386 eventCell = event.GetNextEventCellID();
387 }
388 }
389
390
391
392 if(!event.IsActive() && event.GetDelay() == _age) {
393 eventsTotal++;
394 event.ActivateEvent(); //start event
395 int eventCell = event.GetNextEventCellID();
396 while(eventCell != -1) {
397 // place event ID in cells' data

Callers 7

ProcessPostUpdateMethod · 0.45
NewTrialMethod · 0.45
RunMethod · 0.45
RunMethod · 0.45
RunMethod · 0.45
RunMethod · 0.45
RunMethod · 0.45

Calls 15

GetConfigMethod · 0.80
IsOccupiedMethod · 0.80
GetEnergyUsageRatioMethod · 0.80
GetDelayMethod · 0.80
GetDurationMethod · 0.80
GetNextEventCellIDMethod · 0.80
GetEventIDMethod · 0.80
ReduceEnergyMethod · 0.80
GetStoredEnergyMethod · 0.80
ModifyCellMethod · 0.80
ActivateEventMethod · 0.80
IsDecayedMethod · 0.80

Tested by

no test coverage detected