Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::evaluator_proxy< E > Class Template Reference

#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

Detailed Description

template<Evaluator E>
class ultra::evaluator_proxy< E >

Provides controlled access to an evaluator with transparent caching.

Template Parameters
Ean 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:

  • memoisation of fitness values;
  • optional fast (approximate) evaluation;
  • optional persistence of both evaluator state and cache contents.

The cache is logically mutable: cache updates do not alter the observable behaviour of the evaluator. For this reason, most member functions are const.

Constructor & Destructor Documentation

◆ evaluator_proxy()

template<Evaluator E>
evaluator_proxy::evaluator_proxy ( E eva,
bitwidth ts )

Constructs an evaluator proxy.

Parameters
[in]evathe underlying ("real") evaluator
[in]tscache size expressed as a bit width; the cache contains 2^ts elements. A value of zero disables caching

Member Function Documentation

◆ clear() [1/2]

template<Evaluator E>
void evaluator_proxy::clear ( ) const
noexcept

Clears the entire evaluation cache.

Subsequent evaluations will recompute fitness values as if the cache were empty.

◆ clear() [2/2]

template<Evaluator E>
void evaluator_proxy::clear ( const hash_t & h) const

Clears a specific cache entry.

Parameters
[in]hsignature of the individual whose cached fitness should be removed

◆ core()

template<Evaluator E>
const E & evaluator_proxy::core ( ) const
nodiscardnoexcept

Provides read-only access to the underlying evaluator.

Returns
a const reference to the wrapped evaluator

◆ fast()

template<Evaluator E>
evaluator_fitness_t< E > evaluator_proxy::fast ( const evaluator_individual_t< E > & prg) const
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.

◆ load()

template<Evaluator E>
bool evaluator_proxy::load ( std::istream & in)

Loads the persistent state of the proxy.

Parameters
[in,out]ininput stream
Returns
true if the proxy was loaded successfully
Warning
If the load operation fails, the object may be left in a partially modified state. The temporary object needed to holds values from the stream conceivably is too big to justify the "no change" warranty.

◆ load_cache()

template<Evaluator E>
bool evaluator_proxy::load_cache ( std::istream & in) const

Loads the contents of the evaluation cache.

Parameters
[in,out]ininput stream
Returns
true if the cache was loaded successfully
Warning
If the load operation fails, the cache may be left in a partially modified state.

◆ operator()()

template<Evaluator E>
evaluator_fitness_t< E > evaluator_proxy::operator() ( const evaluator_individual_t< E > & prg) const
nodiscard

Evaluates the fitness of an individual.

Parameters
[in]prgthe individual to evaluate
Returns
the fitness value

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.

◆ save()

template<Evaluator E>
bool evaluator_proxy::save ( std::ostream & out) const

Saves the persistent state of the proxy.

This function saves:

  • the state of the underlying evaluator (if it supports persistence);
  • the contents of the evaluation cache.
Parameters
[out]outoutput stream
Returns
true if the proxy was saved successfully

◆ save_cache()

template<Evaluator E>
bool evaluator_proxy::save_cache ( std::ostream & out) const

Saves the contents of the evaluation cache.

Returns
true if the cache was saved successfully

◆ set_parallel_evaluation()

template<Evaluator E>
bool evaluator_proxy::set_parallel_evaluation ( unsigned helpers,
std::size_t min_samples = 0 )

Configures parallel evaluation for evaluators that support it.

Parameters
[in]helpersnumber of helper threads; zero disables parallel evaluation
[in]min_samplesminimum number of samples per thread; zero uses the evaluator's default
Returns
true if the underlying evaluator accepted the configuration

Forwards the configuration to the underlying evaluator if supported.


The documentation for this class was generated from the following files: