3 #include <geneial/namespaces.h>
4 #include <geneial/core/population/chromosome/BaseChromosome.h>
5 #include <geneial/core/population/Population.h>
6 #include <geneial/core/population/PopulationSettings.h>
7 #include <geneial/core/population/builder/BaseChromosomeFactory.h>
8 #include <geneial/core/population/management/Bookkeeper.h>
9 #include <geneial/utility/ExecutionManager.h>
10 #include <geneial/utility/mixins/EnableMakeShared.h>
14 geneial_private_namespace(geneial)
16 geneial_private_namespace(population)
18 geneial_private_namespace(management)
20 using ::geneial::population::chromosome::BaseChromosomeFactory;
21 using ::geneial::utility::BaseExecutionManager;
22 using ::geneial::utility::SequentialExecutionManager;
23 using ::geneial::utility::EnableMakeShared;
25 geneial_export_namespace
31 template<
typename FITNESS_TYPE>
32 class BaseManager :
public std::enable_shared_from_this<BaseManager<FITNESS_TYPE> >,
33 public EnableMakeShared<BaseManager<FITNESS_TYPE>>
36 explicit BaseManager<FITNESS_TYPE>(
const std::shared_ptr<BaseChromosomeFactory<FITNESS_TYPE>> &chromosomeFactory) :
38 _populationSettings(),
39 _chromosomeFactory(chromosomeFactory),
40 _executionManager(
new SequentialExecutionManager),
41 _bookkeeper(std::make_shared<DefaultBookkeeper>())
44 BaseManager(
const BaseManager& other) =
delete;
45 BaseManager(
const BaseManager&& other) =
delete;
48 static std::shared_ptr<BaseManager<FITNESS_TYPE>> create(
const std::shared_ptr<BaseChromosomeFactory<FITNESS_TYPE>> chromosomeFactory)
50 auto prototype = BaseManager<FITNESS_TYPE>::makeShared(chromosomeFactory);
52 prototype->_population._manager = prototype;
54 return std::move(prototype);
58 virtual ~BaseManager<FITNESS_TYPE>()
62 void replacePopulation(
typename Population<FITNESS_TYPE>::chromosome_container replacementPopulation);
67 void replenishPopulation();
69 typename BaseChromosome<FITNESS_TYPE>::ptr getHighestFitnessChromosome()
const;
71 FITNESS_TYPE getHighestFitness()
const;
73 typename BaseChromosome<FITNESS_TYPE>::ptr getLowestFitnessChromosome()
const;
75 FITNESS_TYPE getLowestFitness()
const;
77 Population<FITNESS_TYPE>& getPopulation()
82 Population<FITNESS_TYPE>& getPopulation()
const
84 return const_cast<Population<FITNESS_TYPE>&
>(_population);
87 BaseChromosomeFactory<FITNESS_TYPE>& getChromosomeFactory()
const
89 return _chromosomeFactory;
92 void setChromosomeFactory(std::shared_ptr<BaseChromosomeFactory<FITNESS_TYPE>> chromosomeFactory)
94 _chromosomeFactory = chromosomeFactory;
97 PopulationSettings& getPopulationSettings()
99 return _populationSettings;
102 void setPopulationSettings(PopulationSettings& populationSettings)
104 _populationSettings = populationSettings;
107 BaseExecutionManager& getExecutionManager()
const
109 return *_executionManager;
112 void setExecutionManager(std::unique_ptr<BaseExecutionManager>&& executionManager)
114 _executionManager = std::move(executionManager);
117 std::shared_ptr<BaseBookkeeper> getBookkeeper()
const
122 void setBookkeeper(
const std::shared_ptr<BaseBookkeeper>& bookkeeper)
124 _bookkeeper = bookkeeper;
128 Population<FITNESS_TYPE> _population;
130 PopulationSettings _populationSettings;
132 std::shared_ptr<BaseChromosomeFactory<FITNESS_TYPE>> _chromosomeFactory;
134 std::unique_ptr<BaseExecutionManager> _executionManager;
136 std::shared_ptr<BaseBookkeeper> _bookkeeper;
146 #include <geneial/core/population/management/BaseManager.hpp>