![]() |
Ultra 0.9.4
|
#include <interpreter.h>
Public Member Functions | |
| interpreter (const gp::individual &) | |
| value_t | run (const locus &) |
| value_t | run () |
| value_t | fetch_arg (std::size_t) const final |
| value_t | fetch_opaque_arg (std::size_t) const final |
| void | rebind (const gp::individual &) noexcept |
| bool | is_valid () const |
| const gp::individual & | program () const noexcept |
| Public Member Functions inherited from ultra::function::params | |
| value_t | operator[] (std::size_t i) const |
Executes a GP individual by interpreting its genome.
The interpreter provides the execution context required by GP functions (function::eval) and implements lazy, memoised argument evaluation through the function::params interface.
Evaluation proceeds by recursively visiting genes starting from a given locus (instruction pointer). When referential transparency is assumed, intermediate results are cached to avoid redundant evaluations.
When arguments are fetched via fetch_arg, the interpreter memoises the result associated with the referenced locus. This optimisation assumes referential transparency of the evaluated expressions.
Side effects must therefore be accessed through fetch_opaque_arg, which bypasses the cache.
The interpreter does not own the associated gp::individual. The lifetime of the individual must exceed that of the interpreter.
An interpreter instance is not thread-safe. It maintains mutable execution state (instruction pointer and evaluation cache) and must not be accessed concurrently from multiple threads. Parallel execution must be achieved by using one interpreter instance per thread.
|
explicit |
| [in] | ind | individual whose value we are interested in |
|
nodiscardfinalvirtual |
Fetches the value of the i-th argument of the current gene.
| [in] | i | i-th argument of the current gene |
We use a cache to avoid recalculating the same value during interpreter execution.
This assumes referential transparency. Side-effecting expressions must therefore be evaluated through fetch_opaque_arg.
This function may internally delegate to fetch_opaque_arg when caching is not applicable.
Implements ultra::function::params.
|
nodiscardfinalvirtual |
Fetches the value of an argument without assuming referential transparency.
| [in] | i | index of the argument to fetch |
This function retrieves the value of the i-th argument of the current gene by fully evaluating it, bypassing any memoisation mechanism.
It must be used for arguments whose evaluation may produce side effects or whose value must always be recomputed.
Implements ultra::function::params.
|
nodiscard |
|
nodiscardnoexcept |
|
noexcept |
Rebinds the interpreter to a different individual.
| [in] | ind | individual to which the interpreter is rebound |
This function updates the internal program pointer so that the interpreter evaluates the specified individual without reallocating or rebuilding its internal state.
These conditions are enforced by contracts and represent a logic error if violated.
| value_t ultra::interpreter::run | ( | ) |
Use the first available locus as starting IP.
Executes the associated individual starting from a given locus.
| [in] | l | locus identifying the gene from which execution starts |
This function initialises the interpreter state, invalidates cached values, sets the instruction pointer to the specified locus and evaluates the gene located there.