From c3b65397de99ab47f7a6a0482c44445ac6bac8c8 Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Tue, 24 Oct 2023 19:14:01 +0200 Subject: [PATCH] restart construction process when number of connection is too low + test --- .../EngineGpuKernels/ConstructorProcessor.cuh | 8 +++- source/EngineTests/ConstructorTests.cpp | 39 +++++++++++++++++++ source/Gui/InspectorWindow.cpp | 26 +++++++------ 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/source/EngineGpuKernels/ConstructorProcessor.cuh b/source/EngineGpuKernels/ConstructorProcessor.cuh index 3bdfed92a..ef273032f 100644 --- a/source/EngineGpuKernels/ConstructorProcessor.cuh +++ b/source/EngineGpuKernels/ConstructorProcessor.cuh @@ -200,12 +200,18 @@ __inline__ __device__ ConstructorProcessor::ConstructionData ConstructorProcesso ConstructionData result; + result.genomeHeader = GenomeDecoder::readGenomeHeader(constructor); result.lastConstructionCell = getLastConstructedCell(cell); if (!result.lastConstructionCell) { constructor.genomeCurrentNodeIndex = 0; constructor.genomeCurrentRepetition = 0; + } else if (result.lastConstructionCell->numConnections == 1) { + int numConstructedCells = constructor.genomeCurrentRepetition * result.genomeHeader.numRepetitions + constructor.genomeCurrentNodeIndex; + if (numConstructedCells > 1) { + constructor.genomeCurrentNodeIndex = 0; + constructor.genomeCurrentRepetition = 0; + } } - result.genomeHeader = GenomeDecoder::readGenomeHeader(constructor); result.genomeCurrentBytePosition = GenomeDecoder::getNodeAddress(constructor.genome, constructor.genomeSize, constructor.genomeCurrentNodeIndex); result.isLastNode = GenomeDecoder::isLastNode(constructor); result.isLastNodeOfLastRepetition = result.isLastNode && GenomeDecoder::isLastRepetition(constructor); diff --git a/source/EngineTests/ConstructorTests.cpp b/source/EngineTests/ConstructorTests.cpp index 917954f60..c7c5673eb 100644 --- a/source/EngineTests/ConstructorTests.cpp +++ b/source/EngineTests/ConstructorTests.cpp @@ -734,6 +734,45 @@ TEST_F(ConstructorTests, constructFirstCellIfNoLastConstructedCellFound) EXPECT_EQ(0, actualConstructor.genomeCurrentRepetition); } +TEST_F(ConstructorTests, constructFirstCellIfNoLastConstructedCellHasWrongConnections) +{ + auto genome = + GenomeDescriptionConverter::convertDescriptionToBytes(GenomeDescription() + .setHeader(GenomeHeaderDescription().setNumRepetitions(2)) + .setCells({CellGenomeDescription(), CellGenomeDescription(), CellGenomeDescription()})); + + DataDescription data; + data.addCells({ + CellDescription() + .setId(1) + .setPos({10.0f, 10.0f}) + .setEnergy(_parameters.cellNormalEnergy[0] * 3) + .setMaxConnections(1) + .setExecutionOrderNumber(0) + .setCellFunction(ConstructorDescription().setGenome(genome).setGenomeCurrentNodeIndex(1).setGenomeCurrentRepetition(1)), + CellDescription() + .setId(2) + .setPos({10.0f - _parameters.cellFunctionConstructorOffspringDistance[0], 10.0f}) + .setEnergy(100) + .setMaxConnections(1) + .setExecutionOrderNumber(5) + .setCellFunction(NerveDescription()) + .setLivingState(LivingState_UnderConstruction), + }); + data.addConnection(1, 2); + + _simController->setSimulationData(data); + _simController->calcTimesteps(1); + auto actualData = _simController->getSimulationData(); + + ASSERT_EQ(3, actualData.cells.size()); + auto actualHostCell = getCell(actualData, 1); + + auto actualConstructor = std::get(*actualHostCell.cellFunction); + EXPECT_EQ(1, actualConstructor.genomeCurrentNodeIndex); + EXPECT_EQ(0, actualConstructor.genomeCurrentRepetition); +} + TEST_F(ConstructorTests, constructNeuronCell) { auto neuron = NeuronGenomeDescription(); diff --git a/source/Gui/InspectorWindow.cpp b/source/Gui/InspectorWindow.cpp index 488c3b121..1c298ad58 100644 --- a/source/Gui/InspectorWindow.cpp +++ b/source/Gui/InspectorWindow.cpp @@ -425,14 +425,6 @@ void _InspectorWindow::processCellGenomeTab(Description& desc) if (ImGui::TreeNodeEx("Properties (principal genome part)", TreeNodeFlags)) { auto genomeDesc = GenomeDescriptionConverter::convertBytesToDescription(desc.genome); - auto numNodes = toInt(genomeDesc.cells.size()); - AlienImGui::InputInt( - AlienImGui::InputIntParameters() - .name("Number of cells") - .textWidth(GenomeTabTextWidth) - .readOnly(true) - .tooltip(Const::GenomeNumCellsTooltip), - numNodes); auto numRepetitions = genomeDesc.header.numRepetitions; AlienImGui::InputInt( AlienImGui::InputIntParameters() @@ -443,13 +435,25 @@ void _InspectorWindow::processCellGenomeTab(Description& desc) .tooltip(Const::GenomeRepetitionsPerConstructionTooltip), numRepetitions); + auto numNodes = toInt(genomeDesc.cells.size()); + AlienImGui::InputInt( + AlienImGui::InputIntParameters() + .name("Number of cells") + .textWidth(GenomeTabTextWidth) + .readOnly(true) + .tooltip(Const::GenomeNumCellsTooltip), + numNodes); + if constexpr (std::is_same()) { + AlienImGui::InputInt( + AlienImGui::InputIntParameters() + .name("Current repetition index") + .textWidth(GenomeTabTextWidth) + .tooltip(Const::GenomeCurrentRepetitionTooltip), + desc.genomeCurrentRepetition); AlienImGui::InputInt( AlienImGui::InputIntParameters().name("Current cell index").textWidth(GenomeTabTextWidth).tooltip(Const::GenomeCurrentCellTooltip), desc.genomeCurrentNodeIndex); - AlienImGui::InputInt( - AlienImGui::InputIntParameters().name("Current repetition index").textWidth(GenomeTabTextWidth).tooltip(Const::GenomeCurrentRepetitionTooltip), - desc.genomeCurrentRepetition); } ImGui::TreePop(); }