• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dedicate-project / beast / a47e88bc-4720-4817-b77a-d8632196f326

pending completion
a47e88bc-4720-4817-b77a-d8632196f326

Pull #9

circleci

fairlight1337
Added proper display of per-pipe mouse-over stats to the frontend
Pull Request #9: Adding pipeline applications

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

2922 of 3222 relevant lines covered (90.69%)

17290.06 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) {
8,289✔
40
  auto& list_genome = dynamic_cast<GAListGenome<unsigned char>&>(genome);
8,289✔
41
  std::vector<unsigned char> data;
8,289✔
42
  data.resize(list_genome.size());
8,289✔
43
  for (int32_t idx = 0; idx < list_genome.size(); ++idx) {
1,656,570✔
44
    data[idx] = *list_genome[idx];
1,648,280✔
45
  }
46

47
  auto* pipe = static_cast<EvolutionPipe*>(genome.userData());
8,289✔
48
  return static_cast<float>(pipe->evaluate(data));
16,578✔
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) {
1,210✔
67
  auto& list_genome = dynamic_cast<GAListGenome<unsigned char>&>(genome);
1,210✔
68
  auto* pipe = static_cast<EvolutionPipe*>(genome.userData());
1,210✔
69
  std::vector<unsigned char> item = pipe->drawInput(0);
2,420✔
70
  for (unsigned char value : item) {
241,210✔
71
    list_genome.insert(value);
240,000✔
72
  }
73
}
1,210✔
74
} // namespace
75

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

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

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

89
  algorithm.evolve();
25✔
90

91
  // Save the finalists if they pass the cut-off score.
92
  const GAPopulation& population = algorithm.population();
25✔
93
  for (int32_t pop_idx = 0; pop_idx < population.size(); ++pop_idx) {
1,235✔
94
    GAGenome& individual = population.individual(pop_idx);
1,210✔
95
    auto& list_genome = dynamic_cast<GAListGenome<unsigned char>&>(individual);
1,210✔
96
    if (list_genome.size() > 0 && individual.score() >= cut_off_score_) {
1,210✔
97
      std::vector<unsigned char> data;
144✔
98
      data.resize(list_genome.size());
72✔
99
      for (int32_t idx = 0; idx < list_genome.size(); ++idx) {
16,288✔
100
        data[idx] = *list_genome[idx];
16,216✔
101
      }
102

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

108
void EvolutionPipe::setCutOffScore(double cut_off_score) { cut_off_score_ = cut_off_score; }
24✔
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) {
72✔
115
  storeOutput(0, {std::move(finalist), static_cast<double>(score)});
72✔
116
}
72✔
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