Skip to content

Commit

Permalink
Merge branch 'main' into remove_unit_library
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewniok committed Jul 25, 2023
2 parents ce63b2d + 92bb036 commit ab73daa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
5 changes: 3 additions & 2 deletions include/fiction/algorithms/path_finding/distance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ template <typename Lyt, typename Dist = double>
*
* Thereby, \f$ s \leq t \f$ iff \f$ x_1 \leq x_2 \f$ and \f$ y_1 \leq y_2 \f$.
*
* @note To represent \f$ \infty \f$, `std::numeric_limits<Dist>::max()` is returned for distances of infinite length.
* @note To represent \f$ \infty \f$, `std::numeric_limits<uint32_t>::max()` is returned for distances of infinite
* length. We are using `uint32_t` to prevent overflows when adding distances in the default `uint64_t` number range.
*
* @tparam Lyt Coordinate layout type.
* @tparam Dist Integral type for the distance.
Expand All @@ -88,7 +89,7 @@ template <typename Lyt, typename Dist = uint64_t>
static_assert(std::is_integral_v<Dist>, "Dist is not an integral type");

return source.x <= target.x && source.y <= target.y ? manhattan_distance<Lyt, Dist>(lyt, source, target) :
std::numeric_limits<Dist>::max();
static_cast<Dist>(std::numeric_limits<uint32_t>::max());
}
/**
* Computes the distance between two SiDB cells in nanometers (unit: nm).
Expand Down
28 changes: 14 additions & 14 deletions test/algorithms/path_finding/distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ TEST_CASE("2DDWave distance", "[distance]")
CHECK(twoddwave_distance<cart_lyt>(layout, {0, 0}, {1, 1}) == 2);
CHECK(twoddwave_distance<cart_lyt>(layout, {1, 2}, {3, 3}) == 3);
CHECK(twoddwave_distance<cart_lyt>(layout, {0, 0}, {4, 4}) == 8);
CHECK(twoddwave_distance<cart_lyt>(layout, {4, 4}, {0, 0}) == std::numeric_limits<uint64_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {2, 1}, {0, 2}) == std::numeric_limits<uint64_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {1, 0}, {0, 1}) == std::numeric_limits<uint64_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {4, 4}, {0, 0}) == std::numeric_limits<uint32_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {2, 1}, {0, 2}) == std::numeric_limits<uint32_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {1, 0}, {0, 1}) == std::numeric_limits<uint32_t>::max());

// ignore z-axis
CHECK(twoddwave_distance<cart_lyt>(layout, {0, 0, 1}, {8, 9, 0}) == 17);
Expand All @@ -247,18 +247,18 @@ TEST_CASE("2DDWave distance", "[distance]")
CHECK(twoddwave_distance<cart_lyt>(layout, {0, 0}, {1, 1}) == 2);
CHECK(twoddwave_distance<cart_lyt>(layout, {1, 2}, {3, 3}) == 3);
CHECK(twoddwave_distance<cart_lyt>(layout, {0, 0}, {4, 4}) == 8);
CHECK(twoddwave_distance<cart_lyt>(layout, {4, 4}, {0, 0}) == std::numeric_limits<uint64_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {2, 1}, {0, 2}) == std::numeric_limits<uint64_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {1, 0}, {0, 1}) == std::numeric_limits<uint64_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {4, 4}, {0, 0}) == std::numeric_limits<uint32_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {2, 1}, {0, 2}) == std::numeric_limits<uint32_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {1, 0}, {0, 1}) == std::numeric_limits<uint32_t>::max());

// ignore z-axis
CHECK(twoddwave_distance<cart_lyt>(layout, {0, 0, 1}, {8, 9, 0}) == 17);
CHECK(twoddwave_distance<cart_lyt>(layout, {0, 0, 1}, {8, 9, 1}) == 17);

// negative coordinates
CHECK(twoddwave_distance<cart_lyt>(layout, {0, 0}, {-1, -1}) == std::numeric_limits<uint64_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {-2, -8}, {-6, -4}) == std::numeric_limits<uint64_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {-6, -4}, {-2, -8}) == std::numeric_limits<uint64_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {0, 0}, {-1, -1}) == std::numeric_limits<uint32_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {-2, -8}, {-6, -4}) == std::numeric_limits<uint32_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {-6, -4}, {-2, -8}) == std::numeric_limits<uint32_t>::max());
CHECK(twoddwave_distance<cart_lyt>(layout, {-4, -3}, {1, -1}) == 7);
}
}
Expand All @@ -279,7 +279,7 @@ TEST_CASE("2DDWave distance functor", "[distance]")
CHECK(distance(layout, {0, 0}, {1, 1}) == 2);
CHECK(distance(layout, {1, 2}, {3, 3}) == 3);
CHECK(distance(layout, {0, 0}, {4, 4}) == 8);
CHECK(distance(layout, {4, 4}, {0, 0}) == std::numeric_limits<uint64_t>::max());
CHECK(distance(layout, {4, 4}, {0, 0}) == std::numeric_limits<uint32_t>::max());

// ignore z-axis
CHECK(distance(layout, {0, 0, 1}, {8, 9, 0}) == 17);
Expand All @@ -299,16 +299,16 @@ TEST_CASE("2DDWave distance functor", "[distance]")
CHECK(distance(layout, {0, 0}, {1, 1}) == 2);
CHECK(distance(layout, {1, 2}, {3, 3}) == 3);
CHECK(distance(layout, {0, 0}, {4, 4}) == 8);
CHECK(distance(layout, {4, 4}, {0, 0}) == std::numeric_limits<uint64_t>::max());
CHECK(distance(layout, {4, 4}, {0, 0}) == std::numeric_limits<uint32_t>::max());

// ignore z-axis
CHECK(distance(layout, {0, 0, 1}, {8, 9, 0}) == 17);
CHECK(distance(layout, {0, 0, 1}, {8, 9, 1}) == 17);

// negative coordinates
CHECK(distance(layout, {0, 0}, {-1, -1}) == std::numeric_limits<uint64_t>::max());
CHECK(distance(layout, {-2, -8}, {-6, -4}) == std::numeric_limits<uint64_t>::max());
CHECK(distance(layout, {-6, -4}, {-2, -8}) == std::numeric_limits<uint64_t>::max());
CHECK(distance(layout, {0, 0}, {-1, -1}) == std::numeric_limits<uint32_t>::max());
CHECK(distance(layout, {-2, -8}, {-6, -4}) == std::numeric_limits<uint32_t>::max());
CHECK(distance(layout, {-6, -4}, {-2, -8}) == std::numeric_limits<uint32_t>::max());
CHECK(distance(layout, {-4, -3}, {1, -1}) == 7);
}
}
Expand Down
14 changes: 6 additions & 8 deletions test/algorithms/path_finding/distance_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST_CASE("Distance map", "[distance-map]")
layout.foreach_coordinate(
[&layout, &dist_map, &dist_map_func, &c1, src](const auto& c2, const unsigned tgt)
{
CHECK(dist_map[src][tgt] == twoddwave_distance(layout, c1, c2));
CHECK(dist_map[src][tgt] == a_star_distance(layout, c1, c2));
CHECK(dist_map[src][tgt] == dist_map_func(layout, c1, c2));
});
});
Expand Down Expand Up @@ -111,7 +111,7 @@ TEST_CASE("Sparse distance map", "[distance-map]")
layout.foreach_coordinate(
[&layout, &dist_map, &dist_map_func, &c1](const auto& c2)
{
CHECK(dist_map.at({c1, c2}) == twoddwave_distance(layout, c1, c2));
CHECK(dist_map.at({c1, c2}) == a_star_distance(layout, c1, c2));
CHECK(dist_map.at({c1, c2}) == dist_map_func(layout, c1, c2));
});
});
Expand Down Expand Up @@ -186,18 +186,16 @@ TEST_CASE("Smart distance cache functor", "[distance-map]")
layout.foreach_coordinate(
[&layout, &dist_map_func](const auto& c1)
{
layout.foreach_coordinate(
[&layout, &dist_map_func, &c1](const auto& c2)
{ CHECK(dist_map_func(layout, c1, c2) == twoddwave_distance(layout, c1, c2)); });
layout.foreach_coordinate([&layout, &dist_map_func, &c1](const auto& c2)
{ CHECK(dist_map_func(layout, c1, c2) == a_star_distance(layout, c1, c2)); });
});

// check that the cached distances are correct
layout.foreach_coordinate(
[&layout, &dist_map_func](const auto& c1)
{
layout.foreach_coordinate(
[&layout, &dist_map_func, &c1](const auto& c2)
{ CHECK(dist_map_func(layout, c1, c2) == twoddwave_distance(layout, c1, c2)); });
layout.foreach_coordinate([&layout, &dist_map_func, &c1](const auto& c2)
{ CHECK(dist_map_func(layout, c1, c2) == a_star_distance(layout, c1, c2)); });
});
}
SECTION("USE clocking")
Expand Down

0 comments on commit ab73daa

Please sign in to comment.