Ultra 0.9.4
Loading...
Searching...
No Matches
evaluator.tcc
Go to the documentation of this file.
1
12
13#if !defined(ULTRA_EVALUATOR_H)
14# error "Don't include this file directly, include the specific .h instead"
15#endif
16
17#if !defined(ULTRA_EVALUATOR_TCC)
18#define ULTRA_EVALUATOR_TCC
19
25template<Individual I>
26test_evaluator<I>::test_evaluator(test_evaluator_type et) : et_(et)
27{
28 ultraDEBUG("Creating a new instance of test_evaluator {}",
29 std::to_underlying(et));
30}
31
48template<Individual I>
49double test_evaluator<I>::operator()(const I &prg) const
50{
51 if (delay_ > std::chrono::milliseconds{0})
52 std::this_thread::sleep_for(delay_);
53
54 switch (et_)
55 {
56 case test_evaluator_type::fixed:
57 return 0.0;
58
59 case test_evaluator_type::random:
60 return random::sup<double>(1000000);
61
62 case test_evaluator_type::age:
63 return static_cast<double>(prg.age());
64
65 default: // test_evaluator_type::realistic
66 {
67 const auto signature(prg.signature());
68 return static_cast<double>(static_cast<std::uint32_t>(signature.data[0]));
69 }
70 }
71}
72
93template<Evaluator E> bool load_eva(std::istream &in, E *e)
94{
95 if constexpr (requires { { e->load(in) } -> std::convertible_to<bool>; })
96 return e->load(in);
97
98 return true;
99}
100
121template<Evaluator E> bool save_eva(std::ostream &out, const E &e)
122{
123 if constexpr (requires { { e.save(out) } -> std::convertible_to<bool>; })
124 return e.save(out);
125
126 return true;
127}
128
137template<Individual I>
138void test_evaluator<I>::delay(std::chrono::milliseconds ms) noexcept
139{
140 delay_ = ms;
141}
142
143#endif // include guard
bool save_eva(std::ostream &out, const E &e)
Definition evaluator.tcc:121
bool load_eva(std::istream &in, E *e)
Definition evaluator.tcc:93