GALib-Parallel
Header-only C++ library for parallel evolutionary algorithms
Loading...
Searching...
No Matches
ConsoleLogger.h
Go to the documentation of this file.
1#ifndef CONSOLE_LOGGER_H
2#define CONSOLE_LOGGER_H
3
4#pragma once
5
6#include <iostream>
7#include <cstddef>
8#include "core/Population.h"
9
10namespace galib::utils {
18 template <typename GeneType>
20 private:
21 std::size_t interval_m;
22
23 public:
28 explicit ConsoleLogger(const std::size_t interval) : interval_m(interval) {}
29
35 void log(const std::size_t gen, const Population<GeneType>& pop) {
36 if (interval_m > 0 && (gen % interval_m == 0 || gen == 0)) {
37 std::cout << "Generation " << gen
38 << " | Best Fitness: " << pop.getBestIndividual().getFitness()
39 << std::endl;
40 }
41 }
42 };
43} // namespace galib::utils
44
45#endif // CONSOLE_LOGGER_H
A container for a group of individuals in the genetic algorithm.
Definition Population.h:24
const Individual< GeneType > & getBestIndividual() const
Finds and returns the individual with the best fitness score.
Definition Population.h:112
Logger for printing optimization progress to the console.
void log(const std::size_t gen, const Population< GeneType > &pop)
Prints the current best fitness if the generation matches the interval.
ConsoleLogger(const std::size_t interval)
Constructs a console logger.