Skip to content

Commit

Permalink
code for duplication mutation cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Sep 28, 2024
1 parent 72b6eff commit 25507e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions source/EngineGpuKernels/GenomeDecoder.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public:
__inline__ __device__ static void setNextConstructorSeparation(uint8_t* genome, int nodeAddress, bool separation);
__inline__ __device__ static void setNextConstructorNumBranches(uint8_t* genome, int nodeAddress, int numBranches);
__inline__ __device__ static bool containsSectionSelfReplication(uint8_t* genome, int genomeSize);
__inline__ __device__ static int getNodeAddressForSelfReplication(uint8_t* genome, int genomeSize); //-1 = no node for self-replication found
__inline__ __device__ static int getNodeAddressForSelfReplication(uint8_t* genome, int genomeSize, bool& containsSelfReplicator);
__inline__ __device__ static void setRandomCellFunctionData(SimulationData& data, uint8_t* genome, int nodeAddress, CellFunction const& cellFunction, bool makeSelfCopy, int subGenomeSize);
__inline__ __device__ static int getCellFunctionDataSize(
CellFunction cellFunction,
Expand Down Expand Up @@ -740,15 +740,16 @@ __inline__ __device__ bool GenomeDecoder::containsSectionSelfReplication(uint8_t
return false;
}

__inline__ __device__ int GenomeDecoder::getNodeAddressForSelfReplication(uint8_t* genome, int genomeSize)
__inline__ __device__ int GenomeDecoder::getNodeAddressForSelfReplication(uint8_t* genome, int genomeSize, bool& containsSelfReplicator)
{
int nodeAddress = 0;
for (; nodeAddress < genomeSize;) {
if (isNextCellSelfReplication(genome, nodeAddress)) {
containsSelfReplicator = true;
return nodeAddress;
}
nodeAddress += Const::CellBasicBytes + getNextCellFunctionDataSize(genome, genomeSize, nodeAddress);
}

return -1;
containsSelfReplicator = false;
return 0;
}
9 changes: 5 additions & 4 deletions source/EngineGpuKernels/MutationProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,11 @@ __inline__ __device__ void MutationProcessor::duplicateMutation(SimulationData&
}
auto sizeDelta = endSourceIndex - startSourceIndex;
auto nodeAddressForSelfReplication = -1;
auto duplicatedSegmentContainsSelfReplicator = false;
if (!cudaSimulationParameters.cellFunctionConstructorMutationSelfReplication) {
nodeAddressForSelfReplication = GenomeDecoder::getNodeAddressForSelfReplication(genome + startSourceIndex, sizeDelta);
if (nodeAddressForSelfReplication != -1 ) {
nodeAddressForSelfReplication += startSourceIndex;
nodeAddressForSelfReplication =
GenomeDecoder::getNodeAddressForSelfReplication(genome + startSourceIndex, sizeDelta, duplicatedSegmentContainsSelfReplicator) + startSourceIndex;
if (duplicatedSegmentContainsSelfReplicator) {
sizeDelta += 2 + Const::GenomeHeaderSize; //additional size for empty subgenome
}
}
Expand Down Expand Up @@ -802,7 +803,7 @@ __inline__ __device__ void MutationProcessor::duplicateMutation(SimulationData&
}

//copy duplicated part
if (nodeAddressForSelfReplication == -1) {
if (!duplicatedSegmentContainsSelfReplicator) {
for (int i = 0; i < sizeDelta; ++i) {
targetGenome[startTargetIndex + i] = genome[startSourceIndex + i];
}
Expand Down

0 comments on commit 25507e8

Please sign in to comment.