Skip to content

Commit

Permalink
Using fp_const for hypergrid granularity
Browse files Browse the repository at this point in the history
  • Loading branch information
kataklinger committed Mar 6, 2024
1 parent 779c194 commit e192e62
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
4 changes: 2 additions & 2 deletions sample/simple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void pesa() {
.stop(criteria::generation_limit{100})
.rank<pareto_preserved_t>(gal::rank::binary{})
.elite(elite::strict{})
.cluster(cluster::hypergrid<std::array<double, 2>, 0.1, 0.1>{})
.cluster(cluster::hypergrid<std::array<double, 2>, 0.1_dc, 0.1_dc>{})
.crowd(crowd::cluster{})
.prune(prune::cluster_random{rng})
.project(project::factory<project::truncate, crowd_density_t>{})
Expand Down Expand Up @@ -380,7 +380,7 @@ void pesa_ii() {
.stop(criteria::generation_limit{100})
.rank<pareto_preserved_t>(gal::rank::binary{})
.elite(elite::strict{})
.cluster(cluster::hypergrid<std::array<double, 2>, 0.1, 0.1>{})
.cluster(cluster::hypergrid<std::array<double, 2>, 0.1_dc, 0.1_dc>{})
.crowd(crowd::none{})
.prune(prune::cluster_random{rng})
.project(project::factory<project::none>{})
Expand Down
7 changes: 6 additions & 1 deletion src/inc/clustering.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,15 @@ namespace details {
return result;
}

template<typename Fitness>
using hypergrid_granularity_t =
literals::to_const_type<multiobjective_value_t<Fitness>>;

} // namespace details

// hypercell (pesa, pesa-ii, paes)
template<grid_fitness Fitness, multiobjective_value_t<Fitness>... Granularity>
template<grid_fitness Fitness,
details::hypergrid_granularity_t<Fitness>... Granularity>
class hypergrid {
private:
inline static constexpr std::array<multiobjective_value_t<Fitness>,
Expand Down
34 changes: 26 additions & 8 deletions src/inc/literals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,35 @@ inline constexpr fp_const<float> operator""_fc(long double value) noexcept {
return fp_const{static_cast<float>(value)};
}

template<typename Ty>
struct underlying_const_type_impl {
using type = Ty;
};
namespace details {

template<typename Ty>
struct underlying_const_type_impl {
using type = Ty;
};

template<typename Ty>
struct underlying_const_type_impl<fp_const<Ty>> {
using type = typename fp_const<Ty>::value_t;
};

template<typename Ty>
struct to_const_type_impl {
using type = Ty;
};

template<std::floating_point Ty>
struct to_const_type_impl<Ty> {
using type = fp_const<Ty>;
};

} // namespace details

template<typename Ty>
struct underlying_const_type_impl<fp_const<Ty>> {
using type = typename fp_const<Ty>::value_t;
};
using underlying_const_type =
typename details::underlying_const_type_impl<Ty>::type;

template<typename Ty>
using underlying_const_type = typename underlying_const_type_impl<Ty>::type;
using to_const_type = typename details::to_const_type_impl<Ty>::type;

} // namespace gal::literals
28 changes: 21 additions & 7 deletions tests/operations/multiobjective/clustering_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ class hypergird_exact_tests : public hypergird_base_tests {
};

TEST_F(hypergird_exact_tests, grouped_clusters_count) {
using namespace gal::literals;

// arrange
gal::cluster::hypergrid<fitness_t, 0.5, 0.5> op;
gal::cluster::hypergrid<fitness_t, 0.5_dc, 0.5_dc> op;

// act
auto clusters = op(*population_, pareto_);
Expand All @@ -318,8 +320,10 @@ TEST_F(hypergird_exact_tests, grouped_clusters_count) {
}

TEST_F(hypergird_exact_tests, grouped_clusters_content) {
using namespace gal::literals;

// arrange
gal::cluster::hypergrid<fitness_t, 0.5, 0.5> op;
gal::cluster::hypergrid<fitness_t, 0.5_dc, 0.5_dc> op;

// act
auto clusters = op(*population_, pareto_);
Expand All @@ -334,8 +338,10 @@ TEST_F(hypergird_exact_tests, grouped_clusters_content) {
}

TEST_F(hypergird_exact_tests, grouped_clusters_labels) {
using namespace gal::literals;

// arrange
gal::cluster::hypergrid<fitness_t, 0.5, 0.5> op;
gal::cluster::hypergrid<fitness_t, 0.5_dc, 0.5_dc> op;

// act
auto clusters = op(*population_, pareto_);
Expand All @@ -350,8 +356,10 @@ TEST_F(hypergird_exact_tests, grouped_clusters_labels) {
}

TEST_F(hypergird_exact_tests, unique_clusters_count) {
using namespace gal::literals;

// arrange
gal::cluster::hypergrid<fitness_t, 0.05, 0.05> op;
gal::cluster::hypergrid<fitness_t, 0.05_dc, 0.05_dc> op;

// act
auto clusters = op(*population_, pareto_);
Expand All @@ -361,8 +369,10 @@ TEST_F(hypergird_exact_tests, unique_clusters_count) {
}

TEST_F(hypergird_exact_tests, unique_clusters_labels) {
using namespace gal::literals;

// arrange
gal::cluster::hypergrid<fitness_t, 0.05, 0.05> op;
gal::cluster::hypergrid<fitness_t, 0.05_dc, 0.05_dc> op;

// act
auto clusters = op(*population_, pareto_);
Expand All @@ -381,8 +391,10 @@ class hypergird_overflow_tests : public hypergird_base_tests {
};

TEST_F(hypergird_overflow_tests, unique_clusters_count) {
using namespace gal::literals;

// arrange
gal::cluster::hypergrid<fitness_t, 0.05, 0.05> op;
gal::cluster::hypergrid<fitness_t, 0.05_dc, 0.05_dc> op;

// act
auto clusters = op(*population_, pareto_);
Expand All @@ -392,8 +404,10 @@ TEST_F(hypergird_overflow_tests, unique_clusters_count) {
}

TEST_F(hypergird_overflow_tests, unique_clusters_labels) {
using namespace gal::literals;

// arrange
gal::cluster::hypergrid<fitness_t, 0.05, 0.05> op;
gal::cluster::hypergrid<fitness_t, 0.05_dc, 0.05_dc> op;

// act
auto clusters = op(*population_, pareto_);
Expand Down

0 comments on commit e192e62

Please sign in to comment.