• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

dedicate-project / beast / 49939c40-5d31-48c2-8363-71719028ff1b

pending completion
49939c40-5d31-48c2-8363-71719028ff1b

Pull #9

circleci

fairlight1337
Made the right-click menu on the frontend a bit nicer
Pull Request #9: Adding pipeline applications

1399 of 1399 new or added lines in 23 files covered. (100.0%)

2922 of 3244 relevant lines covered (90.07%)

15773.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.18
/src/pipes/evolution_pipe.cpp
1
#include <beast/pipes/evolution_pipe.hpp>
2

3
// Standard
4
#include <stdexcept>
5

6
// GAlib
7
// NOTE: For these includes, the `register` error needs to be ignored as this
8
// 3rdparty library uses outdated code. This is not an issue for the library
9
// using it though.
10
#ifndef _MSC_VER
11
#pragma GCC diagnostic push
12
#pragma GCC diagnostic ignored "-Wregister"
13
#endif
14
#include <ga/GAListGenome.h>
15
#include <ga/GASimpleGA.h>
16
#ifndef _MSC_VER
17
#pragma GCC diagnostic pop
18
#endif
19

20
namespace beast {
21

22
namespace {
23
/**
24
 * @brief Intermediary function to trigger evaluation of Genomes
25
 *
26
 * The evolution pipe object is dereferences from the genome's user data to
27
 * trigger the instance's evaluation function. The resulting score value is then
28
 * returned to the GAlib mechanism.
29
 *
30
 * The function needs to be excluded from the clang-tidy linting process because
31
 * the parameter would need to be made const, which does not match GAlib's
32
 * evaluator signature. Ignoring it does no harm here as the function is not
33
 * used anywhere else.
34
 *
35
 * @param genome The GAlib genome to evaluate
36
 * @return The score value resulting from the evaluation
37
 */
38
// NOLINTNEXTLINE
39
float staticEvaluatorWrapper(GAGenome& genome) {
6,006✔
40
  auto& list_genome = dynamic_cast<GAListGenome<unsigned char>&>(genome);
6,006✔
41
  std::vector<unsigned char> data;
6,006✔
42
  data.resize(list_genome.size());
6,006✔
43
  for (int32_t idx = 0; idx < list_genome.size(); ++idx) {
1,250,800✔
44
    data[idx] = *list_genome[idx];
1,244,800✔
45
  }
46

47
  auto* pipe = static_cast<EvolutionPipe*>(genome.userData());
6,006✔
48
  return static_cast<float>(pipe->evaluate(data));
12,012✔
49
}
50

51
/**
52
 * @brief Intermediary function to initialize Genomes
53
 *
54
 * The evolution pipe object is dereferences from the genome's user data to draw
55
 * from the instance's initial population candidates. The GAlib genomes are then
56
 * initialized with that data.
57
 *
58
 * The function needs to be excluded from the clang-tidy linting process because
59
 * the parameter would need to be made const, which does not match GAlib's
60
 * evaluator signature. Ignoring it does no harm here as the function is not
61
 * used anywhere else.
62
 *
63
 * @param genome The GAlib genome to initialize
64
 */
65
// NOLINTNEXTLINE
66
void staticInitializerWrapper(GAGenome& genome) {
860✔
67
  auto& list_genome = dynamic_cast<GAListGenome<unsigned char>&>(genome);
860✔
68
  auto* pipe = static_cast<EvolutionPipe*>(genome.userData());
860✔
69
  std::vector<unsigned char> item = pipe->drawInput(0);
1,720✔
70
  for (unsigned char value : item) {
170,860✔
71
    list_genome.insert(value);
170,000✔
72
  }
73
}
860✔
74
} // namespace
75

76
EvolutionPipe::EvolutionPipe(uint32_t max_candidates) : Pipe(max_candidates, 1, 1) {}
42✔
77

78
void EvolutionPipe::execute() {
18✔
79
  GAListGenome<unsigned char> genome(staticEvaluatorWrapper);
36✔
80
  genome.initializer(staticInitializerWrapper);
18✔
81
  genome.userData(this);
18✔
82

83
  GASimpleGA algorithm(genome);
36✔
84
  algorithm.populationSize(getMaxCandidates());
18✔
85
  algorithm.nGenerations(num_generations_);
18✔
86
  algorithm.pMutation(mutation_probability_);
18✔
87
  algorithm.pCrossover(crossover_probability_);
18✔
88

89
  algorithm.evolve();
18✔
90

91
  // Save the finalists if they pass the cut-off score.
92
  const GAPopulation& population = algorithm.population();
18✔
93
  for (int32_t pop_idx = 0; pop_idx < population.size(); ++pop_idx) {
878✔
94
    GAGenome& individual = population.individual(pop_idx);
860✔
95
    auto& list_genome = dynamic_cast<GAListGenome<unsigned char>&>(individual);
860✔
96
    if (list_genome.size() > 0 && individual.score() >= cut_off_score_) {
860✔
97
      std::vector<unsigned char> data;
104✔
98
      data.resize(list_genome.size());
52✔
99
      for (int32_t idx = 0; idx < list_genome.size(); ++idx) {
13,577✔
100
        data[idx] = *list_genome[idx];
13,525✔
101
      }
102

103
      storeFinalist(std::move(data), individual.score());
52✔
104
    }
105
  }
106
}
18✔
107

108
void EvolutionPipe::setCutOffScore(double cut_off_score) { cut_off_score_ = cut_off_score; }
17✔
109

110
void EvolutionPipe::storeFinalist(const std::vector<unsigned char>& finalist, float score) {
×
111
  storeOutput(0, {finalist, static_cast<double>(score)});
×
112
}
×
113

114
void EvolutionPipe::storeFinalist(std::vector<unsigned char>&& finalist, float score) {
52✔
115
  storeOutput(0, {std::move(finalist), static_cast<double>(score)});
52✔
116
}
52✔
117

118
} // namespace beast
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc