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

Method SelectOffspring

avida-core/source/main/cBirthNeighborhoodHandler.cc:41–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40
41cBirthEntry* cBirthNeighborhoodHandler::SelectOffspring(cAvidaContext& ctx, const Genome& offspring, cOrganism* parent)
42{
43 int parent_id = parent->GetOrgInterface().GetCellID();
44
45 // Get all neighborhood cell ids
46 Apto::Array<int> neighborhood;
47 parent->GetOrgInterface().GetNeighborhoodCellIDs(neighborhood);
48
49 // Produce a list of all valid offspring waiting
50 Apto::Array<int> valid(neighborhood.GetSize());
51 int valid_count = 0;
52 for (int i = 0; i < neighborhood.GetSize(); i++) {
53 // Store the cell id of valid birth entries in the valid list
54 if (m_bc->ValidBirthEntry(m_entries[neighborhood[i]])) valid[valid_count++] = neighborhood[i];
55 }
56 if (m_bc->ValidBirthEntry(m_entries[parent_id])) valid[valid_count++] = parent_id;
57
58 // If no valid entries exist, store the current offspring
59 if (valid_count == 0) {
60 m_bc->StoreAsEntry(offspring, parent, m_entries[parent_id]);
61 return NULL;
62 }
63
64 // Select a random valid entry and return it
65 return &(m_entries[valid[ctx.GetRandom().GetUInt(valid_count)]]);
66}

Callers

nothing calls this directly

Calls 6

ValidBirthEntryMethod · 0.80
StoreAsEntryMethod · 0.80
GetUIntMethod · 0.80
GetCellIDMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected