Skip to content

Commit

Permalink
restart construction process when number of connection is too low + test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 24, 2023
1 parent c86a8c9 commit c3b6539
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
8 changes: 7 additions & 1 deletion source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 39 additions & 0 deletions source/EngineTests/ConstructorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConstructorDescription>(*actualHostCell.cellFunction);
EXPECT_EQ(1, actualConstructor.genomeCurrentNodeIndex);
EXPECT_EQ(0, actualConstructor.genomeCurrentRepetition);
}

TEST_F(ConstructorTests, constructNeuronCell)
{
auto neuron = NeuronGenomeDescription();
Expand Down
26 changes: 15 additions & 11 deletions source/Gui/InspectorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<Description, ConstructorDescription>()) {
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();
}
Expand Down

0 comments on commit c3b6539

Please sign in to comment.