Skip to content

Commit

Permalink
+ allow insert mutation on empty genomes
Browse files Browse the repository at this point in the history
+ mutation and transmitter tests fixed
  • Loading branch information
chrxh committed Oct 19, 2023
1 parent 9074970 commit bfe434f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
4 changes: 0 additions & 4 deletions source/EngineGpuKernels/MutationProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,6 @@ __inline__ __device__ void MutationProcessor::cellFunctionMutation(SimulationDat
__inline__ __device__ void MutationProcessor::insertMutation(SimulationData& data, Cell* cell)
{
auto& constructor = cell->cellFunctionData.constructor;
if (GenomeDecoder::hasEmptyGenome(constructor)) {
return;
}

auto& genome = constructor.genome;
auto const& genomeSize = constructor.genomeSize;

Expand Down
10 changes: 3 additions & 7 deletions source/EngineTests/MutationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,9 @@ TEST_F(MutationTests, individualGeometryMutation)
TEST_F(MutationTests, cellFunctionMutation)
{
auto genome = createGenomeWithMultipleCellsWithDifferentFunctions();
auto cellIndex = 7;
int byteIndex = GenomeDescriptionConverter::convertNodeIndexToNodeAddress(genome, cellIndex);

auto data = DataDescription().addCells(
{CellDescription().setId(1).setCellFunction(ConstructorDescription().setGenome(genome).setGenomeCurrentNodeIndex(byteIndex)).setExecutionOrderNumber(0)});
{CellDescription().setId(1).setCellFunction(ConstructorDescription().setGenome(genome).setGenomeCurrentNodeIndex(3)).setExecutionOrderNumber(0)});

_simController->setSimulationData(data);
for (int i = 0; i < 10000; ++i) {
Expand All @@ -702,16 +700,14 @@ TEST_F(MutationTests, cellFunctionMutation)

auto actualConstructor = std::get<ConstructorDescription>(*actualCellById.at(1).cellFunction);
EXPECT_TRUE(compareCellFunctionMutation(genome, actualConstructor.genome));
auto actualCellIndex = GenomeDescriptionConverter::convertNodeAddressToNodeIndex(actualConstructor.genome, actualConstructor.genomeCurrentNodeIndex);
EXPECT_EQ(cellIndex, actualCellIndex);
EXPECT_EQ(3, actualConstructor.genomeCurrentNodeIndex);
}

TEST_F(MutationTests, insertMutation_emptyGenome)
{
auto cellColor = 3;
auto genome = GenomeDescriptionConverter::convertDescriptionToBytes(GenomeDescription());
auto data = DataDescription().addCells(
{CellDescription().setId(1).setCellFunction(ConstructorDescription().setGenome(genome)).setExecutionOrderNumber(0).setColor(cellColor)});
{CellDescription().setId(1).setCellFunction(ConstructorDescription()).setExecutionOrderNumber(0).setColor(cellColor)});

_simController->setSimulationData(data);
_simController->testOnly_mutate(1, MutationType::Insertion);
Expand Down
4 changes: 3 additions & 1 deletion source/EngineTests/TransmitterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ TEST_F(TransmitterTests, distributeToConnectedCells)

TEST_F(TransmitterTests, distributeToOtherTransmitterAndConstructor)
{
auto genome = GenomeDescriptionConverter::convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription()}));

DataDescription data;
data.addCells({
CellDescription()
Expand All @@ -178,7 +180,7 @@ TEST_F(TransmitterTests, distributeToOtherTransmitterAndConstructor)
.setInputExecutionOrderNumber(5)
.setCellFunction(TransmitterDescription().setMode(EnergyDistributionMode_TransmittersAndConstructors))
.setEnergy(_parameters.cellNormalEnergy[0] * 2),
CellDescription().setId(2).setPos({11.0f, 10.0f}).setMaxConnections(2).setExecutionOrderNumber(5).setCellFunction(ConstructorDescription()),
CellDescription().setId(2).setPos({11.0f, 10.0f}).setMaxConnections(2).setExecutionOrderNumber(5).setCellFunction(ConstructorDescription().setGenome(genome)),
CellDescription().setId(3).setPos({9.0f, 10.0f}).setMaxConnections(1).setExecutionOrderNumber(1).setCellFunction(TransmitterDescription()),
});
data.addConnection(1, 2);
Expand Down

0 comments on commit bfe434f

Please sign in to comment.