27 int CMultiObjectiveMotionOptimizerBase::decide(
    28     const std::vector<mrpt::nav::TCandidateMovementPTG>& movs,
    32     score_values.resize(movs.size());
    35     for (
unsigned int mov_idx = 0; mov_idx < movs.size(); ++mov_idx)
    37         const auto& m = movs[mov_idx];
    42             p.second = std::numeric_limits<double>::quiet_NaN();
    45         for (
const auto& prop : m.props)
    63                         std::string(
"score: ") + f.first);
    65                 catch (std::exception&)
    78                             "Error: Expression name `%s` already exists as an "    84                         std::numeric_limits<double>::quiet_NaN();
    96             for (
size_t i = 0; i < N; i++)
   105                 catch (std::exception&)
   124                 val = sc.second.eval();
   130                     "Undefined value evaluating score `%s` for mov_idx=%u!",
   131                     sc.first.c_str(), mov_idx);
   135             score_values[mov_idx][sc.first] = 
val;
   143         double maxScore = .0;
   144         for (
const auto& s : score_values)
   146             const auto it = s.find(sScoreName);
   154             for (
auto& s : score_values)
   156                 auto it = s.find(sScoreName);
   163         else if (maxScore > 0 && maxScore != 1.0 )
   165             double K = 1.0 / maxScore;
   166             for (
auto& s : score_values)
   168                 auto it = s.find(sScoreName);
   178     for (
unsigned int mov_idx = 0; mov_idx < movs.size(); ++mov_idx)
   180         const auto& m = movs[mov_idx];
   184             p.second = std::numeric_limits<double>::quiet_NaN();
   186         for (
const auto& prop : m.props)
   192         bool assert_failed = 
false;
   196                 const double val = ma.eval();
   199                     assert_failed = 
true;
   201                         "[CMultiObjectiveMotionOptimizerBase] "   202                         "mov_idx=%u ASSERT failed: `%s`",
   203                         mov_idx, ma.get_original_expression().c_str()));
   210             for (
auto& e : score_values[mov_idx])
   224         const std::string& className) noexcept
   233         if (!classId) 
return nullptr;
   247     formula_score[
"collision_free_distance"] = 
"collision_free_distance";
   249         "var dif:=std::abs(target_k-move_k); if (dif>(num_paths/2)) { "   250         "dif:=num_paths-dif; }; exp(-std::abs(dif / (num_paths/10.0)));";
   252         "(ref_dist - dist_eucl_final) / ref_dist";
   265         formula_score.clear();
   269             const std::string sKeyName = 
mrpt::format(
"score%i_name", idx),
   271             const std::string sName = c.
read_string(s, sKeyName, 
"");
   272             const std::string sValue = c.
read_string(s, sKeyValue, 
"");
   274             const bool none = (sName.empty() && sValue.empty());
   275             const bool both = (!sName.empty() && !sValue.empty());
   277             if (none && idx == 1)
   279                     "Expect at least a first `%s` and `%s` pair defining one "   280                     "score in section `[%s]`",
   281                     sKeyName.c_str(), sKeyValue.c_str(), s.c_str());
   288                     "Both `%s` and `%s` must be provided in section `[%s]`",
   289                     sKeyName.c_str(), sKeyValue.c_str(), s.c_str());
   292             formula_score[sName] = sValue;
   298         movement_assert.clear();
   302             const std::string sKey = 
mrpt::format(
"movement_assert%i", idx);
   303             const std::string sValue = c.
read_string(s, sKey, 
"");
   304             if (sValue.empty()) 
break;
   305             movement_assert.push_back(sValue);
   310         scores_to_normalize.clear();
   311         std::string sLst = c.
read_string(s, 
"scores_to_normalize", 
"");
   327         const std::string sComment =
   329             "# Next follows a list of `score%i_{name,formula}` pairs for "   331             "# Each one defines one of the scores that will be evaluated for "   332             "each candidate movement.\n"   333             "# Multiobjective optimizers will then use those scores to select "   334             "the best candidate, \n"   335             "# possibly using more parameters that follow below.\n";
   336         c.
write(s, 
"dummy", 
"", WN, WV, sComment);
   339         for (
const auto& p : this->formula_score)
   342             const std::string sKeyName = 
mrpt::format(
"score%i_name", idx),
   344             c.
write(s, sKeyName, p.first, WN, WV);
   345             c.
write(s, sKeyValue, p.second, WN, WV);
   351         const std::string sComment =
   353             "# Next follows a list of `movement_assert%i` exprtk expressions "   355             "# defining expressions for conditions that any candidate movement "   357             "# in order to get through the evaluation process. *All* assert "   358             "conditions must be satisfied.\n";
   359         c.
write(s, 
"dummy2", 
"", WN, WV, sComment);
   361         for (
unsigned int idx = 0; idx < movement_assert.size(); idx++)
   363             const std::string sKey = 
mrpt::format(
"movement_assert%i", idx + 1);
   364             c.
write(s, sKey, movement_assert[idx], WN, WV);
   370         for (
const auto& sc : scores_to_normalize)
   373             sLst += std::string(
",");
   375         c.
write(s, 
"scores_to_normalize", sLst);
 std::shared_ptr< CObject > createObject() const
 
void registerAllPendingClasses()
Register all pending classes - to be called just before de-serializing an object, for example...
 
std::vector< std::string > log_entries
Optionally, debug logging info will be stored here by the implementor classes. 
 
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
 
std::map< std::string, double > m_expr_vars
 
std::string std::string format(std::string_view fmt, ARGS &&... args)
 
int MRPT_SAVE_NAME_PADDING()
Default padding sizes for macros MRPT_SAVE_CONFIG_VAR_COMMENT(), etc. 
 
virtual void clear()
Resets the object state; use if the parameters change, so they are re-read and applied. 
 
A structure that holds runtime class type information. 
 
mrpt::vision::TStereoCalibParams params
 
std::shared_ptr< CMultiObjectiveMotionOptimizerBase > Ptr
 
void tokenize(const std::string &inString, const std::string &inDelimiters, OUT_CONTAINER &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters. 
 
std::vector< std::map< std::string, double > > score_values
For each candidate (vector indices), the numerical evaluation of all scores defined in TParamsBase::f...
 
This class allows loading and storing values and vectors of different types from a configuration text...
 
IMPLEMENTS_VIRTUAL_MRPT_OBJECT(CMultiObjectiveMotionOptimizerBase, CObject, mrpt::nav) CMultiObjectiveMotionOptimizerBase
 
void saveToConfigFile(mrpt::config::CConfigFileBase &cfg, const std::string §ion) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...
 
static CMultiObjectiveMotionOptimizerBase::Ptr Factory(const std::string &className) noexcept
Class factory from C++ class name. 
 
std::vector< mrpt::expr::CRuntimeCompiledExpression > m_movement_assert_exprs
 
int MRPT_SAVE_VALUE_PADDING()
 
const TRuntimeClassId * findRegisteredClass(const std::string &className, const bool allow_ignore_namespace=true)
Return info about a given class by its name, or nullptr if the class is not registered. 
 
void write(const std::string §ion, const std::string &name, enum_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
 
std::map< std::string, std::string > formula_score
A list of name -> mathematical expression (in the format of the exprtk library) for the list of "scor...
 
Virtual base class for multi-objective motion choosers, as used for reactive navigation engines...
 
std::vector< std::string > scores_to_normalize
List of score names (as defined in the key of formula_score) that must be normalized across all candi...
 
std::map< std::string, mrpt::expr::CRuntimeCompiledExpression > m_score_exprs
score names -> score compiled expressions 
 
std::vector< std::string > movement_assert
A list of exprtk expressions for conditions that any candidate movement must fulfill in order to get ...
 
static CAST_TO::Ptr from(const CAST_FROM_PTR &ptr)
 
TParamsBase & m_params_base
 
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string §ion) override
This method load the options from a ".ini"-like file or memory-stored string list. 
 
CMultiObjectiveMotionOptimizerBase(TParamsBase ¶ms)
 
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
 
virtual int impl_decide(const std::vector< mrpt::nav::TCandidateMovementPTG > &movs, TResultInfo &extra_info)=0