![]() |
Ultra 0.9.4
|
#include <linear_population.h>
Public Member Functions | |
| linear_population ()=default | |
| linear_population (const ultra::problem &) | |
| I & | operator[] (std::size_t) |
| const I & | operator[] (std::size_t) const |
| std::size_t | size () const noexcept |
| std::size_t | safe_size () const |
| bool | empty () const noexcept |
| std::size_t | allowed () const noexcept |
| void | allowed (std::size_t) |
| unsigned | max_age () const noexcept |
| void | max_age (unsigned) noexcept |
| void | inc_age () |
| void | clear () noexcept |
| void | push_back (const I &) |
| void | pop_back () |
| void | reset (const ultra::problem &) |
| const_iterator | begin () const noexcept |
| iterator | begin () noexcept |
| const_iterator | end () const noexcept |
| iterator | end () noexcept |
| std::shared_mutex & | mutex () const |
| bool | load (std::istream &, const symbol_set &) |
| bool | save (std::ostream &) const |
| population_uid | uid () const noexcept |
| bool | is_valid () const |
A one-dimensional population of individuals.
| I | an individual type satisfying the Individual concept |
A linear_population represents a collection of individuals organised as a single, flat sequence. Individuals may interact (for example, by mating or selection) to produce offspring.
The population enforces an upper bound (allowed()) and a lower bound on its size. The invariant:
is maintained whenever the object is in a valid state.
This class does not provide internal synchronisation for most operations. Clients are responsible for serialising concurrent access using the mutex returned by mutex().
Multiple threads may safely call const member functions concurrently, provided that no thread performs a modifying operation at the same time.
Mixing read-only access with modifiers, or invoking non-const member functions concurrently, requires external synchronisation.
The only method that is explicitly thread-safe is safe_size().
Copying a population does not preserve its unique identifier (uid()), which is generated per application instance.
|
default |
Constructs an empty population.
The population is created with default limits and contains no individuals.
|
explicit |
Constructs a random population for a given problem.
| [in] | p | the problem definition |
The population size is initialised according to the problem parameters. Individuals are created using I(p).
|
nodiscardnoexcept |
| void linear_population::allowed | ( | std::size_t | n | ) |
Sets the maximum number of allowed individuals.
| [in] | n | the new maximum population size |
If the population size exceeds the new limit, surplus individuals are removed from the end of the sequence.
The value is clamped so that it's never less than the minimum allowed population size.
|
nodiscardnoexcept |
|
nodiscardnoexcept |
|
noexcept |
Removes all individuals from the population.
After this call size() == 0.
|
nodiscardnoexcept |
|
nodiscardnoexcept |
|
nodiscardnoexcept |
| void linear_population::inc_age | ( | ) |
Increments the age of all individuals.
|
nodiscard |
Checks the internal consistency of the population.
|
nodiscard |
Loads the population from a stream.
| [in] | in | input stream |
| [in] | ss | symbol_set used to rebuild individuals |
|
nodiscardnoexcept |
|
noexcept |
Sets the reference maximum age.
| [in] | m | the new maximum age |
|
nodiscard |
This mutex must be used by clients to synchronise concurrent access to the population.
|
nodiscard |
Access an individual by index.
| [in] | i | index of the individual |
|
nodiscard |
Access an individual by index (const).
| [in] | i | index of the individual |
| void linear_population::pop_back | ( | ) |
Removes the last individual from the population.
| void linear_population::push_back | ( | const I & | i | ) |
Adds an individual to the population.
| [in] | i | the individual to add |
The individual is added only if the population size is strictly less than the allowed maximum.
| void linear_population::reset | ( | const ultra::problem & | p | ) |
|
nodiscard |
|
nodiscard |
Saves the population to a stream.
| [out] | out | output stream |
|
nodiscardnoexcept |
|
nodiscardnoexcept |