| 39 | |
| 40 | |
| 41 | cBirthEntry* 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 | } |
nothing calls this directly
no test coverage detected