![]() |
Ultra 0.9.4
|
#include <evolution.h>
Public Types | |
| using | individual_t = evaluator_individual_t<E> |
| using | fitness_t = evaluator_fitness_t<E> |
| using | after_generation_callback_t |
| using | refinement_callback_t = ultra::refinement_callback_t<E> |
| using | on_new_best_callback_t |
Public Member Functions | |
| evolution (const problem &, E &) | |
| template<template< class > class ES> | |
| summary< individual_t, fitness_t > | run () |
| evolution & | after_generation (after_generation_callback_t) |
| evolution & | logger (search_log &) |
| evolution & | refinement (refinement_callback_t) |
| evolution & | messages (bool) noexcept |
| evolution & | on_new_best (on_new_best_callback_t) |
| evolution & | shake_function (shake_function_callback_t) |
| evolution & | stop_source (std::stop_source) |
| evolution & | tag (const std::string &) |
| bool | is_valid () const |
| template<template< class > class ES> | |
| summary< typename evolution< E >::individual_t, typename evolution< E >::fitness_t > | run () |
| template<Population P> | |
| auto | refinement_tournament (const P &ref_pop) |
| template<Population P> | |
| bool | perform_refinement (P &ref_pop, internal::print_status &ps) |
| template<template< class > class ES> | |
| summary< typename evolution< E >::individual_t, typename evolution< E >::fitness_t > | run () |
The evolution class orchestrates the iterative improvement of a population of candidate solutions over multiple generations.
| E | evaluator type used to score individuals |
It is parameterised by an Evaluator, from which it derives:
The evolution process is strategy-driven: the actual evolutionary operators (selection, variation, replacement) are delegated to an evolution strategy supplied as a template parameter to run().
Evolution supports parallel execution through a thread pool. Each generation may evolve multiple subpopulations concurrently, while cooperative cancellation is handled via std::stop_source.
Users can customise behaviour via:
| using ultra::evolution< E >::after_generation_callback_t |
| using ultra::evolution< E >::on_new_best_callback_t |
|
explicit |
Construct an evolution object.
| [in] | prob | problem definition and evolutionary parameters |
| [in] | eva | evaluator used to compute fitness values |
Initialises the population according to the supplied problem description and stores a reference to the evaluator.
| evolution< E > & evolution::after_generation | ( | after_generation_callback_t | f | ) |
Registers a callback executed after each generation.
| [in] | f | callback function |
|
nodiscard |
Verify internal consistency.
| evolution< E > & evolution::logger | ( | search_log & | sl | ) |
Attaches a search logger.
| [in] | sl | logger instance |
When set, the logger records snapshots of the population and summary data at the end of each generation.
| bool ultra::evolution< E >::perform_refinement | ( | P & | ref_pop, |
| internal::print_status & | ps ) |
Performs refinement on a subset of the population.
| [in] | ps | console print-related data |
Performs a fraction-derived number of tournament draws, then discards duplicate coordinates before refinement. Therefore each selected individual is refined at most once per phase, and the number of backend invocations may be lower than the draw count.
| auto ultra::evolution< E >::refinement_tournament | ( | const P & | ref_pop | ) |
Selects a candidate individual for refinement by tournament selection.
| [in] | ref_pop | population subgroup from which the refinement candidate is selected |
A number of random individuals are sampled from the refinement population and evaluated. The coordinate of the individual with the best fitness is returned.
This biases numerical refinement towards promising individuals while still preserving a stochastic component in the choice of candidates.
| summary< typename evolution< E >::individual_t, typename evolution< E >::fitness_t > ultra::evolution< E >::run | ( | ) |
The evolutionary core loop.
| ES | evolution strategy template |
Runs the main evolutionary loop using the specified evolution strategy. The loop proceeds generation by generation until a stop condition is met.
The evolution strategy controls how offspring are generated and inserted into the population, while this class manages scheduling, monitoring, logging, and coordination.
The returned summary contains partial statistics: fitness-related measures are always computed, while more expensive metrics may be omitted unless explicitly requested elsewhere.
| summary< typename evolution< E >::individual_t, typename evolution< E >::fitness_t > ultra::evolution< E >::run | ( | ) |
The evolutionary core loop.
| ES | evolution strategy template |
Runs the main evolutionary loop using the specified evolution strategy. The loop proceeds generation by generation until a stop condition is met.
The evolution strategy controls how offspring are generated and inserted into the population, while this class manages scheduling, monitoring, logging, and coordination.
The returned summary contains partial statistics: fitness-related measures are always computed, while more expensive metrics may be omitted unless explicitly requested elsewhere.
| evolution< E > & evolution::shake_function | ( | shake_function_callback_t | f | ) |
Sets a per-generation shake function.
| [in] | f | shake function |
The shake function is invoked at the beginning of each generation and can be used to dynamically alter the problem environment (e.g. data resampling, noise injection...).
| evolution< E > & evolution::stop_source | ( | std::stop_source | ss | ) |
Sets an external stop source.
| [in] | ss | stop source |
Enables cooperative cancellation of the evolutionary process from another execution context.
| evolution< E > & evolution::tag | ( | const std::string & | t | ) |
Assigns an identification tag.
| [in] | t | tag string |
The tag is used in progress reporting to distinguish multiple concurrent evolution instances.