diff --git a/docs/encodings.md b/docs/encodings.md index d6f1d156..71544905 100644 --- a/docs/encodings.md +++ b/docs/encodings.md @@ -83,6 +83,15 @@ recommendation is to use `std::variant` or a similar type for the gene type. +### Extending the candidates + +The candidates contain an additional `attributes` field that may hold any +additional data that is associated with the candidate. This field will always +be empty by default, as the library does not use it for anything by default. +The purpose of this field is to allow the user to extend the candidates with +arbitrary data if neccessary, and it may be used freely to do so. + + ### Variable chromosome lengths The length of the chromosomes is specified as part of the fitness function. diff --git a/src/core/candidate.hpp b/src/core/candidate.hpp index 2e5ea09e..36ef39e5 100644 --- a/src/core/candidate.hpp +++ b/src/core/candidate.hpp @@ -11,6 +11,7 @@ #include "../utility/iterators.hpp" #include #include +#include #include #include #include @@ -107,6 +108,9 @@ namespace gapp /** The solution's degree of constraint violation for each constraint. */ CVVector constraint_violation; + /** Arbitrary data associated with the candidate. */ + std::any attributes; + /** * @returns The number of objectives associated with the candidate.