Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::summary< I, F > Class Template Reference

#include <evolution_summary.h>

Public Types

using on_new_best_callback_t = ultra::on_new_best_callback_t<I, F>

Public Member Functions

void clear ()
evolution_status< I, F > starting_status ()
summary & on_new_best (on_new_best_callback_t)
void set_best_fitness (F)
bool update_if_better (scored_individual< I, F >)
scored_individual< I, F > best () const
unsigned last_improvement () const
unsigned stagnation () const
bool load (std::istream &, const problem &)
bool save (std::ostream &) const

Public Attributes

analyzer< I, F > az {}
std::chrono::milliseconds elapsed {0}
 Time elapsed from evolution beginning.
unsigned generation {0}

Detailed Description

template<Individual I, Fitness F>
class ultra::summary< I, F >

A summary of information about evolution (results, statistics...).

Part of the information (status) supports concurrent access and is keep up to date while evolution is ongoing; the remaining part is calculated at the end of evolution.

Member Function Documentation

◆ best()

template<Individual I, Fitness F>
scored_individual< I, F > summary::best ( ) const
nodiscard
Returns
best scored individual found so far

◆ clear()

template<Individual I, Fitness F>
void summary::clear ( )

Resets summary information.

◆ last_improvement()

template<Individual I, Fitness F>
unsigned summary::last_improvement ( ) const
nodiscard
Returns
the generation the last improvement occurred in

◆ load()

template<Individual I, Fitness F>
bool summary::load ( std::istream & in,
const problem & p )
nodiscard

Loads the object from a stream.

Parameters
[in]ininput stream
[in]pactive problem
Returns
true if the object loaded correctly
Note
If the load operation isn't successful the current object isn't changed.

◆ on_new_best()

template<Individual I, Fitness F>
summary< I, F > & summary::on_new_best ( on_new_best_callback_t f)

Registers a callback invoked whenever a new best individual is discovered.

Parameters
[in]fthe callback to invoke on improvement. If empty, no callback is invoked
Returns
a reference to *this (fluent interface)
Precondition
This function must be called during the configuration phase, before concurrent evolution begins

The callback is triggered only when update_if_better() observes an improvement over the current best.

The callback is copied while holding the internal mutex and invoked after releasing it. As a consequence, it must be thread-safe and must not assume any additional synchronisation with summary.

Warning
Changing the callback while evolution is running is not supported.

◆ save()

template<Individual I, Fitness F>
bool summary::save ( std::ostream & out) const
nodiscard

Saves the object into a stream.

Parameters
[out]outoutput stream
Returns
true if summary was saved correctly

◆ set_best_fitness()

template<Individual I, Fitness F>
void summary::set_best_fitness ( F fit)

Replaces the fitness associated with the best individual.

Parameters
[in]fitfitness under the current evaluation context

This is used after the evaluation context changes and the current best individual is evaluated again. The individual and last-improvement generation are preserved, and the new-best callback isn't invoked.

◆ starting_status()

template<Individual I, Fitness F>
evolution_status< I, F > summary::starting_status ( )
nodiscard
Returns
a valid starting evolution status to be used by an evolution strategy

A starting evolution status is an "empty" evolution_status object with reference to this object correctly set, i.e.:

  • the callback function used to keep up to date the best individual found;
  • the current generation.

◆ update_if_better()

template<Individual I, Fitness F>
bool summary::update_if_better ( scored_individual< I, F > prg)

Keeps updated the best individual found so far.

Parameters
[in]prgcandidate new best scored individual
Returns
true if prg contains a new best individual

Member Data Documentation

◆ generation

template<Individual I, Fitness F>
unsigned ultra::summary< I, F >::generation {0}

Current generation. At the end of evolution contains the last generation reached.


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