3 #include <geneial/utility/Debug.h>
5 #include <geneial/namespaces.h>
6 #include <geneial/core/population/chromosome/BaseChromosome.h>
14 geneial_private_namespace(geneial)
16 geneial_private_namespace(population)
18 geneial_private_namespace(chromosome)
21 geneial_export_namespace
24 template<
typename VALUE_TYPE,
typename FITNESS_TYPE>
25 class MultiValueChromosome:
public BaseChromosome<FITNESS_TYPE>
29 typedef typename BaseChromosome<FITNESS_TYPE>::chromsome_hash chromsome_hash;
31 typedef typename std::vector<VALUE_TYPE> value_container;
32 typedef typename value_container::const_iterator const_it;
33 typedef typename value_container::iterator it;
35 typedef typename std::shared_ptr<MultiValueChromosome<VALUE_TYPE, FITNESS_TYPE> > ptr;
36 typedef typename std::shared_ptr<const MultiValueChromosome<VALUE_TYPE, FITNESS_TYPE> > const_ptr;
38 explicit MultiValueChromosome(
typename FitnessEvaluator<FITNESS_TYPE>::ptr fitnessEvaluator) :
39 BaseChromosome<FITNESS_TYPE>(fitnessEvaluator), _container()
41 static_assert(std::is_arithmetic<VALUE_TYPE>::value,
"VALUE_TYPE is expected to be an arithmetic data type!");
42 static_assert(std::is_arithmetic<FITNESS_TYPE>::value,
"FITNESS_TYPE is expected to be an arithmetic data type!");
50 MultiValueChromosome(
const MultiValueChromosome& other) :
51 BaseChromosome<FITNESS_TYPE>(other._fitnessEvaluator), _container(other._container),
52 _cacheValid(other._cacheValid), _hashCache(other._hashCache)
60 MultiValueChromosome(MultiValueChromosome&& other) :
61 BaseChromosome<FITNESS_TYPE>(other._fitnessEvaluator), _container(),
62 _cacheValid(other._cacheValid), _hashCache(other._hashCache)
71 void swap(MultiValueChromosome& other)
74 swap(other._container,_container);
75 swap(other._fitnessEvaluator,this->_fitnessEvaluator);
76 swap(other._cacheValid,_cacheValid);
77 swap(other._hashCache,_hashCache);
80 virtual ~MultiValueChromosome()
84 bool equals(
const BaseChromosome<FITNESS_TYPE> &chromosome)
const override;
86 const_it getConstIt()
const;
89 unsigned int getSize()
const;
94 VALUE_TYPE getAverage()
const;
95 VALUE_TYPE getRange()
const;
96 VALUE_TYPE getSum()
const;
100 value_container& getContainer();
102 const value_container& getContainer()
const;
104 void setValueContainer(
const value_container& container);
106 void setValueContainer(value_container&& container);
110 void print(std::ostream& os)
const override;
112 chromsome_hash getHash()
const override;
114 bool inline hasCache()
const;
116 virtual void doInvalidate()
override
118 invalidateHashCache();
123 void inline invalidateHashCache()
const;
126 value_container _container;
128 mutable bool _cacheValid;
130 mutable chromsome_hash _hashCache;
139 #include <geneial/core/population/chromosome/MultiValueChromosome.hpp>