Ultra 0.9.4
Loading...
Searching...
No Matches
evolution_status.tcc
Go to the documentation of this file.
1
12
13#if !defined(ULTRA_EVOLUTION_STATUS_H)
14# error "Don't include this file directly, include the specific .h instead"
15#endif
16
17#if !defined(ULTRA_EVOLUTION_STATUS_TCC)
18#define ULTRA_EVOLUTION_STATUS_TCC
19
20template<Individual I, Fitness F>
21evolution_status<I, F>::evolution_status(const unsigned *gen,
22 const global_update_f &f)
23 : update_overall_best_(f), generation_(gen)
24{
25}
26
33template<Individual I, Fitness F>
34bool evolution_status<I, F>::update_if_better(const scored_individual<I, F> &si)
35{
36 Expects(!si.empty());
37
38 const bool update(si > best_);
39
40 if (update)
41 {
42 best_ = si;
43
44 if (update_overall_best_)
45 update_overall_best_(best_);
46 }
47
48 return update;
49}
50
54template<Individual I, Fitness F>
55scored_individual<I, F> evolution_status<I, F>::best() const
56{
57 return best_;
58}
59
60template<Individual I, Fitness F>
61unsigned evolution_status<I, F>::generation() const
62{
63 return generation_ ? *generation_ : std::numeric_limits<unsigned>::max();
64}
65
76template<Individual I, Fitness F>
77bool evolution_status<I, F>::load(std::istream &in, const problem &p)
78{
79 scored_individual<I, F> tmp_si;
80 if (!tmp_si.load(in, p))
81 return false;
82
83 best_ = tmp_si;
84
85 return true;
86}
87
94template<Individual I, Fitness F>
95bool evolution_status<I, F>::save(std::ostream &out) const
96{
97 if (!best_.save(out))
98 return false;
99
100 // `generation_` is just a reference, no need to save it.
101
102 return out.good();
103}
104
105#endif // include guard