Go to the documentation of this file.
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)
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])
233 if (!classId)
return nullptr;
248 formula_score[
"collision_free_distance"] =
"collision_free_distance";
250 "var dif:=abs(target_k-move_k); if (dif>(num_paths/2)) { "
251 "dif:=num_paths-dif; }; exp(-abs(dif / (num_paths/10.0)));";
253 "(ref_dist - dist_eucl_final) / ref_dist";
266 formula_score.clear();
275 const bool none = (sName.empty() && sValue.empty());
276 const bool both = (!sName.empty() && !sValue.empty());
278 if (none && idx == 1)
280 "Expect at least a first `%s` and `%s` pair defining one "
281 "score in section `[%s]`",
282 sKeyName.c_str(), sKeyValue.c_str(),
s.c_str());
289 "Both `%s` and `%s` must be provided in section `[%s]`",
290 sKeyName.c_str(), sKeyValue.c_str(),
s.c_str());
293 formula_score[sName] = sValue;
299 movement_assert.clear();
305 if (sValue.empty())
break;
306 movement_assert.push_back(sValue);
311 scores_to_normalize.clear();
312 std::string sLst =
c.read_string(
s,
"scores_to_normalize",
"");
330 "# Next follows a list of `score%i_{name,formula}` pairs for "
332 "# Each one defines one of the scores that will be evaluated for "
333 "each candidate movement.\n"
334 "# Multiobjective optimizers will then use those scores to select "
335 "the best candidate, \n"
336 "# possibly using more parameters that follow below.\n";
337 c.write(
s,
"dummy",
"", WN, WV, sComment);
340 for (
const auto&
p : this->formula_score)
345 c.write(
s, sKeyName,
p.first, WN, WV);
346 c.write(
s, sKeyValue,
p.second, WN, WV);
354 "# Next follows a list of `movement_assert%i` exprtk expressions "
356 "# defining expressions for conditions that any candidate movement "
358 "# in order to get through the evaluation process. *All* assert "
359 "conditions must be satisfied.\n";
360 c.write(
s,
"dummy2",
"", WN, WV, sComment);
362 for (
unsigned int idx = 0; idx < movement_assert.size(); idx++)
365 c.write(
s, sKey, movement_assert[idx], WN, WV);
371 for (
const auto& sc : scores_to_normalize)
376 c.write(
s,
"scores_to_normalize", sLst);
static CMultiObjectiveMotionOptimizerBase::Ptr Factory(const std::string &className) noexcept
Class factory from C++ class name.
A structure that holds runtime class type information.
std::vector< std::string > log_entries
Optionally, debug logging info will be stored here by the implementor classes.
void registerAllPendingClasses()
Register all pending classes - to be called just before de-serializing an object, for example.
std::shared_ptr< CMultiObjectiveMotionOptimizerBase > Ptr
std::vector< mrpt::expr::CRuntimeCompiledExpression > m_movement_assert_exprs
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
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.
TParamsBase & m_params_base
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...
IMPLEMENTS_VIRTUAL_MRPT_OBJECT(CMultiObjectiveMotionOptimizerBase, CObject, mrpt::nav) CMultiObjectiveMotionOptimizerBase
CMultiObjectiveMotionOptimizerBase(TParamsBase ¶ms)
This class allows loading and storing values and vectors of different types from a configuration text...
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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.
virtual 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.
virtual void clear()
Resets the object state; use if the parameters change, so they are re-read and applied.
std::vector< std::map< std::string, double > > score_values
For each candidate (vector indices), the numerical evaluation of all scores defined in TParamsBase::f...
virtual int impl_decide(const std::vector< mrpt::nav::TCandidateMovementPTG > &movs, TResultInfo &extra_info)=0
Virtual base class for multi-objective motion choosers, as used for reactive navigation engines.
mrpt::rtti::CObject * createObject() const
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...
int MRPT_SAVE_VALUE_PADDING()
std::vector< std::string > movement_assert
A list of exprtk expressions for conditions that any candidate movement must fulfill in order to get ...
std::map< std::string, double > m_expr_vars
GLsizei const GLchar ** string
std::map< std::string, mrpt::expr::CRuntimeCompiledExpression > m_score_exprs
score names -> score compiled expressions
virtual 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.
int MRPT_SAVE_NAME_PADDING()
Default padding sizes for macros MRPT_SAVE_CONFIG_VAR_COMMENT(), etc.
const TRuntimeClassId * findRegisteredClass(const std::string &className)
Return info about a given class by its name, or nullptr if the class is not registered.
GLenum const GLfloat * params
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |