3 #include <geneial/namespaces.h>
4 #include <geneial/core/population/chromosome/BaseChromosome.h>
5 #include <geneial/core/population/ContainerTypes.h>
6 #include <geneial/utility/mixins/Printable.h>
11 #include <unordered_map>
15 geneial_private_namespace(geneial)
17 geneial_private_namespace(population)
19 geneial_private_namespace(management)
21 geneial_export_namespace
23 template<
typename FITNESS_TYPE>
30 geneial_private_namespace(geneial)
32 geneial_private_namespace(population)
34 using ::geneial::utility::Printable;
35 using ::geneial::population::management::BaseManager;
36 geneial_export_namespace
39 template<
typename FITNESS_TYPE>
40 class Population:
public Printable
46 friend class BaseManager<FITNESS_TYPE>;
48 const static int POPULATION_AGE_INITIAL = 0;
51 typedef unsigned int population_age;
52 typedef unsigned int population_size;
55 typedef typename ContainerTypes<FITNESS_TYPE>::chromosome_container chromosome_container;
60 inline size_t operator() (
const typename BaseChromosome<FITNESS_TYPE>::chromsome_hash &hash)
const
67 typedef typename std::unordered_map<typename BaseChromosome<FITNESS_TYPE>::chromsome_hash,
68 typename BaseChromosome<FITNESS_TYPE>::ptr> hash_map;
71 typedef typename hash_map::value_type hashmap_value_type;
72 typedef typename hash_map::key_type hashmap_key_type;
74 typedef typename hash_map::const_iterator hashmap_const_it;
75 typedef typename hash_map::iterator hashmap_it;
78 typedef typename std::multimap<FITNESS_TYPE, typename BaseChromosome<FITNESS_TYPE>::ptr> fitness_map;
80 typedef typename fitness_map::value_type fitnessmap_value_type;
81 typedef typename fitness_map::key_type fitnessmap_key_type;
83 typedef typename fitness_map::const_iterator fitnessmap_const_it;
84 typedef typename fitness_map::iterator fitnessmap_it;
88 population_size getSize()
const;
94 virtual ~Population();
96 virtual void print(std::ostream& os)
const;
98 population_age getAge()
const;
100 void setAge(population_age age);
104 typename BaseChromosome<FITNESS_TYPE>::ptr getOldestChromosome();
106 typename BaseChromosome<FITNESS_TYPE>::ptr getYoungestChromosome();
108 const inline fitness_map& getFitnessMap()
const
113 const inline hash_map& getHashMap()
const
118 bool hashExists(
const typename BaseChromosome<FITNESS_TYPE>::chromsome_hash);
120 unsigned int removeDuplicates(chromosome_container &toCheck);
122 typename BaseChromosome<FITNESS_TYPE>::ptr getChromosomeByHash(
123 const typename BaseChromosome<FITNESS_TYPE>::chromsome_hash);
125 void replacePopulation(chromosome_container &replacementPopulation);
127 unsigned int insertChromosomeContainer(chromosome_container &container);
129 bool insertChromosome(
const typename BaseChromosome<FITNESS_TYPE>::ptr &chromosome);
131 void removeChromosomeContainer(
const chromosome_container &container);
133 void removeChromosome(
const typename BaseChromosome<FITNESS_TYPE>::ptr &chromosome);
135 void clearChromosomes();
137 BaseManager<FITNESS_TYPE>& getManager()
const
139 assert(!_manager.expired() &&
"Manager is already expired. Something was not properly bootstrapped");
140 const auto manager = _manager.lock();
146 void _insertChromosome(
const typename BaseChromosome<FITNESS_TYPE>::ptr &chromosome,
147 typename BaseChromosome<FITNESS_TYPE>::chromsome_hash hashValue);
149 fitness_map _fitnessMap;
157 std::weak_ptr<BaseManager<FITNESS_TYPE>> _manager;
164 #include <geneial/core/population/Population.hpp>