Skip to content

Commit

Permalink
+ parameters cellFunctionConstructorExternalEnergy and cellFunctionCo…
Browse files Browse the repository at this point in the history
…nstructorExternalEnergySupplyRate added

+ parameter cellFunctionConstructionUnlimitedEnergy removed
+ insert mutation tweaked
  • Loading branch information
chrxh committed Nov 25, 2023
1 parent a5f266d commit 47ab2b1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 69 deletions.
2 changes: 1 addition & 1 deletion source/Base/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Const
{
std::string const ProgramVersion = "4.4.1";
std::string const ProgramVersion = "4.4.2";
std::string const DiscordLink = "https://discord.gg/7bjyZdXXQ2";

std::string const BasePath = "resources/";
Expand Down
35 changes: 19 additions & 16 deletions source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -718,26 +718,29 @@ ConstructorProcessor::constructCellIntern(

__inline__ __device__ bool ConstructorProcessor::checkAndReduceHostEnergy(SimulationData& data, Cell* hostCell, ConstructionData const& constructionData)
{
if (!cudaSimulationParameters.cellFunctionConstructionUnlimitedEnergy) {
auto cellFunctionConstructorPumpEnergyFactor = cudaSimulationParameters.cellFunctionConstructorPumpEnergyFactor[hostCell->color];
if (hostCell->energy < constructionData.energy + cudaSimulationParameters.cellNormalEnergy[hostCell->color]
&& cudaSimulationParameters.cellFunctionConstructorExternalEnergySupplyRate[hostCell->color] > 0) {
hostCell->energy += constructionData.energy * cudaSimulationParameters.cellFunctionConstructorExternalEnergySupplyRate[hostCell->color];
}

auto cellFunctionConstructorPumpEnergyFactor = cudaSimulationParameters.cellFunctionConstructorPumpEnergyFactor[hostCell->color];

auto energyNeededFromHost = max(0.0f, constructionData.energy - cudaSimulationParameters.cellNormalEnergy[hostCell->color])
+ min(constructionData.energy, cudaSimulationParameters.cellNormalEnergy[hostCell->color]) * (1.0f - cellFunctionConstructorPumpEnergyFactor);
auto energyNeededFromHost = max(0.0f, constructionData.energy - cudaSimulationParameters.cellNormalEnergy[hostCell->color])
+ min(constructionData.energy, cudaSimulationParameters.cellNormalEnergy[hostCell->color]) * (1.0f - cellFunctionConstructorPumpEnergyFactor);

if (cellFunctionConstructorPumpEnergyFactor < 1.0f && hostCell->energy < cudaSimulationParameters.cellNormalEnergy[hostCell->color] + energyNeededFromHost) {
if (cellFunctionConstructorPumpEnergyFactor < 1.0f && hostCell->energy < cudaSimulationParameters.cellNormalEnergy[hostCell->color] + energyNeededFromHost) {
return false;
}
auto energyNeededFromRadiation = constructionData.energy - energyNeededFromHost;
auto orig = atomicAdd(data.residualEnergy, -energyNeededFromRadiation);
if (orig < energyNeededFromRadiation) {
atomicAdd(data.residualEnergy, energyNeededFromRadiation);
if (hostCell->energy < cudaSimulationParameters.cellNormalEnergy[hostCell->color] + constructionData.energy) {
return false;
}
auto energyNeededFromRadiation = constructionData.energy - energyNeededFromHost;
auto orig = atomicAdd(data.residualEnergy, -energyNeededFromRadiation);
if (orig < energyNeededFromRadiation) {
atomicAdd(data.residualEnergy, energyNeededFromRadiation);
if (hostCell->energy < cudaSimulationParameters.cellNormalEnergy[hostCell->color] + constructionData.energy) {
return false;
}
hostCell->energy -= constructionData.energy;
} else {
hostCell->energy -= energyNeededFromHost;
}
hostCell->energy -= constructionData.energy;
} else {
hostCell->energy -= energyNeededFromHost;
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/MutationProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ __inline__ __device__ void MutationProcessor::insertMutation(SimulationData& dat
int numSubGenomesSizeIndices;

int nodeAddress = 0;
if (data.numberGen1.randomBool() && data.numberGen1.randomBool() && genomeSize > Const::GenomeHeaderSize) {
if (data.numberGen1.randomBool() && genomeSize > Const::GenomeHeaderSize) {

//choose a random node position to a constructor with a subgenome
int numConstructorsWithSubgenome = 0;
Expand Down
12 changes: 9 additions & 3 deletions source/EngineInterface/AuxiliaryDataParserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,15 @@ namespace
parserTask);
encodeDecodeProperty(
tree,
parameters.cellFunctionConstructionUnlimitedEnergy,
defaultParameters.cellFunctionConstructionUnlimitedEnergy,
"simulation parameters.cell.function.constructor.unlimited energy",
parameters.cellFunctionConstructorExternalEnergy,
defaultParameters.cellFunctionConstructorExternalEnergy,
"simulation parameters.cell.function.constructor.external energy",
parserTask);
encodeDecodeProperty(
tree,
parameters.cellFunctionConstructorExternalEnergySupplyRate,
defaultParameters.cellFunctionConstructorExternalEnergySupplyRate,
"simulation parameters.cell.function.constructor.external energy supply rate",
parserTask);

encodeDecodeProperty(
Expand Down
10 changes: 8 additions & 2 deletions source/EngineInterface/SimulationParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ struct SimulationParameters
bool particleTransformationRandomCellFunction = false;
int particleTransformationMaxGenomeSize = 300;

bool cellFunctionConstructionUnlimitedEnergy = false;
ColorVector<float> cellFunctionConstructorOffspringDistance = {2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f};
ColorVector<float> cellFunctionConstructorConnectingCellMaxDistance = {1.8f, 1.8f, 1.8f, 1.8f, 1.8f, 1.8f, 1.8f};
ColorVector<float> cellFunctionConstructorActivityThreshold = {0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f};
Expand All @@ -82,6 +81,8 @@ struct SimulationParameters
{true, true, true, true, true, true, true}};
bool cellFunctionConstructorMutationPreventDepthIncrease = false;
bool cellFunctionConstructorMutationSelfReplication = false;
ColorVector<float> cellFunctionConstructorExternalEnergy = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
ColorVector<float> cellFunctionConstructorExternalEnergySupplyRate = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};

ColorVector<float> cellFunctionInjectorRadius = {3.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.0f};
ColorMatrix<int> cellFunctionInjectorDurationColorMatrix = {
Expand Down Expand Up @@ -271,6 +272,12 @@ struct SimulationParameters
if (cellFunctionDetonatorChainExplosionProbability[i] != other.cellFunctionDetonatorChainExplosionProbability[i]) {
return false;
}
if (cellFunctionConstructorExternalEnergy[i] != other.cellFunctionConstructorExternalEnergy[i]) {
return false;
}
if (cellFunctionConstructorExternalEnergySupplyRate[i] != other.cellFunctionConstructorExternalEnergySupplyRate[i]) {
return false;
}
}
if (numParticleSources != other.numParticleSources) {
return false;
Expand Down Expand Up @@ -322,7 +329,6 @@ struct SimulationParameters
&& particleTransformationMaxGenomeSize == other.particleTransformationMaxGenomeSize
&& clusterDecay == other.clusterDecay
&& cellFunctionSensorActivityThreshold == other.cellFunctionSensorActivityThreshold
&& cellFunctionConstructionUnlimitedEnergy == other.cellFunctionConstructionUnlimitedEnergy
&& cellFunctionMuscleBendingAccelerationThreshold == other.cellFunctionMuscleBendingAccelerationThreshold
&& cellFunctionConstructorMutationSelfReplication == other.cellFunctionConstructorMutationSelfReplication
&& cellMaxAgeBalancer == other.cellMaxAgeBalancer && cellMaxAgeBalancerInterval == other.cellMaxAgeBalancerInterval
Expand Down
Loading

0 comments on commit 47ab2b1

Please sign in to comment.