Skip to content

Commit

Permalink
make cellDeathProbability spot-dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Nov 11, 2024
1 parent 39f6111 commit 25ae2ab
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 13 deletions.
8 changes: 7 additions & 1 deletion source/EngineGpuKernels/CellProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,13 @@ __inline__ __device__ void CellProcessor::decay(SimulationData& data)
&SimulationParametersSpotValues::cellMinEnergy, &SimulationParametersSpotActivatedValues::cellMinEnergy, data, cell->pos, cell->color);

if (cell->livingState == LivingState_Dying || cell->livingState == LivingState_Detaching) {
if (data.numberGen1.random() < cudaSimulationParameters.cellDeathProbability[cell->color]) {
auto cellDeathProbability = SpotCalculator::calcParameter(
&SimulationParametersSpotValues::cellDeathProbability,
&SimulationParametersSpotActivatedValues::cellDeathProbability,
data,
cell->pos,
cell->color);
if (data.numberGen1.random() < cellDeathProbability) {
CellConnectionProcessor::scheduleDeleteCell(data, index);
}
}
Expand Down
3 changes: 0 additions & 3 deletions source/EngineInterface/SimulationParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ bool SimulationParameters::operator==(SimulationParameters const& other) const
if (cellFunctionConstructorConnectingCellMaxDistance[i] != other.cellFunctionConstructorConnectingCellMaxDistance[i]) {
return false;
}
if (cellDeathProbability[i] != other.cellDeathProbability[i]) {
return false;
}
if (cellNormalEnergy[i] != other.cellNormalEnergy[i]) {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion source/EngineInterface/SimulationParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ struct SimulationParameters
ColorVector<float> highRadiationFactor = {0, 0, 0, 0, 0, 0, 0};
ColorVector<float> highRadiationMinCellEnergy = {500.0f, 500.0f, 500.0f, 500.0f, 500.0f, 500.0f, 500.0f};
CellDeathConsquences cellDeathConsequences = CellDeathConsquences_DetachedPartsDie;
ColorVector<float> cellDeathProbability = {0.001f, 0.001f, 0.001f, 0.001f, 0.001f, 0.001f, 0.001f};
ColorVector<int> cellMaxAge = {
Infinity<int>::value,
Infinity<int>::value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct SimulationParametersSpotActivatedValues
bool radiationDisableSources = false;
bool cellMaxForce = false;
bool cellMinEnergy = false;
bool cellDeathProbability = false;
bool cellFusionVelocity = false;
bool cellMaxBindingEnergy = false;
bool cellInactiveMaxAge = false;
Expand Down Expand Up @@ -63,8 +64,8 @@ struct SimulationParametersSpotActivatedValues
&& cellFunctionAttackerGenomeComplexityBonus == other.cellFunctionAttackerGenomeComplexityBonus
&& radiationAbsorptionLowVelocityPenalty == other.radiationAbsorptionLowVelocityPenalty
&& cellFunctionAttackerNewComplexMutantPenalty == other.cellFunctionAttackerNewComplexMutantPenalty
&& cellInactiveMaxAge == other.cellInactiveMaxAge
&& radiationDisableSources == other.radiationDisableSources
&& cellInactiveMaxAge == other.cellInactiveMaxAge && radiationDisableSources == other.radiationDisableSources
&& cellDeathProbability == other.cellDeathProbability
;
}
};
5 changes: 5 additions & 0 deletions source/EngineInterface/SimulationParametersSpotValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct SimulationParametersSpotValues
bool radiationDisableSources = false;
ColorVector<float> cellMaxForce = {0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f};
ColorVector<float> cellMinEnergy = {50.0f, 50.0f, 50.0f, 50.0f, 50.0f, 50.0f, 50.0f};
ColorVector<float> cellDeathProbability = {0.001f, 0.001f, 0.001f, 0.001f, 0.001f, 0.001f, 0.001f};

float cellFusionVelocity = 0.6f;
float cellMaxBindingEnergy = Infinity<float>::value;
ColorVector<float> cellInactiveMaxAge = {
Expand Down Expand Up @@ -95,6 +97,9 @@ struct SimulationParametersSpotValues
}
}
for (int i = 0; i < MAX_COLORS; ++i) {
if (cellDeathProbability[i] != other.cellDeathProbability[i]) {
return false;
}
if (cellMaxForce[i] != other.cellMaxForce[i]) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion source/EngineTests/CellConnectionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST_F(CellConnectionTests, decay)
{
_parameters.baseValues.radiationAbsorption[0] = 0;
_parameters.cellDeathConsequences = CellDeathConsquences_CreatureDies;
_parameters.cellDeathProbability[0] = 0.5f;
_parameters.baseValues.cellDeathProbability[0] = 0.5f;

_simulationFacade->setSimulationParameters(_parameters);
auto origData =
Expand Down
16 changes: 14 additions & 2 deletions source/Gui/SimulationParametersWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,12 +659,12 @@ void SimulationParametersWindow::processBase()
.max(0.1f)
.format("%.6f")
.logarithmic(true)
.defaultValue(origParameters.cellDeathProbability)
.defaultValue(origParameters.baseValues.cellDeathProbability)
.tooltip("The probability per time step with which a cell will disintegrate (i.e. transform into an energy particle) when it is in the "
"state 'Dying'. This can occur when one of the following conditions is satisfied:\n\n"
ICON_FA_CHEVRON_RIGHT " The cell has too low energy.\n\n"
ICON_FA_CHEVRON_RIGHT " The cell has exceeded its maximum age."),
parameters.cellDeathProbability);
parameters.baseValues.cellDeathProbability);
AlienImGui::Switcher(
AlienImGui::SwitcherParameters()
.name("Cell death consequences")
Expand Down Expand Up @@ -1969,6 +1969,18 @@ bool SimulationParametersWindow::processSpot(int index)
.disabledValue(parameters.baseValues.cellMinEnergy),
spot.values.cellMinEnergy,
&spot.activatedValues.cellMinEnergy);
AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
.name("Decay rate of dying cells")
.colorDependence(true)
.textWidth(RightColumnWidth)
.min(1e-6f)
.max(0.1f)
.format("%.6f")
.logarithmic(true)
.defaultValue(origSpot.values.cellDeathProbability).disabledValue(parameters.baseValues.cellDeathProbability),
spot.values.cellDeathProbability,
&spot.activatedValues.cellDeathProbability);
AlienImGui::EndTreeNode();
}

Expand Down
13 changes: 12 additions & 1 deletion source/PersisterInterface/AuxiliaryDataParserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ namespace
missingParameters.cellDeathConsequences = ParameterParser::encodeDecode(
tree, parameters.cellDeathConsequences, defaultParameters.cellDeathConsequences, "simulation parameters.cell.death consequences", parserTask);
ParameterParser::encodeDecode(
tree, parameters.cellDeathProbability, defaultParameters.cellDeathProbability, "simulation parameters.cell.death probability", parserTask);
tree,
parameters.baseValues.cellDeathProbability,
defaultParameters.baseValues.cellDeathProbability,
"simulation parameters.cell.death probability",
parserTask);

ParameterParser::encodeDecode(
tree,
Expand Down Expand Up @@ -789,6 +793,13 @@ namespace
tree, spot.values.cellMaxForce, spot.activatedValues.cellMaxForce, defaultSpot.values.cellMaxForce, base + "cell.max force", parserTask);
ParameterParser::encodeDecodeWithEnabled(
tree, spot.values.cellMinEnergy, spot.activatedValues.cellMinEnergy, defaultSpot.values.cellMinEnergy, base + "cell.min energy", parserTask);
ParameterParser::encodeDecodeWithEnabled(
tree,
spot.values.cellDeathProbability,
spot.activatedValues.cellDeathProbability,
defaultSpot.values.cellDeathProbability,
base + "cell.death probability",
parserTask);

ParameterParser::encodeDecodeWithEnabled(
tree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ void LegacyAuxiliaryDataParserService::activateParametersAndFeaturesForLegacyFil
parameters.cellDeathConsequences = legacyParameters.base.clusterDecay.parameter ? CellDeathConsquences_CreatureDies : CellDeathConsquences_None;
if (parameters.cellDeathConsequences == CellDeathConsquences_None) {
for (int i = 0; i < MAX_COLORS; ++i) {
parameters.cellDeathProbability[i] = 0.01f;
parameters.baseValues.cellDeathProbability[i] = 0.01f;
}
} else {
for (int i = 0; i < MAX_COLORS; ++i) {
parameters.cellDeathProbability[i] = legacyParameters.base.clusterDecayProb.parameter[i];
parameters.baseValues.cellDeathProbability[i] = legacyParameters.base.clusterDecayProb.parameter[i];
}
}
}
Expand Down

0 comments on commit 25ae2ab

Please sign in to comment.