3 #include <geneial/algorithm/diagnostics/Diagnostics.h>
9 geneial_private_namespace(geneial)
11 geneial_private_namespace(algorithm)
14 geneial_export_namespace
17 template<
typename FITNESS_TYPE>
18 Diagnostics<FITNESS_TYPE>::Diagnostics(
const std::shared_ptr<BaseGeneticAlgorithm<FITNESS_TYPE>> &algorithm)
19 :_algorithm(algorithm)
21 instrumentAlgorithm();
25 template<
typename FITNESS_TYPE>
26 void Diagnostics<FITNESS_TYPE>::instrumentAlgorithm()
29 if (!_algorithm->hasBeenStarted())
33 if (!std::dynamic_pointer_cast<StatisticBookkeeper>(_algorithm->getBookkeeper()))
35 _algorithm->setBookkeeper(std::shared_ptr<StatisticBookkeeper>(
new StatisticBookkeeper));
40 std::runtime_error(
"Algorithm has already started! Unable to inject diagnosis instrumentation!");
48 template<
typename FITNESS_TYPE>
49 inline void Diagnostics<FITNESS_TYPE>::analyseAll(std::ostream& os)
54 template<
typename FITNESS_TYPE>
55 inline void Diagnostics<FITNESS_TYPE>::analyseTimeSpent(std::ostream& os)
57 auto statkeeper = std::dynamic_pointer_cast<StatisticBookkeeper>(_algorithm->getBookkeeper());
58 auto& events = statkeeper->getEvents();
62 printTiming(
"TIME_ITERATION",events,os);
63 printTiming(
"TIME_AGING",events,os);
64 printTiming(
"TIME_SELECTION",events,os);
65 printTiming(
"TIME_OFFSPRING",events,os);
66 printTiming(
"TIME_MUTATION",events,os);
67 printTiming(
"TIME_REPLACEMENT",events,os);
68 printTiming(
"TIME_REPLENISHMENT",events,os);
69 printTiming(
"TIME_CRITERIA",events,os);
70 printTiming(
"TIME_OBSERVERS",events,os);
73 template<
typename FITNESS_TYPE>
74 inline void Diagnostics<FITNESS_TYPE>::analyseEventsCoupling(std::ostream& os)
78 template<
typename FITNESS_TYPE>
79 inline void Diagnostics<FITNESS_TYPE>::analyseEventsCrossover(std::ostream& os)
83 template<
typename FITNESS_TYPE>
84 inline void Diagnostics<FITNESS_TYPE>::analyseEventsMutation(std::ostream& os)
88 template<
typename FITNESS_TYPE>
89 inline void Diagnostics<FITNESS_TYPE>::analyseEventsReplacement(std::ostream& os)
93 template<
typename FITNESS_TYPE>
94 inline void Diagnostics<FITNESS_TYPE>::anaylseEventsSelection(std::ostream& os)
98 template<
typename FITNESS_TYPE>
99 inline void Diagnostics<FITNESS_TYPE>::anaylseConvergence(std::ostream& os)