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

#include <scored_individual.h>

Public Member Functions

 scored_individual (I, F)
bool empty () const noexcept
bool load (std::istream &, const problem &)
bool save (std::ostream &) const

Public Attributes

I ind {}
F fit {lowest<F>()}

Detailed Description

template<Individual I, Fitness F>
struct ultra::scored_individual< I, F >

Associates an individual with its fitness value.

Template Parameters
Itype modelling an individual
Ftype modelling a fitness value

scored_individual is a lightweight value type used to represent the result of evaluating an individual. It is primarily intended for ranking, selection, and replacement operations in evolutionary algorithms.

The class supports ordering by fitness (via operator<=>) but deliberately does not define equality. Fitness values are typically floating-point and exact equality comparisons would be semantically misleading.

Note
Since equality is not defined, scored_individual does not model a totally ordered type and cannot be used with default std::ranges::less. Algorithms that require ordering should provide an explicit comparator or projection (e.g. comparing the fit member).

Constructor & Destructor Documentation

◆ scored_individual()

template<Individual I, Fitness F>
scored_individual::scored_individual ( I i,
F f )

Builds a new individual/fitness pair.

Parameters
[in]ian individual (can be empty)
[in]fa fitness

Member Function Documentation

◆ empty()

template<Individual I, Fitness F>
bool scored_individual::empty ( ) const
nodiscardnoexcept
Returns
true if the ind component is empty

◆ load()

template<Individual I, Fitness F>
bool scored_individual::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.

◆ save()

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

Saves the object into a stream.

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

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