Skip to content

Commit

Permalink
+ Revert a6acca4 ("+ set activation time always to 0")
Browse files Browse the repository at this point in the history
+ initial check (directory)
  • Loading branch information
chrxh committed Nov 11, 2024
1 parent 83b3259 commit 2e8f1d6
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 24 deletions.
8 changes: 8 additions & 0 deletions source/Base/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
#include <stdexcept>
#include <string>

class InitialCheckException : public std::runtime_error
{
public:
InitialCheckException(std::string const& what)
: std::runtime_error(what.c_str())
{}
};

class CudaException : public std::runtime_error
{
public:
Expand Down
12 changes: 5 additions & 7 deletions source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ private:
__inline__ __device__ static ConstructionData readConstructionData(Cell* cell);
__inline__ __device__ static bool isConstructionTriggered(SimulationData const& data, Cell* cell, Activity const& activity);

__inline__ __device__ static Cell*
tryConstructCell(SimulationData& data, SimulationStatistics& statistics, Cell* hostCell, ConstructionData const& constructionData);
__inline__ __device__ static Cell* tryConstructCell(SimulationData& data, SimulationStatistics& statistics, Cell* hostCell, ConstructionData const& constructionData);

__inline__ __device__ static Cell* getLastConstructedCell(Cell* hostCell);
__inline__ __device__ static Cell*
startNewConstruction(SimulationData& data, SimulationStatistics& statistics, Cell* hostCell, ConstructionData const& constructionData);
__inline__ __device__ static Cell*
continueConstruction(SimulationData& data, SimulationStatistics& statistics, Cell* hostCell, ConstructionData const& constructionData);
__inline__ __device__ static Cell* startNewConstruction(SimulationData& data, SimulationStatistics& statistics, Cell* hostCell, ConstructionData const& constructionData);
__inline__ __device__ static Cell* continueConstruction(SimulationData& data, SimulationStatistics& statistics, Cell* hostCell, ConstructionData const& constructionData);

__inline__ __device__ static bool isConnectable(int numConnections, int maxConnections, bool adaptMaxConnections);

Expand Down Expand Up @@ -651,7 +648,7 @@ ConstructorProcessor::constructCellIntern(
result->inputExecutionOrderNumber = constructionData.inputExecutionOrderNumber;
result->outputBlocked = constructionData.outputBlocked;

result->activationTime = 0;
result->activationTime = constructionData.containsSelfReplication ? constructor.constructionActivationTime : 0;
result->genomeComplexity = hostCell->genomeComplexity;

auto genomeCurrentBytePosition = constructionData.genomeCurrentBytePosition;
Expand All @@ -675,6 +672,7 @@ ConstructorProcessor::constructCellIntern(
case CellFunction_Constructor: {
auto& newConstructor = result->cellFunctionData.constructor;
newConstructor.activationMode = GenomeDecoder::readByte(constructor, genomeCurrentBytePosition);
newConstructor.constructionActivationTime = GenomeDecoder::readWord(constructor, genomeCurrentBytePosition) % MaxActivationTime;
newConstructor.lastConstructedCellId = 0;
newConstructor.currentBranch = 0;
newConstructor.genomeCurrentNodeIndex = 0;
Expand Down
1 change: 1 addition & 0 deletions source/EngineGpuKernels/DataAccessKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace
} break;
case CellFunction_Constructor: {
cellTO.cellFunctionData.constructor.activationMode = cell->cellFunctionData.constructor.activationMode;
cellTO.cellFunctionData.constructor.constructionActivationTime = cell->cellFunctionData.constructor.constructionActivationTime;
copyAuxiliaryData(
cell->cellFunctionData.constructor.genomeSize,
cell->cellFunctionData.constructor.genome,
Expand Down
1 change: 1 addition & 0 deletions source/EngineGpuKernels/Object.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct ConstructorFunction
{
//settings
uint32_t activationMode; //0 = manual, 1 = every cycle, 2 = every second cycle, 3 = every third cycle, etc.
uint32_t constructionActivationTime;

//genome
uint16_t genomeSize;
Expand Down
2 changes: 2 additions & 0 deletions source/EngineGpuKernels/ObjectFactory.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ __inline__ __device__ void ObjectFactory::changeCellFromTO(DataTO const& dataTO,
} break;
case CellFunction_Constructor: {
cell->cellFunctionData.constructor.activationMode = cellTO.cellFunctionData.constructor.activationMode;
cell->cellFunctionData.constructor.constructionActivationTime = cellTO.cellFunctionData.constructor.constructionActivationTime;
createAuxiliaryData(
cellTO.cellFunctionData.constructor.genomeSize,
cellTO.cellFunctionData.constructor.genomeDataIndex,
Expand Down Expand Up @@ -321,6 +322,7 @@ __inline__ __device__ Cell* ObjectFactory::createRandomCell(float energy, float2
} else {
cell->cellFunctionData.constructor.activationMode = _data->numberGen1.random(50);
}
cell->cellFunctionData.constructor.constructionActivationTime = _data->numberGen1.random(10000);
cell->cellFunctionData.constructor.genomeSize = Const::GenomeHeaderSize;
cell->cellFunctionData.constructor.numInheritedGenomeNodes = 0;
cell->cellFunctionData.constructor.genome = _data->objects.auxiliaryData.getAlignedSubArray(cell->cellFunctionData.constructor.genomeSize);
Expand Down
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/SimulationParametersService.cu
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SimulationParameters SimulationParametersService::integrateChanges(
if (currentParameters.radiationSources[i].velX != 0) {
result.radiationSources[i].posX = currentParameters.radiationSources[i].posX;
}
if (currentParameters.spots[i].velY != 0) {
if (currentParameters.radiationSources[i].velY != 0) {
result.radiationSources[i].posY = currentParameters.radiationSources[i].posY;
}
}
Expand Down
1 change: 1 addition & 0 deletions source/EngineGpuKernels/TOs.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct TransmitterTO
struct ConstructorTO
{
uint32_t activationMode; //0 = manual, 1 = every cycle, 2 = every second cycle, 3 = every third cycle, etc.
uint32_t constructionActivationTime;

uint16_t genomeSize;
uint16_t numInheritedGenomeNodes;
Expand Down
2 changes: 2 additions & 0 deletions source/EngineImpl/DescriptionConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ CellDescription DescriptionConverter::createCellDescription(DataTO const& dataTO
case CellFunction_Constructor: {
ConstructorDescription constructor;
constructor.activationMode = cellTO.cellFunctionData.constructor.activationMode;
constructor.constructionActivationTime = cellTO.cellFunctionData.constructor.constructionActivationTime;
convert(dataTO, cellTO.cellFunctionData.constructor.genomeSize, cellTO.cellFunctionData.constructor.genomeDataIndex, constructor.genome);
constructor.numInheritedGenomeNodes = cellTO.cellFunctionData.constructor.numInheritedGenomeNodes;
constructor.lastConstructedCellId = cellTO.cellFunctionData.constructor.lastConstructedCellId;
Expand Down Expand Up @@ -589,6 +590,7 @@ void DescriptionConverter::addCell(
auto const& constructorDesc = std::get<ConstructorDescription>(*cellDesc.cellFunction);
ConstructorTO constructorTO;
constructorTO.activationMode = constructorDesc.activationMode;
constructorTO.constructionActivationTime = constructorDesc.constructionActivationTime;
CHECK(constructorDesc.genome.size() >= Const::GenomeHeaderSize)
convert(dataTO, constructorDesc.genome, constructorTO.genomeSize, constructorTO.genomeDataIndex);
constructorTO.numInheritedGenomeNodes = static_cast<uint16_t>(constructorDesc.numInheritedGenomeNodes);
Expand Down
2 changes: 2 additions & 0 deletions source/EngineInterface/CellFunctionConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,5 @@ enum ActivityOrigin_
ActivityOrigin_Unknown,
ActivityOrigin_Sensor
};

auto constexpr MaxActivationTime = 256 * 4;
6 changes: 6 additions & 0 deletions source/EngineInterface/Descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct TransmitterDescription
struct ConstructorDescription
{
int activationMode = 13; //0 = manual, 1 = every cycle, 2 = every second cycle, 3 = every third cycle, etc.
int constructionActivationTime = 100;
std::vector<uint8_t> genome;
int numInheritedGenomeNodes = 0;
int genomeGeneration = 0;
Expand All @@ -123,6 +124,11 @@ struct ConstructorDescription
activationMode = value;
return *this;
}
ConstructorDescription& setConstructionActivationTime(int value)
{
constructionActivationTime = value;
return *this;
}
ConstructorDescription& setGenome(std::vector<uint8_t> const& value)
{
genome = value;
Expand Down
6 changes: 3 additions & 3 deletions source/EngineInterface/GenomeConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ namespace Const
auto constexpr CellInputExecutionNumberPos = 6;
auto constexpr CellOutputBlockedPos = 7;

auto constexpr ConstructorConstructionAngle1Pos = 1;
auto constexpr ConstructorConstructionAngle2Pos = 2;
auto constexpr ConstructorConstructionAngle1Pos = 3;
auto constexpr ConstructorConstructionAngle2Pos = 4;

auto constexpr CellBasicBytes = 8;
auto constexpr NeuronBytes = 64 + 8 + 8;
auto constexpr TransmitterBytes = 1;
auto constexpr ConstructorFixedBytes = 3;
auto constexpr ConstructorFixedBytes = 5;
auto constexpr SensorBytes = 7;
auto constexpr NerveBytes = 2;
auto constexpr AttackerBytes = 1;
Expand Down
2 changes: 2 additions & 0 deletions source/EngineInterface/GenomeDescriptionService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ std::vector<uint8_t> GenomeDescriptionService::convertDescriptionToBytes(GenomeD
case CellFunction_Constructor: {
auto const& constructor = std::get<ConstructorGenomeDescription>(*cell.cellFunction);
writeByte(result, constructor.mode);
writeWord(result, constructor.constructionActivationTime);
writeAngle(result, constructor.constructionAngle1);
writeAngle(result, constructor.constructionAngle2);
writeGenome(result, constructor.genome);
Expand Down Expand Up @@ -330,6 +331,7 @@ namespace
case CellFunction_Constructor: {
ConstructorGenomeDescription constructor;
constructor.mode = readByte(data, bytePosition);
constructor.constructionActivationTime = readWord(data, bytePosition);
constructor.constructionAngle1 = readAngle(data, bytePosition);
constructor.constructionAngle2 = readAngle(data, bytePosition);
constructor.genome = readGenome(data, bytePosition);
Expand Down
6 changes: 6 additions & 0 deletions source/EngineInterface/GenomeDescriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct TransmitterGenomeDescription
struct ConstructorGenomeDescription
{
int mode = 13; //0 = manual, 1 = every cycle, 2 = every second cycle, 3 = every third cycle, etc.
int constructionActivationTime = 100;

std::variant<MakeGenomeCopy, std::vector<uint8_t>> genome = std::vector<uint8_t>();
float constructionAngle1 = 0;
Expand All @@ -58,6 +59,11 @@ struct ConstructorGenomeDescription
mode = value;
return *this;
}
ConstructorGenomeDescription& setConstructionActivationTime(int value)
{
constructionActivationTime = value;
return *this;
}
ConstructorGenomeDescription& setGenome(std::vector<uint8_t> const& value)
{
genome = value;
Expand Down
23 changes: 12 additions & 11 deletions source/EngineTests/ConstructorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ TEST_F(ConstructorTests, constructFirstCell_wrongCycle)

TEST_F(ConstructorTests, constructFirstCell_completenessCheck_constructionNotBuilt)
{
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setMakeSelfCopy();
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setMakeSelfCopy();
auto genome =
GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription().setCellFunction(constructorGenome)}));
auto otherGenome = GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription()}));
Expand Down Expand Up @@ -299,7 +299,7 @@ TEST_F(ConstructorTests, constructFirstCell_completenessCheck_constructionNotBui

TEST_F(ConstructorTests, constructFirstCell_completenessCheck_repeatedConstructionNotBuilt)
{
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setMakeSelfCopy();
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setMakeSelfCopy();
auto genome =
GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription().setCellFunction(constructorGenome)}));
auto otherGenome = GenomeDescriptionService::get().convertDescriptionToBytes(
Expand Down Expand Up @@ -340,9 +340,9 @@ TEST_F(ConstructorTests, constructFirstCell_completenessCheck_repeatedConstructi
TEST_F(ConstructorTests, constructFirstCell_completenessCheck_constructionBuilt)
{
auto otherGenome = GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription()}));
auto otherConstructorGenome = ConstructorGenomeDescription().setMode(0).setGenome(otherGenome);
auto otherConstructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setGenome(otherGenome);

auto constructorGenome = ConstructorGenomeDescription().setMode(0).setMakeSelfCopy();
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setMakeSelfCopy();
auto genome = GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells(
{CellGenomeDescription().setCellFunction(constructorGenome), CellGenomeDescription(), CellGenomeDescription().setCellFunction(otherConstructorGenome)}));

Expand Down Expand Up @@ -382,9 +382,9 @@ TEST_F(ConstructorTests, constructFirstCell_completenessCheck_infiniteConstructi
{
auto otherGenome = GenomeDescriptionService::get().convertDescriptionToBytes(
GenomeDescription().setHeader(GenomeHeaderDescription().setInfiniteRepetitions()).setCells({CellGenomeDescription()}));
auto otherConstructorGenome = ConstructorGenomeDescription().setMode(0).setGenome(otherGenome);
auto otherConstructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setGenome(otherGenome);

auto constructorGenome = ConstructorGenomeDescription().setMode(0).setMakeSelfCopy();
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setMakeSelfCopy();
auto genome = GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells(
{CellGenomeDescription().setCellFunction(constructorGenome), CellGenomeDescription(), CellGenomeDescription().setCellFunction(otherConstructorGenome)}));

Expand Down Expand Up @@ -425,7 +425,7 @@ TEST_F(ConstructorTests, constructFirstCell_completenessCheck_largeCluster)
auto constexpr RectLength = 50;
auto rect = DescriptionEditService::get().createRect(DescriptionEditService::CreateRectParameters().height(RectLength).width(RectLength));

auto constructorGenome = ConstructorGenomeDescription().setMode(0).setMakeSelfCopy();
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setMakeSelfCopy();
auto genome =
GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription().setCellFunction(constructorGenome)}));
auto otherGenome = GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription()}));
Expand All @@ -446,7 +446,7 @@ TEST_F(ConstructorTests, constructFirstCell_completenessCheck_largeCluster)

TEST_F(ConstructorTests, constructFirstCell_completenessCheck_thinCluster)
{
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setMakeSelfCopy();
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setMakeSelfCopy();
auto genome = GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription()
.setHeader(GenomeHeaderDescription().setNumBranches(2))
.setCells(
Expand Down Expand Up @@ -544,7 +544,7 @@ TEST_F(ConstructorTests, constructFirstCell_completenessCheck_thinCluster)
*/
TEST_F(ConstructorTests, DISABLED_constructFirstCell_completenessCheck_underConstruction)
{
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setMakeSelfCopy();
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setMakeSelfCopy();
auto genome =
GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription().setCellFunction(constructorGenome)}));
auto otherGenome = GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription()}));
Expand Down Expand Up @@ -601,7 +601,7 @@ TEST_F(ConstructorTests, constructFirstCell_noSeparation)
.setEnergy(_parameters.cellNormalEnergy[0] * 3)
.setMaxConnections(1)
.setExecutionOrderNumber(0)
.setCellFunction(ConstructorDescription().setGenome(genome)));
.setCellFunction(ConstructorDescription().setGenome(genome).setConstructionActivationTime(123)));

_simulationFacade->setSimulationData(data);
_simulationFacade->calcTimesteps(1);
Expand Down Expand Up @@ -857,7 +857,7 @@ TEST_F(ConstructorTests, constructNeuronCell)

TEST_F(ConstructorTests, constructConstructorCell)
{
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setGenome(createRandomGenome(MAX_GENOME_BYTES / 2));
auto constructorGenome = ConstructorGenomeDescription().setMode(0).setConstructionActivationTime(123).setGenome(createRandomGenome(MAX_GENOME_BYTES / 2));

auto genome =
GenomeDescriptionService::get().convertDescriptionToBytes(GenomeDescription().setCells({CellGenomeDescription().setCellFunction(constructorGenome)}));
Expand All @@ -882,6 +882,7 @@ TEST_F(ConstructorTests, constructConstructorCell)

auto actualConstructor = std::get<ConstructorDescription>(*actualConstructedCell.cellFunction);
EXPECT_EQ(constructorGenome.mode, actualConstructor.activationMode);
EXPECT_EQ(constructorGenome.constructionActivationTime, actualConstructor.constructionActivationTime);
EXPECT_EQ(constructorGenome.getGenomeData(), actualConstructor.genome);
}

Expand Down
8 changes: 8 additions & 0 deletions source/Gui/GenomeEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,13 @@ void GenomeEditorWindow::processNode(
}
}
table.next();
AlienImGui::InputInt(
AlienImGui::InputIntParameters()
.name("Offspring activation time")
.textWidth(ContentTextWidth)
.tooltip(Const::GenomeConstructorOffspringActivationTime),
constructor.constructionActivationTime);
table.next();
AlienImGui::InputFloat(
AlienImGui::InputFloatParameters()
.name("Construction angle #1")
Expand Down Expand Up @@ -983,6 +990,7 @@ void GenomeEditorWindow::validationAndCorrection(CellGenomeDescription& cell) co
if (constructor.mode < 0) {
constructor.mode = 0;
}
constructor.constructionActivationTime = ((constructor.constructionActivationTime % MaxActivationTime) + MaxActivationTime) % MaxActivationTime;
} break;
case CellFunction_Sensor: {
auto& sensor = std::get<SensorGenomeDescription>(*cell.cellFunction);
Expand Down
10 changes: 10 additions & 0 deletions source/Gui/InspectorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,12 @@ void _InspectorWindow::processConstructorContent(ConstructorDescription& constru
AlienImGui::InputIntParameters().name("Interval").textWidth(CellFunctionTextWidth).tooltip(Const::GenomeConstructorIntervalTooltip),
constructor.activationMode);
}
AlienImGui::InputInt(
AlienImGui::InputIntParameters()
.name("Offspring activation time")
.textWidth(CellFunctionTextWidth)
.tooltip(Const::GenomeConstructorOffspringActivationTime),
constructor.constructionActivationTime);
AlienImGui::InputFloat(
AlienImGui::InputFloatParameters()
.name("Construction angle #1")
Expand Down Expand Up @@ -771,6 +777,10 @@ void _InspectorWindow::validationAndCorrection(CellDescription& cell) const
constructor.genomeCurrentRepetition = 0;
}

constructor.constructionActivationTime = ((constructor.constructionActivationTime % MaxActivationTime) + MaxActivationTime) % MaxActivationTime;
if (constructor.constructionActivationTime < 0) {
constructor.constructionActivationTime = 0;
}
if (constructor.activationMode < 0) {
constructor.activationMode = 0;
}
Expand Down
Loading

0 comments on commit 2e8f1d6

Please sign in to comment.