| 701 | } |
| 702 | |
| 703 | std::vector<CellOrParticleDescription> DescriptionEditService::getConstructorToMainGenomes(DataDescription const& data) |
| 704 | { |
| 705 | std::map<std::vector<uint8_t>, size_t> genomeToCellIndex; |
| 706 | for (auto const& [index, cell] : data.cells | boost::adaptors::indexed(0)) { |
| 707 | if (cell.getCellFunctionType() == CellFunction_Constructor) { |
| 708 | auto const& genome = std::get<ConstructorDescription>(*cell.cellFunction).genome; |
| 709 | if (!genomeToCellIndex.contains(genome) || cell.livingState != LivingState_UnderConstruction) { |
| 710 | genomeToCellIndex[genome] = index; |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | std::vector<std::pair<std::vector<uint8_t>, size_t>> genomeAndCellIndex; |
| 715 | for (auto const& [genome, index] : genomeToCellIndex) { |
| 716 | genomeAndCellIndex.emplace_back(std::make_pair(genome, index)); |
| 717 | } |
| 718 | std::ranges::sort(genomeAndCellIndex, [](auto const& element1, auto const& element2) { return element1.first.size() > element2.first.size(); }); |
| 719 | |
| 720 | std::vector<CellOrParticleDescription> result; |
| 721 | for (auto it = genomeAndCellIndex.begin(); it != genomeAndCellIndex.end(); ++it) { |
| 722 | bool alreadyContained = false; |
| 723 | for (auto it2 = genomeAndCellIndex.begin(); it2 != it; ++it2) { |
| 724 | auto const& genome1 = it->first; |
| 725 | auto const& genome2 = it2->first; |
| 726 | if (contains(genome2, genome1)) { |
| 727 | alreadyContained = true; |
| 728 | break; |
| 729 | } |
| 730 | } |
| 731 | if (!alreadyContained) { |
| 732 | result.emplace_back(data.cells.at(it->second)); |
| 733 | } |
| 734 | } |
| 735 | return result; |
| 736 | } |
no test coverage detected