Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::fitnd Class Reference

#include <fitness.h>

Public Types

using value_type = double
using values_t = std::vector<value_type>
using iterator = values_t::iterator
using const_iterator = values_t::const_iterator
using difference_type = values_t::difference_type

Public Member Functions

constexpr fitnd (std::initializer_list< double >)
 fitnd (values_t)
 fitnd (with_size, value_type=std::numeric_limits< value_type >::lowest())
std::size_t size () const noexcept
bool empty () const noexcept
value_type operator[] (std::size_t) const
value_type & operator[] (std::size_t)
iterator begin () noexcept
iterator end () noexcept
const_iterator begin () const noexcept
const_iterator end () const noexcept
fitnd & operator+= (const fitnd &)
fitnd & operator-= (const fitnd &)
fitnd & operator*= (const fitnd &)
fitnd & operator/= (const fitnd &)
fitnd & operator*= (value_type)
fitnd & operator/= (value_type)

Friends

auto operator<=> (const fitnd &, const fitnd &)=default
bool load (std::istream &, fitnd *)
fitnd combine (const fitnd &, const fitnd &)

(Note that these are not member symbols.)

bool load (std::istream &in, fitnd *f)
std::ostream & operator<< (std::ostream &o, const fitnd &f)
std::istream & operator>> (std::istream &in, fitnd &f)
fitnd operator+ (fitnd lhs, const fitnd &rhs)
fitnd operator- (fitnd lhs, const fitnd &rhs)
fitnd operator* (fitnd lhs, const fitnd &rhs)
fitnd operator/ (fitnd lhs, const fitnd &rhs)
fitnd operator/ (fitnd f, fitnd::value_type v)
fitnd operator* (fitnd f, fitnd::value_type v)
fitnd combine (const fitnd &f1, const fitnd &f2)

Detailed Description

A basic multi-dimensional fitness type.

Useful for rapid prototyping. Real use cases may require ad-hoc fitness type.

Constructor & Destructor Documentation

◆ fitnd() [1/3]

fitnd::fitnd ( std::initializer_list< double > l)
inlineconstexpr

Builds a fitness from a list of values.

◆ fitnd() [2/3]

ultra::fitnd::fitnd ( values_t v)

Builds a fitness from a vector of values.

◆ fitnd() [3/3]

ultra::fitnd::fitnd ( with_size s,
value_type v = std::numeric_limits<value_type>::lowest() )

Fills the fitness with copies of a given value.

Parameters
[in]sdimension of the the fitness vector
[in]vdefault value

Both Herb Sutter and Scott Meyers recommend to avoid class designs where a initializer_list constructor overload can cause ambiguities to the programmer. We use a tag to avoid such situations.

The tag also helps to clarify the meaning of the other arguments.

Member Function Documentation

◆ begin() [1/2]

fitnd::const_iterator ultra::fitnd::begin ( ) const
nodiscardnoexcept
Returns
returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to cend()

◆ begin() [2/2]

fitnd::iterator ultra::fitnd::begin ( )
nodiscardnoexcept
Returns
returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to end()

◆ empty()

bool ultra::fitnd::empty ( ) const
nodiscardnoexcept
Returns
true if size() == 0.

◆ end() [1/2]

fitnd::const_iterator ultra::fitnd::end ( ) const
nodiscardnoexcept
Returns
an iterator to the element following the last element

◆ end() [2/2]

fitnd::iterator ultra::fitnd::end ( )
nodiscardnoexcept
Returns
an iterator to the element following the last element

◆ operator*=() [1/2]

fitnd & ultra::fitnd::operator*= ( const fitnd & f)
Parameters
[in]fa fitness
Returns
product of this and f

◆ operator*=() [2/2]

fitnd & ultra::fitnd::operator*= ( fitnd::value_type v)
Parameters
[in]vscalar value
Returns
the product of this and v

◆ operator+=()

fitnd & ultra::fitnd::operator+= ( const fitnd & f)
Parameters
[in]fa fitness
Returns
the sum of this and f

◆ operator-=()

fitnd & ultra::fitnd::operator-= ( const fitnd & f)
Parameters
[in]fa fitness
Returns
the difference of this and f

◆ operator/=() [1/2]

fitnd & ultra::fitnd::operator/= ( const fitnd & f)
Parameters
[in]fa fitness
Returns
division of this and f

◆ operator/=() [2/2]

fitnd & ultra::fitnd::operator/= ( fitnd::value_type v)
Parameters
[in]vscalar value
Returns
the division of this and v

◆ operator[]() [1/2]

fitnd::value_type & ultra::fitnd::operator[] ( std::size_t i)
nodiscard
Parameters
[in]iindex of an element
Returns
a reference to the i-th element of the fitness vector

◆ operator[]() [2/2]

fitnd::value_type ultra::fitnd::operator[] ( std::size_t i) const
nodiscard
Parameters
[in]iindex of an element
Returns
the i-th element of the fitness vector

◆ size()

std::size_t ultra::fitnd::size ( ) const
nodiscardnoexcept
Returns
the size of the fitness vector

◆ combine()

fitnd combine ( const fitnd & f1,
const fitnd & f2 )
related
Parameters
[in]f1first fitness value
[in]f2second fitness value
Returns
the fitness vector obtained joining f1 and f2

◆ load()

bool load ( std::istream & in,
fitnd * f )
related

Deserialises a fitnd value.

Parameters
[in]ininput stream
[out]fload the fitness here
Returns
true if the object has been loaded correctly
Note
If the load operation isn't successful 'f' isn't changed.

◆ operator*() [1/2]

fitnd operator* ( fitnd f,
fitnd::value_type v )
related
Parameters
[in]fa fitness value
[in]va scalar
Returns
a new vector obtained multiplying each component of f by the scalar value v

◆ operator*() [2/2]

fitnd operator* ( fitnd lhs,
const fitnd & rhs )
related
Parameters
[in]lhsfirst factor
[in]rhssecond factor
Returns
the product of lhs and rhs

◆ operator+()

fitnd operator+ ( fitnd lhs,
const fitnd & rhs )
related
Parameters
[in]lhsfirst addend
[in]rhssecond addend
Returns
the sum of lhs and rhs

◆ operator-()

fitnd operator- ( fitnd lhs,
const fitnd & rhs )
related
Parameters
[in]lhsminuend
[in]rhssubtrahend
Returns
difference between lhs and rhs

◆ operator/() [1/2]

fitnd operator/ ( fitnd f,
fitnd::value_type v )
related
Parameters
[in]fa fitness value
[in]va scalar
Returns
a new vector obtained dividing each component of f by the scalar value v

◆ operator/() [2/2]

fitnd operator/ ( fitnd lhs,
const fitnd & rhs )
related
Parameters
[in]lhsfirst factor
[in]rhssecond factor
Returns
the division of lhs and rhs

◆ operator<<()

std::ostream & operator<< ( std::ostream & o,
const fitnd & f )
related

Standard output operator for fitnd.

Parameters
[out]ooutput stream to print data to
[in]fconstant reference to a fitness to insert
Returns
o

This function is used for displaying values / debugging. For serialisation use the save function.

◆ operator>>()

std::istream & operator>> ( std::istream & in,
fitnd & f )
related

Standard input operator for fitnd.

Parameters
[in]ina character input stream
[out]fa fitness to be extracted
Returns
in
Warning
For deserialisation use the load function.

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