Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Jan 9, 2024
2 parents 8123d24 + 70b973d commit 2d1c962
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 23 deletions.
5 changes: 5 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release notes

## [4.7.3] - 2024-01-09
### Fixed
- engine: drop restriction on start construction angle
- engine: truncate neural activities to avoid overflow

## [4.7.2] - 2024-01-06
### Added
- engine, gui/simulation parameters: splitting of energy particles above a certain minimum energy
Expand Down
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.7.2";
std::string const ProgramVersion = "4.7.3";
std::string const DiscordLink = "https://discord.gg/7bjyZdXXQ2";

std::string const BasePath = "resources/";
Expand Down
26 changes: 21 additions & 5 deletions source/EngineGpuKernels/CellFunctionProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ __inline__ __device__ Activity CellFunctionProcessor::calcInputActivity(Cell* ce
if (connectedCell->executionOrderNumber == cell->inputExecutionOrderNumber) {
for (int i = 0; i < MAX_CHANNELS; ++i) {
result.channels[i] += connectedCell->activity.channels[i];
result.channels[i] = max(-1000000.0f, min(1000000.0f, result.channels[i])); //truncate value to avoid overflow
}
}
}
Expand Down Expand Up @@ -142,15 +143,30 @@ CellFunctionProcessor::calcLargestGapReferenceAndActualAngle(SimulationData& dat
}
angle += angleDiff;
}
auto angleFromPreviousConnection = cell->connections[index].angleFromPrevious / 2 + angleDeviation;
if (angleFromPreviousConnection < 30.0f || angleFromPreviousConnection > cell->connections[index].angleFromPrevious - 30.0f) {
angleFromPreviousConnection = cell->connections[index].angleFromPrevious / 2;

auto angleFromPrev = cell->connections[index].angleFromPrevious;
for (int i = 0; i < numConnections - 1; ++i) {
if (angleDeviation > angleFromPrev / 2) {
angleDeviation -= angleFromPrev / 2;
index = (index + 1) % numConnections;
angleOfLargestAngleGap += angleFromPrev;
angleFromPrev = cell->connections[index].angleFromPrevious;
angleDeviation = angleDeviation - angleFromPrev / 2;
}
if (angleDeviation < -angleFromPrev / 2) {
angleDeviation += angleFromPrev / 2;
index = (index + numConnections - 1) % numConnections;
angleFromPrev = cell->connections[index].angleFromPrevious;
angleDeviation = angleDeviation + angleFromPrev / 2;
angleOfLargestAngleGap -= angleFromPrev;
}
}
auto angleFromPreviousConnection = angleFromPrev / 2 + angleDeviation;

if (angleFromPreviousConnection > 360.0f) {
angleFromPreviousConnection -= 360;
}

angleFromPreviousConnection = max(min(angleFromPreviousConnection, cell->connections[index].angleFromPrevious), 0.0f);
angleFromPreviousConnection = max(30.0f, min(angleFromPrev - 30.0f, angleFromPreviousConnection));

return ReferenceAndActualAngle{angleFromPreviousConnection, angleOfLargestAngleGap + angleFromPreviousConnection};
}
Expand Down
3 changes: 1 addition & 2 deletions source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ __inline__ __device__ ConstructorProcessor::ConstructionData ConstructorProcesso
result.angle = result.genomeHeader.concatenationAngle1;
}
}
if (result.isLastNode) {
if (result.isLastNode && !isAtFirstNode) {
if (result.isLastNodeOfLastRepetition) {
result.angle = constructor.constructionAngle2;
} else {
Expand Down Expand Up @@ -345,7 +345,6 @@ ConstructorProcessor::startNewConstruction(SimulationData& data, SimulationStati
if (!isConnectable(hostCell->numConnections, hostCell->maxConnections, true)) {
return false;
}

auto anglesForNewConnection = CellFunctionProcessor::calcLargestGapReferenceAndActualAngle(data, hostCell, constructionData.angle);

auto newCellDirection = Math::unitVectorOfAngle(anglesForNewConnection.actualAngle);
Expand Down
62 changes: 62 additions & 0 deletions source/EngineTests/ConstructorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,3 +1836,65 @@ TEST_F(ConstructorTests, restartIfLastConstructedCellHasLowNumConnections)
EXPECT_EQ(1, actualConstructor.genomeCurrentNodeIndex);
EXPECT_EQ(0, actualConstructor.genomeCurrentRepetition);
}

TEST_F(ConstructorTests, allowLargeConstructionAngle1)
{
auto genome =
GenomeDescriptionService::convertDescriptionToBytes(GenomeDescription().setHeader(GenomeHeaderDescription()).setCells({CellGenomeDescription()}));

DataDescription data;
data.addCells({
CellDescription()
.setId(1)
.setPos({10.0f, 10.0f})
.setEnergy(_parameters.cellNormalEnergy[0] * 3)
.setMaxConnections(2)
.setExecutionOrderNumber(0)
.setCellFunction(ConstructorDescription().setGenome(genome).setConstructionAngle1(180.0f)),
CellDescription().setId(2).setPos({11.0f, 9.0f}).setEnergy(100).setMaxConnections(1).setExecutionOrderNumber(5),
CellDescription().setId(3).setPos({11.0f, 11.0f}).setEnergy(100).setMaxConnections(1).setExecutionOrderNumber(5),
});
data.addConnection(1, 2);
data.addConnection(1, 3);

_simController->setSimulationData(data);
_simController->calcTimesteps(1);
auto actualData = _simController->getSimulationData();

ASSERT_EQ(4, actualData.cells.size());
auto actualConstructedCell = getOtherCell(actualData, {1, 2, 3});

EXPECT_TRUE(approxCompare(11.0f, actualConstructedCell.pos.x));
EXPECT_TRUE(approxCompare(10.0f, actualConstructedCell.pos.y));
}

TEST_F(ConstructorTests, allowLargeConstructionAngle2)
{
auto genome =
GenomeDescriptionService::convertDescriptionToBytes(GenomeDescription().setHeader(GenomeHeaderDescription()).setCells({CellGenomeDescription()}));

DataDescription data;
data.addCells({
CellDescription()
.setId(1)
.setPos({10.0f, 10.0f})
.setEnergy(_parameters.cellNormalEnergy[0] * 3)
.setMaxConnections(2)
.setExecutionOrderNumber(0)
.setCellFunction(ConstructorDescription().setGenome(genome).setConstructionAngle1(-180.0f)),
CellDescription().setId(2).setPos({11.0f, 9.0f}).setEnergy(100).setMaxConnections(1).setExecutionOrderNumber(5),
CellDescription().setId(3).setPos({11.0f, 11.0f}).setEnergy(100).setMaxConnections(1).setExecutionOrderNumber(5),
});
data.addConnection(1, 2);
data.addConnection(1, 3);

_simController->setSimulationData(data);
_simController->calcTimesteps(1);
auto actualData = _simController->getSimulationData();

ASSERT_EQ(4, actualData.cells.size());
auto actualConstructedCell = getOtherCell(actualData, {1, 2, 3});

EXPECT_TRUE(approxCompare(11.0f, actualConstructedCell.pos.x));
EXPECT_TRUE(approxCompare(10.0f, actualConstructedCell.pos.y));
}
12 changes: 9 additions & 3 deletions source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void _MainWindow::processMenubar()

if (ImGui::BeginMainMenuBar()) {
if (AlienImGui::ShutdownButton()) {
_exitDialog->open();
onExit();
}
ImGui::Dummy(ImVec2(10.0f, 0.0f));
if (AlienImGui::BeginMenuButton(" " ICON_FA_GAMEPAD " Simulation ", _simulationMenuToggled, "Simulation")) {
Expand Down Expand Up @@ -581,10 +581,8 @@ void _MainWindow::processMenubar()
if (ImGui::IsKeyPressed(GLFW_KEY_SPACE)) {
if (_simController->isSimulationRunning()) {
onPauseSimulation();
printOverlayMessage("Pause");
} else {
onRunSimulation();
printOverlayMessage("Run");
}

}
Expand Down Expand Up @@ -829,11 +827,19 @@ void _MainWindow::onSaveSimulation()
void _MainWindow::onRunSimulation()
{
_simController->runSimulation();
printOverlayMessage("Run");
}

void _MainWindow::onPauseSimulation()
{
_simController->pauseSimulation();
printOverlayMessage("Pause");
}

void _MainWindow::onExit()
{
delayedExecution([this] { _exitDialog->open(); });
printOverlayMessage("Exiting ...");
}

void _MainWindow::pushGlobalStyle()
Expand Down
1 change: 1 addition & 0 deletions source/Gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class _MainWindow
void onSaveSimulation();
void onRunSimulation();
void onPauseSimulation();
void onExit();

void pushGlobalStyle();
void popGlobalStyle();
Expand Down
40 changes: 29 additions & 11 deletions source/Gui/TemporalControlWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "StyleRepository.h"
#include "StatisticsWindow.h"
#include "AlienImGui.h"
#include "DelayedExecutionController.h"
#include "OverlayMessageController.h"

namespace
Expand Down Expand Up @@ -116,28 +117,38 @@ void _TemporalControlWindow::processTpsRestriction()
void _TemporalControlWindow::processRunButton()
{
ImGui::BeginDisabled(_simController->isSimulationRunning());
if (AlienImGui::ToolbarButton(ICON_FA_PLAY)) {
auto result = AlienImGui::ToolbarButton(ICON_FA_PLAY);
AlienImGui::Tooltip("Run");
if (result) {
_history.clear();
_simController->runSimulation();
printOverlayMessage("Run");
}
ImGui::EndDisabled();
}

void _TemporalControlWindow::processPauseButton()
{
ImGui::BeginDisabled(!_simController->isSimulationRunning());
if (AlienImGui::ToolbarButton(ICON_FA_PAUSE)) {
auto result = AlienImGui::ToolbarButton(ICON_FA_PAUSE);
AlienImGui::Tooltip("Pause");
if (result) {
_simController->pauseSimulation();
printOverlayMessage("Pause");
}
ImGui::EndDisabled();
}

void _TemporalControlWindow::processStepBackwardButton()
{
ImGui::BeginDisabled(_history.empty() || _simController->isSimulationRunning());
if (AlienImGui::ToolbarButton(ICON_FA_CHEVRON_LEFT)) {
auto result = AlienImGui::ToolbarButton(ICON_FA_CHEVRON_LEFT);
AlienImGui::Tooltip("Load previous time step");
if (result) {
auto const& snapshot = _history.back();
applySnapshot(snapshot);
delayedExecution([this, snapshot] { applySnapshot(snapshot); });
printOverlayMessage("Loading previous time step ...");

_history.pop_back();
}
ImGui::EndDisabled();
Expand All @@ -146,7 +157,9 @@ void _TemporalControlWindow::processStepBackwardButton()
void _TemporalControlWindow::processStepForwardButton()
{
ImGui::BeginDisabled(_simController->isSimulationRunning());
if (AlienImGui::ToolbarButton(ICON_FA_CHEVRON_RIGHT)) {
auto result = AlienImGui::ToolbarButton(ICON_FA_CHEVRON_RIGHT);
AlienImGui::Tooltip("Process single time step");
if (result) {
_history.emplace_back(createSnapshot());
_simController->calcTimesteps(1);
}
Expand All @@ -155,21 +168,26 @@ void _TemporalControlWindow::processStepForwardButton()

void _TemporalControlWindow::processSnapshotButton()
{
if (AlienImGui::ToolbarButton(ICON_FA_CAMERA)) {
onSnapshot();
printOverlayMessage("Snapshot taken");
auto result = AlienImGui::ToolbarButton(ICON_FA_CAMERA);
AlienImGui::Tooltip("Create flashback");
if (result) {
delayedExecution([this] { onSnapshot(); });

printOverlayMessage("Creating flashback ...");
}
}

void _TemporalControlWindow::processRestoreButton()
{
ImGui::BeginDisabled(!_snapshot);
if (AlienImGui::ToolbarButton(ICON_FA_UNDO)) {
applySnapshot(*_snapshot);
auto result = AlienImGui::ToolbarButton(ICON_FA_UNDO);
AlienImGui::Tooltip("Load flashback");
if (result) {
delayedExecution([this] { applySnapshot(*_snapshot); });
_simController->removeSelection();
_history.clear();

printOverlayMessage("Snapshot restored"); //flashback?
printOverlayMessage("Loading flashback ...");
}
ImGui::EndDisabled();
}
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alien",
"version": "4.7.2",
"version": "4.7.3",
"dependencies": [
{
"name": "glew",
Expand Down

0 comments on commit 2d1c962

Please sign in to comment.