![]() |
Ultra 0.9.4
|
#include <evaluator_proxy.h>
Public Member Functions | |
| evaluator_proxy (E, bitwidth) | |
| bool | load (std::istream &) |
| bool | save (std::ostream &) const |
| bool | load_cache (std::istream &) const |
| bool | save_cache (std::ostream &) const |
| void | clear () const noexcept |
| void | clear (const hash_t &) const |
| evaluator_fitness_t< E > | operator() (const evaluator_individual_t< E > &) const |
| evaluator_fitness_t< E > | fast (const evaluator_individual_t< E > &) const |
| bool | set_parallel_evaluation (unsigned, std::size_t=0) |
| const E & | core () const noexcept |
Provides controlled access to an evaluator with transparent caching.
| E | an Evaluator type |
evaluator_proxy acts as a surrogate for an Evaluator, adding an internal cache that stores fitness values keyed by individual signatures. This avoids repeated evaluation of semantically equivalent individuals and allows expensive evaluators to be reused efficiently.
The proxy preserves the semantics of the underlying evaluator while extending its capabilities with:
The cache is logically mutable: cache updates do not alter the observable behaviour of the evaluator. For this reason, most member functions are const.
| evaluator_proxy::evaluator_proxy | ( | E | eva, |
| bitwidth | ts ) |
Constructs an evaluator proxy.
| [in] | eva | the underlying ("real") evaluator |
| [in] | ts | cache size expressed as a bit width; the cache contains 2^ts elements. A value of zero disables caching |
|
noexcept |
Clears the entire evaluation cache.
Subsequent evaluations will recompute fitness values as if the cache were empty.
| void evaluator_proxy::clear | ( | const hash_t & | h | ) | const |
Clears a specific cache entry.
| [in] | h | signature of the individual whose cached fitness should be removed |
|
nodiscardnoexcept |
Provides read-only access to the underlying evaluator.
|
nodiscard |
Computes a fast fitness value for an individual.
If the underlying evaluator provides a fast member function, that function is invoked directly. Such results may be approximate and are not cached.
Otherwise, this function falls back to normal proxy evaluation via operator(), which may use the cache.
| bool evaluator_proxy::load | ( | std::istream & | in | ) |
Loads the persistent state of the proxy.
| [in,out] | in | input stream |
| bool evaluator_proxy::load_cache | ( | std::istream & | in | ) | const |
Loads the contents of the evaluation cache.
| [in,out] | in | input stream |
|
nodiscard |
Evaluates the fitness of an individual.
| [in] | prg | the individual to evaluate |
If caching is enabled and a cached value exists for the individual's signature, the cached fitness is returned. Otherwise, the underlying evaluator is invoked and the result is stored in the cache.
| bool evaluator_proxy::save | ( | std::ostream & | out | ) | const |
Saves the persistent state of the proxy.
This function saves:
| [out] | out | output stream |
| bool evaluator_proxy::save_cache | ( | std::ostream & | out | ) | const |
Saves the contents of the evaluation cache.
| bool evaluator_proxy::set_parallel_evaluation | ( | unsigned | helpers, |
| std::size_t | min_samples = 0 ) |
Configures parallel evaluation for evaluators that support it.
| [in] | helpers | number of helper threads; zero disables parallel evaluation |
| [in] | min_samples | minimum number of samples per thread; zero uses the evaluator's default |
Forwards the configuration to the underlying evaluator if supported.