GENEIAL  0.2=/
 All Classes Pages
Diagnostics.hpp
1 #pragma once
2 
3 #include <geneial/algorithm/diagnostics/Diagnostics.h>
4 
5 #include <memory>
6 #include <algorithm>
7 #include <iomanip>
8 
9 geneial_private_namespace(geneial)
10 {
11 geneial_private_namespace(algorithm)
12 {
13 
14 geneial_export_namespace
15 {
16 
17 template<typename FITNESS_TYPE>
18 Diagnostics<FITNESS_TYPE>::Diagnostics(const std::shared_ptr<BaseGeneticAlgorithm<FITNESS_TYPE>> &algorithm)
19 :_algorithm(algorithm)
20 {
21  instrumentAlgorithm();
22 }
23 
24 
25 template<typename FITNESS_TYPE>
26 void Diagnostics<FITNESS_TYPE>::instrumentAlgorithm()
27 {
28  //Have we already done something?
29  if (!_algorithm->hasBeenStarted())
30  {
31  //Inject Statistical Bookkeeper
32  //Prepare Algorithm for Diagnosis
33  if (!std::dynamic_pointer_cast<StatisticBookkeeper>(_algorithm->getBookkeeper()))
34  {
35  _algorithm->setBookkeeper(std::shared_ptr<StatisticBookkeeper>(new StatisticBookkeeper));
36  }
37  }
38  else
39  {
40  std::runtime_error("Algorithm has already started! Unable to inject diagnosis instrumentation!");
41  }
42 }
43 
44 
45 
46 
47 
48 template<typename FITNESS_TYPE>
49 inline void Diagnostics<FITNESS_TYPE>::analyseAll(std::ostream& os)
50 {
51  analyseTimeSpent(os);
52 }
53 
54 template<typename FITNESS_TYPE>
55 inline void Diagnostics<FITNESS_TYPE>::analyseTimeSpent(std::ostream& os)
56 {
57  auto statkeeper = std::dynamic_pointer_cast<StatisticBookkeeper>(_algorithm->getBookkeeper());
58  auto& events = statkeeper->getEvents();
59 
60 // std::sort (events.begin(), events.end());
61 
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);
71 }
72 
73 template<typename FITNESS_TYPE>
74 inline void Diagnostics<FITNESS_TYPE>::analyseEventsCoupling(std::ostream& os)
75 {
76 }
77 
78 template<typename FITNESS_TYPE>
79 inline void Diagnostics<FITNESS_TYPE>::analyseEventsCrossover(std::ostream& os)
80 {
81 }
82 
83 template<typename FITNESS_TYPE>
84 inline void Diagnostics<FITNESS_TYPE>::analyseEventsMutation(std::ostream& os)
85 {
86 }
87 
88 template<typename FITNESS_TYPE>
89 inline void Diagnostics<FITNESS_TYPE>::analyseEventsReplacement(std::ostream& os)
90 {
91 }
92 
93 template<typename FITNESS_TYPE>
94 inline void Diagnostics<FITNESS_TYPE>::anaylseEventsSelection(std::ostream& os)
95 {
96 }
97 
98 template<typename FITNESS_TYPE>
99 inline void Diagnostics<FITNESS_TYPE>::anaylseConvergence(std::ostream& os)
100 {
101 }
102 
103 }
104 }
105 }