Candidates & Populations#
-
namespace gapp
class FitnessVector#
#include <population/candidate.hpp>
class FitnessMatrix#
#include <population/candidate.hpp>
class CVVector#
#include <population/candidate.hpp>
-
using gapp::CVVector = small_vector<double, 2>#
The class used to represent the constraint violations of a candidate. It contains the degree of constraint violation for each constraint separately. Higher values mean greater degrees of constraint violation, while 0 or lower values mean no constraint violation for a given constraint.
The size of a constraint violation vector is equal to the number of constraints.
class Chromosome#
#include <population/candidate.hpp>
class CandidateInfo#
#include <population/candidate.hpp>
-
struct CandidateInfo#
The base class used for the representation of candidate solutions in all of the GAs. This class contains the parts of the candidates that are independent of the encoding type. The derived Candidate class contains the encoding dependent parts in addition to these.
- Template Parameters:
T – The gene type used in the candidate’s chromosome.
Subclassed by gapp::Candidate< Ts >, gapp::Candidate< RealGene >, gapp::Candidate< IntegerGene >, gapp::Candidate< PermutationGene >, gapp::Candidate< BinaryGene >, gapp::Candidate< T >
Public Functions
-
inline size_t num_objectives() const noexcept#
- Returns:
The number of objectives associated with the candidate. The return value will be 0 if called before the candidate has been evaluated. Equivalent to calling fitness.size().
-
inline bool is_evaluated() const noexcept#
- Returns:
True if the candidate has a valid fitness vector associated with it. Equivalent to calling !fitness.empty().
-
inline size_t num_constraints() const noexcept#
- Returns:
The number of constraints associated with the candidate. The return value will be 0 if called before the constraints have been evaluated. Equivalent to calling constraint_violation.size().
-
inline bool has_constraint_violation() const noexcept#
- Returns:
True if the candidate violates any of its constraints. If there are no constraints associated with the candidate, it will also return false. Returns false if called before the constraints have been evaluated.
Public Members
-
FitnessVector fitness#
The solution’s fitness value for each objective.
class Candidate#
#include <population/candidate.hpp>
-
template<typename T>
struct Candidate : public virtual gapp::CandidateInfo, public gapp::detail::CandidateBounds<T>, public gapp::detail::container_interface<Candidate<T>># The class that is used to represent candidate solutions in the genetic algorithms.
Contains several helper methods to access the chromosome directly, such as iterator methods. The behaviour of all these helper functions is equivalent to calling the matching functions on the chromosome member.
- Template Parameters:
T – The gene type used in the candidate’s chromosome.
Public Functions
-
Candidate() = default#
Create a candidate with an empty fitness vector and chromosome.
-
explicit Candidate(BoundsView<T> bounds)#
Create a candidate with an empty fitness vector, empty constraints vector, and the specified gene bounds.
- Parameters:
bounds – The lower and upper bounds of each gene of the chromosome. The size of the bounds should match the size of the chromosome later.
-
explicit Candidate(Chromosome<T> chrom)#
Create a candidate with an empty fitness vector and a given chromosome.
- Parameters:
chrom – The chromosome of the candidate.
-
Candidate(Chromosome<T> chrom, BoundsView<T> bounds)#
Create a candidate with an empty fitness vector, using the given chromosome and bounds.
- Parameters:
chrom – The chromosome of the candidate.
bounds – The bounds of each gene of the chromosome.
-
inline auto begin() noexcept#
- Returns:
An iterator to the first element of the candidate’s chromosome.
-
inline auto end() noexcept#
- Returns:
An iterator to the end of the candidate’s chromosome.
-
template<typename GeneType = T>
size_t chrom_len() const noexcept# - Returns:
The length of the chromosome.
-
template<typename GeneType = T>
Chromosome<GeneType> &chrom() & noexcept# - Returns:
The chromosome of the candidate.
-
template<typename GeneType = T>
const Chromosome<GeneType> &chrom( - Returns:
The chromosome of the candidate.
Public Members
-
Chromosome<T> chromosome#
The chromosome encoding the solution.
Public Static Attributes
-
static constexpr std::size_t NumChroms = 1#
The number of chromosomes the candidate has.
class Candidate<MixedGene>#
#include <population/candidate.hpp>
-
template<typename ...Ts>
struct Candidate<MixedGene<Ts...>> : public gapp::Candidate<Ts># The class used to represent candidate solutions in the mixed encoded genetic algorithms. It contains a separate chromosome for each component gene type of the mixed gene.
- Template Parameters:
Ts – The component gene types of the mixed gene.
Public Functions
-
Candidate() = default#
Create a candidate with an empty fitness vector and chromosomes.
-
inline explicit Candidate(std::tuple<Chromosome<Ts>...> chroms)#
Create a candidate with the specified chromosomes. The fitness and constraint vectors of the candidate will be empty.
- Parameters:
chroms – The chromosomes of the candidate solution.
- inline Candidate(
- std::tuple<Chromosome<Ts>...> chroms,
- detail::map_types_t<BoundsView, detail::filter_types_t<is_bounded_gene, Ts...>> bounds
Create a candidate with the specified chromosomes and bounds for each bounded component gene type. The bounds are only specified for the bounded component genes. The fitness and constraint vectors of the candidate will be empty.
- Parameters:
chroms – The chromosomes of the candidate solution.
bounds – The bounds vectors for each of the bounded chromosomes.
-
inline explicit Candidate(std::tuple<Candidate<Ts>...> parts)#
Create a candidate from a set of candidates for each of the component genes. The chromosomes and the bounds will be copied from the associated candidates, while the fitness and constraint vectors of the candidate will be empty.
- Parameters:
parts – The component candidates to create this candidate from.
-
template<typename GeneType>
size_t chrom_len() const noexcept# - Returns:
The length of the chromosome associated with the specified gene type.
-
template<typename GeneType>
Chromosome<GeneType> &chrom() & noexcept# - Returns:
The candidate’s chromosome associated with the specified gene type.
-
template<typename GeneType>
const Chromosome<GeneType> &chrom( - Returns:
The candidate’s chromosome associated with the specified gene type.
Public Static Attributes
-
template<>
struct constructor_tag_t#
class CandidatePair#
#include <population/candidate.hpp>
-
template<typename T>
struct CandidatePair# A pair of candidates.
class Candidates#
#include <population/population.hpp>
class Population#
#include <population/population.hpp>
class PopulationView#
#include <population/population.hpp>
-
using gapp::PopulationView = detail::base_view<const CandidateInfo>#
A view of a population without the encoding specific parts (i.e. without the chromosomes).
class Bounds#
#include <population/candidate.hpp>
-
template<typename T>
class Bounds# The class used to represent the lower and upper bounds of a gene.
- Template Parameters:
T – The gene type. The lower and upper bounds will also be this type.
Public Functions
Friends
- friend constexpr friend bool operator== (const Bounds &, const Bounds &)=default
- Returns:
true if the bounds are the same.