Skip to content

Commit

Permalink
Add support for insulations
Browse files Browse the repository at this point in the history
  • Loading branch information
paxbun committed Dec 22, 2021
1 parent 3f80b2b commit 296f012
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
7 changes: 4 additions & 3 deletions server/core/Public/leth/MatrixSpace.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class MatrixSpace : public Space
};

private:
std::vector<float> _A, _x, _b;
std::vector<Pos> _i2Pos;
std::vector<size_t> _pos2I;
std::vector<float> _A, _x, _b;
std::vector<Pos> _i2Pos;
std::vector<uint32_t> _i2NumNeighbors;
std::vector<size_t> _pos2I;

public:
MatrixSpace(uint16_t width, uint16_t height);
Expand Down
15 changes: 12 additions & 3 deletions server/core/Source/MatrixSpace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ bool MatrixSpace::BuildEquation(Point const* input) noexcept
_x.clear();
_b.clear();
_i2Pos.clear();
_i2NumNeighbors.clear();

constexpr int16_t offsets[4][2] {
{ -1, 0 },
Expand All @@ -75,17 +76,25 @@ bool MatrixSpace::BuildEquation(Point const* input) noexcept
size_t const idx { GetIndex(i, j) };
if (input[idx].type == PointType::GroundTruth)
{
uint32_t numNeighbors { 0 };
for (auto& offset : offsets)
{
if (!Inside(i + offset[0], j + offset[1]))
return false;
{
--numNeighbors;
continue;
}

if (input[GetIndex(i + offset[0], j + offset[1])].type == PointType::OutOfRange)
return false;
{
--numNeighbors;
continue;
}
}

_pos2I[idx] = _i2Pos.size();
_i2Pos.push_back(Pos { static_cast<uint16_t>(j), static_cast<uint16_t>(i) });
_i2NumNeighbors.push_back(numNeighbors);
}
else
_pos2I[idx] = std::numeric_limits<size_t>::max();
Expand All @@ -99,7 +108,7 @@ bool MatrixSpace::BuildEquation(Point const* input) noexcept

for (size_t i { 0 }, iEnd { _i2Pos.size() }; i < iEnd; ++i)
{
_A[i * numVars + i] = -4;
_A[i * numVars + i] = -4 + _i2NumNeighbors[i];

size_t const idx { GetIndex(_i2Pos[i].y, _i2Pos[i].x) };
for (auto& offset : offsets)
Expand Down
16 changes: 14 additions & 2 deletions server/core/Source/MonteCarloSpace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,30 @@ float MonteCarloSpace::DoMonteCarlo(Point const* input, uint16_t i, uint16_t j)
{
std::uniform_int_distribution<int> dist { 0, 3 };

int16_t beforeX, beforeY;
int16_t x { static_cast<int16_t>(j) }, y { static_cast<int16_t>(i) };
while (true)
{
if (!Inside(y, x))
return 0.0f;
{
x = beforeX;
y = beforeY;
continue;
}

auto idx { GetIndex(y, x) };
if (input[idx].type == PointType::Boundary)
return input[idx].temp;

if (input[idx].type == PointType::OutOfRange)
return 0.0f;
{
x = beforeX;
y = beforeY;
continue;
}

beforeX = x;
beforeY = y;

switch (dist(_eng))
{
Expand Down

0 comments on commit 296f012

Please sign in to comment.