Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::evolution< E > Class Template Reference

#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 ()

Detailed Description

template<Evaluator E>
class ultra::evolution< E >

The evolution class orchestrates the iterative improvement of a population of candidate solutions over multiple generations.

Template Parameters
Eevaluator type used to score individuals

It is parameterised by an Evaluator, from which it derives:

  • the individual representation;
  • the fitness type;
  • the evaluation semantics.

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().

Responsibilities

  • Initialise and validate the population.
  • Execute the evolutionary loop across generations.
  • Dispatch parallel tasks to evolve subpopulations.
  • Monitor progress and termination conditions.
  • Collect summary statistics and optional logs.
  • Invoke user-defined hooks and callbacks.

Concurrency model

Evolution supports parallel execution through a thread pool. Each generation may evolve multiple subpopulations concurrently, while cooperative cancellation is handled via std::stop_source.

Customisation points

Users can customise behaviour via:

  • evolution strategies;
  • per-generation callbacks;
  • shake functions;
  • logging facilities;
  • external stop sources.
See also
layered_population
evolution_strategy

Member Typedef Documentation

◆ after_generation_callback_t

template<Evaluator E>
using ultra::evolution< E >::after_generation_callback_t
Initial value:
ultra::after_generation_callback_t<individual_t, fitness_t>

◆ on_new_best_callback_t

template<Evaluator E>
using ultra::evolution< E >::on_new_best_callback_t
Initial value:
ultra::on_new_best_callback_t<individual_t, fitness_t>

Constructor & Destructor Documentation

◆ evolution()

template<Evaluator E>
evolution::evolution ( const problem & prob,
E & eva )
explicit

Construct an evolution object.

Parameters
[in]probproblem definition and evolutionary parameters
[in]evaevaluator used to compute fitness values

Initialises the population according to the supplied problem description and stores a reference to the evaluator.

Member Function Documentation

◆ after_generation()

template<Evaluator E>
evolution< E > & evolution::after_generation ( after_generation_callback_t f)

Registers a callback executed after each generation.

Parameters
[in]fcallback function
Returns
a reference to this object (fluent interface)

◆ is_valid()

template<Evaluator E>
bool evolution::is_valid ( ) const
nodiscard

Verify internal consistency.

Returns
true if the object passes the internal consistency check

◆ logger()

template<Evaluator E>
evolution< E > & evolution::logger ( search_log & sl)

Attaches a search logger.

Parameters
[in]sllogger instance
Returns
reference to this object (fluent interface)

When set, the logger records snapshots of the population and summary data at the end of each generation.

Remarks
Logging is disabled by default.

◆ perform_refinement()

template<Evaluator E>
template<Population P>
bool ultra::evolution< E >::perform_refinement ( P & ref_pop,
internal::print_status & ps )

Performs refinement on a subset of the population.

Parameters
[in]psconsole print-related data
Returns
true if at least one refinement backend invocation occurred

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.

◆ refinement_tournament()

template<Evaluator E>
template<Population P>
auto ultra::evolution< E >::refinement_tournament ( const P & ref_pop)

Selects a candidate individual for refinement by tournament selection.

Parameters
[in]ref_poppopulation subgroup from which the refinement candidate is selected
Returns
coordinate of the selected individual

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.

◆ run() [1/2]

template<Evaluator E>
template<template< class > class ES>
summary< typename evolution< E >::individual_t, typename evolution< E >::fitness_t > ultra::evolution< E >::run ( )

The evolutionary core loop.

Template Parameters
ESevolution strategy template
Returns
a summary describing the outcome of the evolutionary search

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.

See also
evolution_strategy
summary

◆ run() [2/2]

template<Evaluator E>
template<template< class > class ES>
summary< typename evolution< E >::individual_t, typename evolution< E >::fitness_t > ultra::evolution< E >::run ( )

The evolutionary core loop.

Template Parameters
ESevolution strategy template
Returns
a summary describing the outcome of the evolutionary search

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.

See also
evolution_strategy
summary

◆ shake_function()

template<Evaluator E>
evolution< E > & evolution::shake_function ( shake_function_callback_t f)

Sets a per-generation shake function.

Parameters
[in]fshake function
Returns
reference to this object (fluent interface)

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...).

◆ stop_source()

template<Evaluator E>
evolution< E > & evolution::stop_source ( std::stop_source ss)

Sets an external stop source.

Parameters
[in]ssstop source
Returns
reference to this object (fluent interface)

Enables cooperative cancellation of the evolutionary process from another execution context.

◆ tag()

template<Evaluator E>
evolution< E > & evolution::tag ( const std::string & t)

Assigns an identification tag.

Parameters
[in]ttag string
Returns
reference to this object (fluent interface)

The tag is used in progress reporting to distinguish multiple concurrent evolution instances.


The documentation for this class was generated from the following files: