40 template <std::convertible_to<
double>... Values>
41 requires(
sizeof...(Values) > 0 &&
sizeof...(Values) <= max_symbol_parameters)
44 ,
parameters {
static_cast<double>(values)... }
45 , arity(
static_cast<uint8_t
>(
sizeof...(Values)))
49 [[nodiscard]] std::optional<double> parameter(
size_t index)
const noexcept;
61 static const char tag {};
68 std::span<const Symbol>
word;
78 [[nodiscard]]
const C&
controls() const noexcept
80 static const C none {};
146 [[nodiscard]]
static std::vector<Symbol> symbols_from_text(std::string_view text);
149 [[nodiscard]]
static Successor text_successor(std::string_view text);
152 bool replace(Replacement replacement);
153 bool replace(SymbolId predecessor, Successor successor, Predicate predicate = {});
156 bool replace(SymbolId predecessor, std::string_view successor,
double weight = 0.0);
183 template <
typename C>
189 m_read = [
this](std::string_view name) {
201 template <
typename C>
202 void set(
const C& incoming)
208 template <
typename C>
209 [[nodiscard]] C
get()
const
215 [[nodiscard]] RewriteResult rewrite(uint64_t steps = 1, std::span<const double> inputs = {});
218 [[nodiscard]] SubmitResult submit();
229 [[nodiscard]] GrowResult grow(uint64_t steps = 1, std::span<const double> inputs = {});
235 [[nodiscard]]
bool published() const noexcept;
238 [[nodiscard]]
bool restore_axiom();
257 [[nodiscard]] std::shared_ptr<const Word> active_word()
const;
265 void process(
float frames)
override;
268 void set_parameter(std::string_view name,
double value)
override;
271 [[nodiscard]] std::optional<double> query_state(std::string_view name)
const override;
272 [[nodiscard]] std::string_view
get_type_name()
const override {
return "Rewrite"; }
276 std::shared_ptr<const Word>
word;
290 void drain_retired();
291 [[nodiscard]]
bool matches_context(
const Replacement& replacement,
const Environment& environment)
const;
292 [[nodiscard]]
const Replacement* select_replacement(
const Symbol& symbol,
const Environment& environment);
298 std::function<std::shared_ptr<const void>()>
m_hold;
299 std::function<std::optional<double>(std::string_view)>
m_read;
static std::optional< double > read_named(const C &controls, std::string_view name)
Unified generative infrastructure for stochastic and procedural algorithms.
C & declare_controls()
Create the operator's controls struct and keep it alive.
void merge_controls(const C &incoming)
Apply the members of incoming that hold a value, for an operator whose controls type is not fixed.
C snapshot_controls() const
A copy of the declared struct, for an operator whose controls type is not fixed.
Operator that acts on a network's slots over one block at a time.
std::atomic< bool > m_full
bool push(Submission &submission) noexcept
Submission pop() noexcept
std::string_view get_type_name() const override
Type name for introspection.
void clear_replacements() noexcept
std::atomic< uint64_t > m_active_submission_id
bool m_retirement_received
std::function< bool(Symbol)> EmitSymbol
Append a symbol; false on a bound violation.
void set(const C &incoming)
Apply the members of incoming that hold a value; empty members are left alone.
bool valid() const noexcept
SubmissionMailbox m_retired
std::function< std::shared_ptr< const void >()> m_hold
std::shared_ptr< const Word > m_active_word
std::shared_ptr< const Word > draft_word() const noexcept
The draft word on the producer lane: the axiom, or what rewrite() last built.
Kinesis::Stochastic::Stochastic & generator() noexcept
The generator behind weighted choices.
static const void * controls_tag() noexcept
A tag that is the same for every use of one type C in a module, and differs between types.
SubmissionMailbox m_ready
std::atomic< uint64_t > m_active_generation
static constexpr size_t max_symbol_parameters
uint64_t active_generation() const noexcept
uint64_t m_max_generations
std::function< std::optional< double >(std::string_view)> m_read
std::vector< const Replacement * > m_candidates
std::vector< Replacement > m_replacements
std::vector< SymbolId > m_ignore
std::vector< double > m_weights
std::function< void(const Symbol &, Environment, const EmitSymbol &)> Successor
uint64_t m_next_submission_id
std::span< const Symbol > active_symbols() const noexcept
Read the active word on the RelationNetwork processing lane.
uint64_t draft_generation() const noexcept
RewriteOperator(Config config)
std::shared_ptr< const Word > m_draft
std::shared_ptr< const Word > m_axiom
C get() const
The controls with the values the operator holds now.
Kinesis::Stochastic::Stochastic m_generator
GrowResult
What grow() did; the first failure of its rewrite or its submit.
C & declare()
Declare the struct of controls the grammar's rules read, and return it.
std::function< bool(const Symbol &, Environment)> Predicate
Bounded parallel rewriting of a typed word in a RelationNetwork.
Globlal configuration for MayaFlux.
std::vector< Symbol > axiom
std::vector< SymbolId > ignore
std::span< const double > inputs
const C & controls() const noexcept
The grammar's controls as they were when this rewrite began.
std::span< const Symbol > word
What a replacement sees: the caller's inputs, the word with the symbol's position in it,...
std::vector< SymbolId > right
std::vector< SymbolId > left
One rewrite rule: left < predecessor > right, if predicate, with weight.
std::shared_ptr< const Word > word
std::array< double, max_symbol_parameters > parameters
Symbol(SymbolId symbol_id, Values... values)
Symbol(SymbolId id, std::initializer_list< double > values={})
std::vector< Symbol > symbols