MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ select_replacement()

const RewriteOperator::Replacement * MayaFlux::Nodes::Network::RewriteOperator::select_replacement ( const Symbol & symbol,
const Environment & environment )
nodiscardprivate

Definition at line 148 of file RewriteOperator.cpp.

149{
150 m_candidates.clear();
151 m_weights.clear();
152
153 for (const auto& replacement : m_replacements) {
154 if (replacement.predecessor != symbol.id
155 || !matches_context(replacement, environment)
156 || (replacement.predicate && !replacement.predicate(symbol, environment))) {
157 continue;
158 }
159
160 if (!(replacement.weight > 0.0)) {
161 if (m_candidates.empty()) {
162 return &replacement;
163 }
164 continue;
165 }
166
167 m_candidates.push_back(&replacement);
168 m_weights.push_back(replacement.weight);
169 }
170
171 if (m_candidates.empty()) {
172 return nullptr;
173 }
174 if (m_candidates.size() == 1) {
175 return m_candidates.front();
176 }
177
179 return m_candidates[std::min(pick, m_candidates.size() - 1)];
180}
static size_t weighted_pick(std::span< const double > weights, Stochastic &generator)
Weighted random draw over a row of nonnegative weights.
std::vector< const Replacement * > m_candidates
bool matches_context(const Replacement &replacement, const Environment &environment) const
Kinesis::Stochastic::Stochastic m_generator
void pick(std::string title, std::vector< std::string > labels, PickCallback callback)
Open a window of clickable rows, one per label, and report the choice.
Definition Picker.cpp:49

References MayaFlux::Nodes::Network::RewriteOperator::Symbol::id, m_candidates, m_generator, m_replacements, m_weights, matches_context(), select_replacement(), and MayaFlux::Kinesis::Stochastic::Weights::weighted_pick().

Referenced by rewrite(), and select_replacement().

Here is the call graph for this function:
Here is the caller graph for this function: