3 * \remark This file is part of VITA.
5 * \copyright Copyright (C) 2013-2019 EOS di Manlio Morini.
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
10 * You can obtain one at http://mozilla.org/MPL/2.0/
13#if !defined(VITA_EVOLUTION_SUMMARY_H)
14# error "Don't include this file directly, include the specific .h instead"
17#if !defined(VITA_EVOLUTION_SUMMARY_TCC)
18#define VITA_EVOLUTION_SUMMARY_TCC
21/// Default constructor just call the summary::clear method.
24summary<T>::summary() : az(), best{T(), model_measurements()}, elapsed(0),
25 crossovers(0), mutations(0), gen(0), last_imp(0)
30/// Resets summary informations.
33void summary<T>::clear()
39/// Loads the object from a stream.
41/// \param[in] in input stream
42/// \param[in] p active problem
43/// \return `true` if the object loaded correctly
46/// If the load operation isn't successful the current object isn't changed.
49bool summary<T>::load(std::istream &in, const problem &p)
51 unsigned known_best(false);
52 if (!(in >> known_best))
59 if (!tmp_ind.load(in, p.sset))
62 decltype(best.score.fitness) tmp_fitness;
63 if (!tmp_fitness.load(in))
66 decltype(best.score.accuracy) tmp_accuracy;
67 if (!load_float_from_stream(in, &tmp_accuracy))
70 tmp_summary.best.solution = tmp_ind;
71 tmp_summary.best.score.fitness = tmp_fitness;
72 tmp_summary.best.score.accuracy = tmp_accuracy;
78 tmp_summary.elapsed = std::chrono::milliseconds(ms);
80 if (!(in >> tmp_summary.mutations >> tmp_summary.crossovers
81 >> tmp_summary.gen >> tmp_summary.last_imp))
89/// Saves the object into a stream.
91/// \param[out] out output stream
92/// \return `true` if summary was saved correctly
95bool summary<T>::save(std::ostream &out) const
97 // analyzer az doesn't need to be saved: it'll be recalculated at the
98 // beginning of evolution.
100 if (best.solution.empty())
105 best.solution.save(out);
106 best.score.fitness.save(out);
107 save_float_to_stream(out, best.score.accuracy);
111 out << elapsed.count() << ' ' << mutations << ' ' << crossovers << ' '
112 << gen << ' ' << last_imp << '\n';
117#endif // include guard