Skip to content

Commit

Permalink
Fixing elitism parameter for random replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
kataklinger committed Mar 6, 2024
1 parent 2638ec1 commit ba14d5a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
29 changes: 24 additions & 5 deletions src/inc/replacement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class random {
inline static constexpr fitness_tag_t fitness_tag{};

public:
inline explicit random(generator_t& generator) noexcept
inline explicit random(generator_t& generator,
countable_t<Elitism> /*unused*/) noexcept
: generator_{&generator} {
}

Expand All @@ -92,11 +93,29 @@ class random {
generator_t* generator_;
};

template<typename Generator, std::size_t Elitism = 0>
using random_raw = random<Generator, Elitism, raw_fitness_tag>;
template<typename Generator, std::size_t Elitism>
class random_raw : public random<Generator, Elitism, raw_fitness_tag> {
private:
using base_t = random<Generator, Elitism, raw_fitness_tag>;

public:
inline explicit random_raw(Generator& generator,
countable_t<Elitism> size) noexcept
: base_t{generator, size} {
}
};

template<typename Generator, std::size_t Elitism = 0>
using random_scaled = random<Generator, Elitism, scaled_fitness_tag>;
template<typename Generator, std::size_t Elitism>
class random_scaled : public random<Generator, Elitism, scaled_fitness_tag> {
private:
using base_t = random<Generator, Elitism, raw_fitness_tag>;

public:
inline explicit random_scaled(Generator& generator,
countable_t<Elitism> size) noexcept
: base_t{generator, size} {

Check failure on line 116 in src/inc/replacement.hpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release, gcc)

type ‘gal::replace::random<std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 2, gal::raw_fitness_tag>’ is not a direct base of ‘gal::replace::random_scaled<std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 2>’

Check failure on line 116 in src/inc/replacement.hpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release, gcc)

no matching function for call to ‘gal::replace::random<std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 2, gal::scaled_fitness_tag>::random()’

Check failure on line 116 in src/inc/replacement.hpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release, gcc)

type ‘gal::replace::random<std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 0, gal::raw_fitness_tag>’ is not a direct base of ‘gal::replace::random_scaled<std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 0>’

Check failure on line 116 in src/inc/replacement.hpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release, gcc)

no matching function for call to ‘gal::replace::random<std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 0, gal::scaled_fitness_tag>::random()’

Check failure on line 116 in src/inc/replacement.hpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release, clang)

type 'base_t' (aka 'random<std::mersenne_twister_engine<unsigned long, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 2UL, raw_fitness_tag>') is not a direct or virtual base of 'gal::replace::random_scaled<std::mersenne_twister_engine<unsigned long, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 2>'

Check failure on line 116 in src/inc/replacement.hpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release, clang)

type 'base_t' (aka 'random<std::mersenne_twister_engine<unsigned long, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 0UL, raw_fitness_tag>') is not a direct or virtual base of 'gal::replace::random_scaled<std::mersenne_twister_engine<unsigned long, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>, 0>'
}
};

template<typename FitnessTag>
class worst {
Expand Down
2 changes: 1 addition & 1 deletion src/scrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void test_ground() {
gal::select::lineal_raw sl6{};
sl6(p);

gal::replace::random_raw<std::mt19937, 2> ro1{gen};
gal::replace::random_raw ro1{gen, gal::countable<1>};
ro1(p, std::vector<parent_replacement_t>{});

gal::replace::worst<gal::raw_fitness_tag> ro2{};
Expand Down
24 changes: 12 additions & 12 deletions tests/operations/population/replacement_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct replacement_tests : public ::testing::Test {

TEST_F(replacement_tests, random_raw_elitism_removed_count) {
// arrange
gal::replace::random_raw<std::mt19937, 2> op{rng_};
gal::replace::random_raw op{rng_, gal::countable<2>};

// act
auto replaced = op(population_, offsprings_5_);
Expand All @@ -83,7 +83,7 @@ TEST_F(replacement_tests, random_raw_elitism_removed_count) {

TEST_F(replacement_tests, random_raw_elitism_removed_content) {
// arrange
gal::replace::random_raw<std::mt19937, 2> op{rng_};
gal::replace::random_raw op{rng_, gal::countable<2>};

// act
auto replaced = op(population_, offsprings_5_);
Expand All @@ -95,7 +95,7 @@ TEST_F(replacement_tests, random_raw_elitism_removed_content) {

TEST_F(replacement_tests, random_raw_elitism_added_content) {
// arrange
gal::replace::random_raw<std::mt19937, 2> op{rng_};
gal::replace::random_raw op{rng_, gal::countable<2>};

// act
op(population_, offsprings_5_);
Expand All @@ -107,7 +107,7 @@ TEST_F(replacement_tests, random_raw_elitism_added_content) {

TEST_F(replacement_tests, random_scaled_elitism_removed_count) {
// arrange
gal::replace::random_scaled<std::mt19937, 2> op{rng_};
gal::replace::random_scaled op{rng_, gal::countable<2>};

// act
auto replaced = op(population_, offsprings_5_);
Expand All @@ -118,7 +118,7 @@ TEST_F(replacement_tests, random_scaled_elitism_removed_count) {

TEST_F(replacement_tests, random_scaled_elitism_removed_content) {
// arrange
gal::replace::random_scaled<std::mt19937, 2> op{rng_};
gal::replace::random_scaled op{rng_, gal::countable<2>};

// act
auto replaced = op(population_, offsprings_5_);
Expand All @@ -130,7 +130,7 @@ TEST_F(replacement_tests, random_scaled_elitism_removed_content) {

TEST_F(replacement_tests, random_scaled_elitism_added_content) {
// arrange
gal::replace::random_scaled<std::mt19937, 2> op{rng_};
gal::replace::random_scaled op{rng_, gal::countable<2>};

// act
op(population_, offsprings_5_);
Expand All @@ -142,7 +142,7 @@ TEST_F(replacement_tests, random_scaled_elitism_added_content) {

TEST_F(replacement_tests, random_raw_no_elitism_removed_count) {
// arrange
gal::replace::random_raw op{rng_};
gal::replace::random_raw op{rng_, gal::countable<0>};

// act
auto replaced = op(population_, offsprings_5_);
Expand All @@ -153,7 +153,7 @@ TEST_F(replacement_tests, random_raw_no_elitism_removed_count) {

TEST_F(replacement_tests, random_raw_no_elitism_removed_content) {
// arrange
gal::replace::random_raw op{rng_};
gal::replace::random_raw op{rng_, gal::countable<0>};

// act
auto replaced = op(population_, offsprings_5_);
Expand All @@ -165,7 +165,7 @@ TEST_F(replacement_tests, random_raw_no_elitism_removed_content) {

TEST_F(replacement_tests, random_raw_no_elitism_added_content) {
// arrange
gal::replace::random_raw op{rng_};
gal::replace::random_raw op{rng_, gal::countable<0>};

// act
op(population_, offsprings_5_);
Expand All @@ -177,7 +177,7 @@ TEST_F(replacement_tests, random_raw_no_elitism_added_content) {

TEST_F(replacement_tests, random_scaled_no_elitism_removed_count) {
// arrange
gal::replace::random_scaled op{rng_};
gal::replace::random_scaled op{rng_, gal::countable<0>};

// act
auto replaced = op(population_, offsprings_5_);
Expand All @@ -188,7 +188,7 @@ TEST_F(replacement_tests, random_scaled_no_elitism_removed_count) {

TEST_F(replacement_tests, random_scaled_no_elitism_removed_content) {
// arrange
gal::replace::random_scaled op{rng_};
gal::replace::random_scaled op{rng_, gal::countable<0>};

// act
auto replaced = op(population_, offsprings_5_);
Expand All @@ -200,7 +200,7 @@ TEST_F(replacement_tests, random_scaled_no_elitism_removed_content) {

TEST_F(replacement_tests, random_scaled_no_elitism_added_content) {
// arrange
gal::replace::random_scaled op{rng_};
gal::replace::random_scaled op{rng_, gal::countable<0>};

// act
op(population_, offsprings_5_);
Expand Down

0 comments on commit ba14d5a

Please sign in to comment.