Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added additional distance functions and distance maps #250

Merged
merged 20 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6f9f63c
:sparkles: Added a 2DDWave distance function
marcelwa Jun 18, 2023
a6c8309
:memo: Added RST documentation for the 2DDWave distance function
marcelwa Jun 18, 2023
cf5d448
:construction: Work in progress save commit
marcelwa Jun 28, 2023
7698565
:memo: Adjusted docstrings
marcelwa Jul 11, 2023
d0fe319
:bug: Fixed coordinate comparison for 2DDWave distance
marcelwa Jul 11, 2023
d0a6fc9
:sparkles: Added `distance_map` and `sparse_distance_map` data types …
marcelwa Jul 11, 2023
b2c5185
:memo: Added documentation on distance maps
marcelwa Jul 11, 2023
666e0fb
:sparkles: Added `smart_distance_cache_functor` that builds up a dist…
marcelwa Jul 11, 2023
1ea9564
:art: ClangFormat changes
Jul 11, 2023
b1ab9d0
:white_check_mark: Passed failing test case
marcelwa Jul 12, 2023
eb83621
Merge remote-tracking branch 'origin/distances' into distances
marcelwa Jul 12, 2023
bf984a3
:alembic: Added a benchmarking framework to measure code efficiency
marcelwa Jul 12, 2023
ead02ee
:alembic: Added benchmarking for the `smart_distance_cache_functor`
marcelwa Jul 12, 2023
7ce10a8
:white_check_mark: Added test cases for the `smart_distance_cache_fun…
marcelwa Jul 12, 2023
70120e5
Merge branch 'main' into distances
marcelwa Jul 12, 2023
272c5b8
:white_check_mark: Added tests to ensure caching of `smart_distance_c…
marcelwa Jul 15, 2023
b2fcd63
:memo: Added documentation for `smart_distance_cache_functor`
marcelwa Jul 15, 2023
e92730f
:memo: Added documentation on the introduced code benchmarking feature
marcelwa Jul 18, 2023
501e600
:construction_worker: Make sure the benchmarks compile on every CI sy…
marcelwa Jul 18, 2023
8a20859
Merge branch 'main' into distances
marcelwa Jul 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ jobs:
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DFICTION_CLI=ON
-DFICTION_TEST=ON
-DFICTION_BENCHMARK=ON
-DFICTION_EXPERIMENTS=ON
-DFICTION_Z3=ON
-DFICTION_PROGRESS_BARS=OFF
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ jobs:
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DFICTION_CLI=ON
-DFICTION_TEST=ON
-DFICTION_BENCHMARK=ON
-DFICTION_EXPERIMENTS=ON
-DFICTION_Z3=ON
-DFICTION_ENABLE_MUGEN=ON
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DFICTION_CLI=ON
-DFICTION_TEST=ON
-DFICTION_BENCHMARK=ON
-DFICTION_EXPERIMENTS=ON
-DFICTION_Z3=ON
-DMOCKTURTLE_EXAMPLES=OFF
Expand Down
24 changes: 24 additions & 0 deletions docs/algorithms/path_finding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,35 @@ Distance functions compute (an approximation for) the distance between two coord

.. doxygenfunction:: fiction::manhattan_distance
.. doxygenfunction:: fiction::euclidean_distance
.. doxygenfunction:: fiction::twoddwave_distance

.. doxygenclass:: fiction::distance_functor
:members:
.. doxygenclass:: fiction::manhattan_distance_functor
.. doxygenclass:: fiction::euclidean_distance_functor
.. doxygenclass:: fiction::twoddwave_distance_functor

Distance Maps
-------------

Distance maps can store the distance from a coordinate to all other coordinates. They are particularly useful when
repeatedly calling complex distance functions that are expensive to evaluate. The distance maps can serve as a
lookup-table for these cases.

**Header:** ``fiction/algorithms/path_finding/distance_map.hpp``

.. doxygentypedef:: fiction::distance_map
.. doxygentypedef:: fiction::sparse_distance_map

.. doxygenfunction:: fiction::initialize_distance_map
.. doxygenfunction:: fiction::initialize_sparse_distance_map

.. doxygenclass:: fiction::distance_map_functor
:members:
.. doxygenclass:: fiction::sparse_distance_map_functor
:members:
.. doxygenclass:: fiction::smart_distance_cache_functor
:members:

Cost Functions
--------------
Expand Down
12 changes: 12 additions & 0 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ linked against *fiction* and compiled as a stand-alone binary using the followin
cmake --build . -j4


Building code benchmarks
------------------------

Using ``Catch2``'s micro-benchmarking feature, you can compile and run code tests that evaluate the performance of
certain code constructs. The ``test/benchmark`` folder provides a selection of benchmarks we were running to evaluate
the performance of our code during development. Any ``*.cpp`` file that is placed in that folder is automatically
linked against *fiction* and compiled as a stand-alone binary using the following commands::

cmake . -B build -DFICTION_BENCHMARK=ON
cd build
cmake --build . -j4

Uninstall
---------

Expand Down
44 changes: 42 additions & 2 deletions include/fiction/algorithms/path_finding/distance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <cmath>
#include <cstdint>
#include <functional>
#include <limits>
#include <type_traits>

namespace fiction
Expand Down Expand Up @@ -62,6 +63,33 @@ template <typename Lyt, typename Dist = double>

return static_cast<Dist>(std::hypot(x, y));
}
/**
* The 2DDWave distance \f$ D \f$ between two layout coordinates \f$ s = (x_1, y_1) \f$ and \f$ t = (x_2, y_2) \f$ given
* by
*
* \f$ D = |x_1 - x_2| + |y_1 - y_2| \f$ iff \f$ s \leq t \f$ and \f$ \infty \f$, otherwise.
*
* 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.
*
* @tparam Lyt Coordinate layout type.
* @tparam Dist Integral type for the distance.
* @param lyt Layout.
* @param source Source coordinate.
* @param target Target coordinate.
* @return 2DDWave distance between `source` and `target`.
*/
template <typename Lyt, typename Dist = uint64_t>
[[nodiscard]] constexpr Dist twoddwave_distance([[maybe_unused]] const Lyt& lyt, const coordinate<Lyt>& source,
const coordinate<Lyt>& target) noexcept
{
static_assert(is_coordinate_layout_v<Lyt>, "Lyt is not a coordinate layout");
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();
}
/**
* Computes the distance between two SiDB cells in nanometers.
*
Expand Down Expand Up @@ -109,7 +137,7 @@ class distance_functor
* @param dist_fn A function that maps from layout coordinates to a distance value.
*/
explicit distance_functor(
const std::function<Dist(const Lyt& lyt, const coordinate<Lyt>&, const coordinate<Lyt>&)>& dist_fn) :
const std::function<Dist(const Lyt&, const coordinate<Lyt>&, const coordinate<Lyt>&)>& dist_fn) :
distance_function{dist_fn}
{
static_assert(is_coordinate_layout_v<Lyt>, "Lyt is not a coordinate layout");
Expand All @@ -136,7 +164,7 @@ class distance_functor
/**
* Distance function.
*/
const std::function<Dist(const Lyt& lyt, const coordinate<Lyt>&, const coordinate<Lyt>&)> distance_function;
const std::function<Dist(const Lyt&, const coordinate<Lyt>&, const coordinate<Lyt>&)> distance_function;
};

// NOLINTEND(*-special-member-functions)
Expand Down Expand Up @@ -165,6 +193,18 @@ class euclidean_distance_functor : public distance_functor<Lyt, Dist>
public:
euclidean_distance_functor() : distance_functor<Lyt, Dist>(&euclidean_distance<Lyt, Dist>) {}
};
/**
* A pre-defined distance functor that uses the 2DDWave distance.
*
* @tparam Lyt Coordinate layout type.
* @tparam Dist Integral distance type.
*/
template <typename Lyt, typename Dist = uint64_t>
class twoddwave_distance_functor : public distance_functor<Lyt, Dist>
{
public:
twoddwave_distance_functor() : distance_functor<Lyt, Dist>(&twoddwave_distance<Lyt, Dist>) {}
};

} // namespace fiction

Expand Down
Loading
Loading