13#if !defined(ULTRA_ORACLE_H)
14# error "Don't include this file directly, include the specific .h instead"
17#if !defined(ULTRA_ORACLE_INTERNAL_TCC)
18#define ULTRA_ORACLE_INTERNAL_TCC
28template<
class P,
bool S>
class reg_oracle_storage;
57 explicit reg_oracle_storage(
const gp::individual &ind) : ind_(ind)
71 reg_oracle_storage(std::istream &in,
const symbol_set &ss)
73 if (!ind_.load(in, ss))
74 throw exception::data_format(
"Cannot load individual");
99 template<
class ...Args> [[nodiscard]]
value_t run(Args && ...args)
const
106 return int_->run(std::forward<Args>(args)...);
112 [[nodiscard]]
bool is_valid()
const
114 return ind_.is_valid();
123 bool save(std::ostream &out)
const {
return ind_.save(out); }
135 mutable std::optional<src::interpreter> int_ {};
140class reg_oracle_storage<gp::
individual, false>
143 explicit reg_oracle_storage(
const gp::individual &ind) : int_(ind)
144 { Ensures(is_valid()); }
146 template<
class ...Args> [[nodiscard]]
value_t run(Args && ...args)
const
148 return int_.run(std::forward<Args>(args)...);
151 [[nodiscard]]
bool is_valid()
const {
return true; }
154 bool save(std::ostream &out)
const
156 return int_.program().save(out);
160 mutable src::interpreter int_;
164template<gp::Team T,
bool S>
165class reg_oracle_storage<T, S>
168 explicit reg_oracle_storage(
const T &t)
170 team_.reserve(t.size());
171 for (
const auto &ind : t)
172 team_.emplace_back(ind);
177 reg_oracle_storage(std::istream &in,
const symbol_set &ss)
180 if (!(in >> n) || !n)
181 throw exception::data_format(
"Unknown/wrong number of programs");
184 for (std::size_t j(0); j < n; ++j)
185 team_.emplace_back(in, ss);
190 [[nodiscard]]
bool is_valid()
const
196 bool save(std::ostream &o)
const
198 return (o << team_.size() <<
'\n')
199 && std::ranges::all_of(
201 [&o](
const auto &ind) {
return ind.save(o); });
205 std::vector<reg_oracle_storage<typename T::value_type, S>> team_ {};
bool save(std::ostream &out, F f)
Definition fitness.tcc:150
value_t run(const gp::individual &ind)
Definition interpreter.cc:239
std::variant< D_VOID, D_INT, D_DOUBLE, D_STRING, const D_NULLARY *, D_ADDRESS, const D_VARIABLE *, D_IVECTOR > value_t
Definition value.h:54
std::ranges::range_value_t< P > individual(const P &p)
Definition population.h:107