27#include <SimoxUtility/algorithm/get_map_keys_values.h>
50 template <
class DerivedT>
62 explicit Prediction(
const std::map<PredictionEngine, Predictor>& predictors = {})
70 _predictors.emplace(engine.
engineID, predictor);
72 if (Predictive* predictive = this->_asPredictive())
74 predictive->addPredictionEngine(engine);
81 this->_predictors.clear();
82 for (
const auto& [engine, predictor] : predictors)
84 _predictors.emplace(engine.engineID, predictor);
87 if (Predictive* predictive = this->_asPredictive())
89 predictive->setPredictionEngines(simox::alg::get_keys(predictors));
98 std::vector<PredictionResult>
102 std::vector<PredictionResult> results;
103 for (
const auto& request : requests)
123 if (it != _predictors.end())
126 result = predictor(request);
131 std::stringstream sstream;
132 sstream <<
"Could not dispatch prediction request for " << request.
snapshotID
134 <<
"' in " << ownID <<
": Engine not registered.";
141 std::stringstream sstream;
142 sstream <<
"Could not dispatch prediction request for " << request.
snapshotID
143 <<
" to " << target <<
" from " << ownID;
150 std::map<std::string, Predictor> _predictors;
156 template <
class DerivedT>
167 std::vector<PredictionResult>
171 const std::map<MemoryID, std::vector<PredictionEngine>> engines =
172 derivedThis.getAllPredictionEngines();
174 std::vector<PredictionResult> results;
185 const std::vector<PredictionEngine>& supported) ->
bool
189 if (engine.engineID ==
190 request.predictionSettings.predictionEngineID)
198 if (iter != engines.end())
200 const MemoryID& responsibleID = iter->first;
207 std::stringstream sstream;
208 sstream <<
"Could not find segment offering prediction engine '"
209 << request.predictionSettings.predictionEngineID <<
"' for memory ID "
210 << request.snapshotID <<
".";
237 std::string childName = _getChildName(ownID, target);
242 typename DerivedT::ChildT* child =
nullptr;
243 derivedThis.forEachChild(
244 [&child, &childName](
auto& otherChild)
246 if (otherChild.name() == childName)
253 result = child->dispatchTargetedPrediction(request, target);
258 std::stringstream sstream;
259 sstream <<
"Could not find memory item with ID " << target <<
".";
266 std::stringstream sstream;
267 sstream <<
"Could not dispatch prediction request for " << request.
snapshotID
268 <<
" to " << target <<
" from " << ownID <<
".";
281 size_t parentLength = parent.
getItems().size();
284 std::vector<std::string> childItems = child.
getItems();
286 int index = parentLength;
289 return childItems[
index];
std::vector< std::string > getItems(bool escapeDelimiters=false) const
Get the levels from root to first not defined level (excluding).
Something that supports a set of prediction engines.
PredictionResult dispatchTargetedPrediction(const PredictionRequest &request, const MemoryID &target)
Semantics: This container or one of its children (target) is responsible for performing the predictio...
std::vector< PredictionResult > dispatchPredictions(const std::vector< PredictionRequest > &requests)
PredictionContainer(const std::map< PredictionEngine, Predictor > &predictors={})
Can do predictions, but has no children it could delegate predictions to.
void setPredictors(const std::map< PredictionEngine, Predictor > &predictors)
void addPredictor(const PredictionEngine &engine, Predictor &&predictor)
PredictionResult dispatchTargetedPrediction(const PredictionRequest &request, const MemoryID &target)
Dispatches a single prediction request (assuming resolution was done by the caller).
std::vector< PredictionResult > dispatchPredictions(const std::vector< PredictionRequest > &requests)
Resolves mapping of requests to predictors and dispatches them.
Prediction(const std::map< PredictionEngine, Predictor > &predictors={})
#define ARMARX_CHECK_FITS_SIZE(number, size)
Check whether number is nonnegative (>= 0) and less than size.
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
DerivedT & derived(ThisT *t)
std::function< PredictionResult(const PredictionRequest &)> Predictor
bool contains(const MemoryID &general, const MemoryID &specific)
Indicates whether general is "less specific" than, or equal to, specific, i.e.
std::map< MemoryID, ValueT >::const_iterator findMostSpecificEntryContainingIDAnd(const std::map< MemoryID, ValueT > &idMap, const MemoryID &id, const std::function< bool(const MemoryID &, const ValueT &)> &predicate)
Find the entry with the most specific key that contains the given ID and satisfies the predicate,...
armem::MemoryID snapshotID
PredictionSettings predictionSettings
armem::MemoryID snapshotID
std::string predictionEngineID