2 #include "gtest/gtest.h" 4 #include <boost/concept_check.hpp> 18 namespace cost_functions
20 template <
typename MapData>
27 this->arcAcc = [
this](
const size_t& _i)
29 return this->latticePtr_->at(_i).arc;
53 enum class StateNmVars
61 enum class StateCfVars
70 enum class ParamFuncVars
77 enum class ParamFuncLattices
94 double stateArc()
const override 96 return stateCf_.value(
asInt(StateCfVars::T));
100 double stateDist()
const override 102 return stateCf_.value(
asInt(StateCfVars::S));
121 paramFuncs_.
setEvalArc(_arc, _evalArcGuarantee);
122 stateCf_.value(
asInt(StateCfVars::T)) = _arc;
124 stateCf_.value(
asInt(StateCfVars::W)) = paramFuncs_.computeFuncVal(
asInt(ParamFuncVars::W));
125 stateCf_.value(
asInt(StateCfVars::S)) = paramFuncs_.computeS();
129 State& stateNmDot()
override 131 stateNmDotCache_.
value(
asInt(StateNmVars::X)) =
133 stateNmDotCache_.value(
asInt(StateNmVars::Y)) =
135 stateNmDotCache_.value(
asInt(StateNmVars::THETA)) = stateCf_.value(
asInt(StateCfVars::W));
136 return stateNmDotCache_;
140 State& stateNmDelta(
const double& _dArc)
override 143 const double& w = stateCf_.value(
asInt(StateCfVars::W));
144 const double& theta = stateNm_.value(
asInt(StateNmVars::THETA));
145 double& dx = stateNmDotCache_.value(
asInt(StateNmVars::X));
146 double& dy = stateNmDotCache_.value(
asInt(StateNmVars::Y));
147 double& da = stateNmDotCache_.value(
asInt(StateNmVars::THETA));
149 if (fabs(w) > FLT_MIN)
151 const double r = v / w;
152 dx = (-r * sin(theta) + r * sin(theta + w * _dArc));
153 dy = (+r * cos(theta) - r * cos(theta + w * _dArc));
158 dx = v * _dArc * cos(theta);
159 dy = v * _dArc * sin(theta);
162 return stateNmDotCache_;
169 using SNF = StateSimTest::StateVars;
170 using SNV = StateSimTest::StateNmVars;
171 using SCF = StateSimTest::StateCfVars;
172 using PFV = StateSimTest::ParamFuncVars;
182 class TrajSimGradeTest :
public ::testing::Test
190 dummyMapData = shared_ptr<double>(
new double(0));
197 vector<PFS> pf(2, PFS());
198 static constexpr
const int paramFuncArcRefIdxAll = 0;
199 pf[0].ctrlPtsSize = 3;
200 pf[0].ctrlPtsArcRefIdx = paramFuncArcRefIdxAll;
201 pf[1].ctrlPtsSize = 3;
202 pf[1].ctrlPtsArcRefIdx = paramFuncArcRefIdxAll;
207 stateSimPtr = std::shared_ptr<StateSimTest>(
new StateSimTest);
208 stateSimPtr->paramFuncs()->init(pf);
212 ParamFuncs* funcs = stateSimPtr->paramFuncs();
230 virtual ~TrajSimGradeTest()
241 virtual void TearDown()
249 shared_ptr<double> dummyMapData;
252 template <
typename CostEvalType>
253 void multiCheckCostFunc(
const double& _dt,
const double& _ds, std::function<
double(
double,
double)> costExpFunc)
255 trajSimGrade = shared_ptr<TrajectorySimGrade>(
new TrajectorySimGrade(stateSimPtr, std::make_unique<CostEvalType>(dummyMapData)));
259 trajSimGrade->trajSim()->dtBase() = _dt;
260 trajSimGrade->evaluateTrajectory();
262 double sumEndAns, sumEndExp;
263 sumEndAns = trajSimGrade->trajSim()->costsEvaluator_->f;
264 sumEndExp = costExpFunc(_dt, _ds);
265 EXPECT_DOUBLE_EQ(sumEndExp, sumEndAns);
268 trajSimGrade->trajSim()->dtBase() = _dt;
269 trajSimGrade->evaluateTrajectory();
271 sumEndAns = trajSimGrade->trajSim()->costsEvaluator_->f;
272 sumEndExp = costExpFunc(_dt, _ds);
273 EXPECT_DOUBLE_EQ(sumEndExp, sumEndAns);
275 trajSimGrade->trajSim()->dtBase() = _dt;
276 trajSimGrade->trajSim()->dsBase() = _ds;
277 trajSimGrade->evaluateTrajectory();
279 sumEndAns = trajSimGrade->trajSim()->costsEvaluator_->f;
280 sumEndExp = costExpFunc(_dt, _ds);
281 EXPECT_DOUBLE_EQ(sumEndExp, sumEndAns);
284 trajSimGrade->trajSim()->dtBase() = _dt;
285 trajSimGrade->trajSim()->dsBase() = _ds;
286 trajSimGrade->evaluateTrajectory();
288 sumEndAns = trajSimGrade->trajSim()->costsEvaluator_->f;
289 sumEndExp = costExpFunc(_dt, _ds);
290 EXPECT_DOUBLE_EQ(sumEndExp, sumEndAns);
293 template <
typename CostEvalType>
294 void multiCheckCostFuncArray(
const double& _dt,
const double& _ds,
295 function<shared_ptr<vector<double>>(
double,
double)> costExpFunc)
297 trajSimGrade = shared_ptr<TrajectorySimGrade>(
new TrajectorySimGrade(stateSimPtr, std::make_unique<CostEvalType>(dummyMapData)));
301 trajSimGrade->trajSim()->dtBase() = _dt;
302 trajSimGrade->evaluateTrajectory();
304 shared_ptr<vector<double>> ans = shared_ptr<vector<double>>(
new vector<double>);
305 shared_ptr<vector<double>> exp;
306 ans->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
307 for (
size_t i = 0; i < ans->size(); ++i)
309 ans->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
311 exp = costExpFunc(_dt, _ds);
312 ASSERT_EQ(exp->size(), ans->size());
313 for (
size_t i = 0; i < ans->size(); ++i)
315 EXPECT_DOUBLE_EQ(exp->at(i), ans->at(i));
318 trajSimGrade->evaluateTrajectory(0.2);
319 ans->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
320 for (
size_t i = 0; i < ans->size(); ++i)
322 ans->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
324 exp = costExpFunc(_dt, _ds);
325 ASSERT_EQ(exp->size(), ans->size());
326 for (
size_t i = 0; i < ans->size(); ++i)
328 EXPECT_DOUBLE_EQ(exp->at(i), ans->at(i));
332 trajSimGrade->trajSim()->dtBase() = _dt;
333 trajSimGrade->evaluateTrajectory();
335 ans->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
336 for (
size_t i = 0; i < ans->size(); ++i)
338 ans->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
340 exp = costExpFunc(_dt, _ds);
341 ASSERT_EQ(exp->size(), ans->size());
342 for (
size_t i = 0; i < ans->size(); ++i)
344 EXPECT_DOUBLE_EQ(exp->at(i), ans->at(i));
347 trajSimGrade->trajSim()->dtBase() = _dt;
348 trajSimGrade->trajSim()->dsBase() = _ds;
349 trajSimGrade->evaluateTrajectory();
351 ans->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
352 for (
size_t i = 0; i < ans->size(); ++i)
354 ans->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
356 exp = costExpFunc(_dt, _ds);
357 ASSERT_EQ(exp->size(), ans->size());
358 for (
size_t i = 0; i < ans->size(); ++i)
360 EXPECT_DOUBLE_EQ(exp->at(i), ans->at(i));
364 trajSimGrade->trajSim()->dtBase() = _dt;
365 trajSimGrade->trajSim()->dsBase() = _ds;
366 trajSimGrade->evaluateTrajectory();
368 ans->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
369 for (
size_t i = 0; i < ans->size(); ++i)
371 ans->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
373 exp = costExpFunc(_dt, _ds);
374 ASSERT_EQ(exp->size(), ans->size());
375 for (
size_t i = 0; i < ans->size(); ++i)
377 EXPECT_DOUBLE_EQ(exp->at(i), ans->at(i));
381 template <
typename CostEvalType>
382 void multiCheckCostFuncArrayKnot(
const double& _dt,
const double& _ds,
bool checkEqCostsNr)
384 trajSimGrade = shared_ptr<TrajectorySimGrade>(
new TrajectorySimGrade(stateSimPtr, std::make_unique<CostEvalType>(dummyMapData)));
387 ParamFuncs* funcs = trajSimGrade->trajSim()->stateSim()->paramFuncs();
388 vector<vector<double*>> funcKnotsLattice(1, vector<double*>(funcs->
funcsArcSize(0), 0));
389 for (
size_t i = 0; i < funcKnotsLattice[0].size(); ++i)
391 funcKnotsLattice[0][i] = &funcs->
funcsArc(0, i);
393 trajSimGrade->trajSim()->setUserDefLattice(funcKnotsLattice);
397 trajSimGrade->trajSim()->dtBase() = _dt;
398 trajSimGrade->evaluateTrajectory();
399 trajSimGrade->trajSim()->dsBase() = -1;
400 shared_ptr<vector<double>> expPreEq = shared_ptr<vector<double>>(
new vector<double>);
401 expPreEq->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
402 for (
size_t i = 0; i < expPreEq->size(); ++i)
404 expPreEq->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
408 trajSimGrade->trajSim()->dtBase() = _dt / 10.;
409 trajSimGrade->trajSim()->dsBase() = _ds;
410 trajSimGrade->evaluateTrajectory();
411 shared_ptr<vector<double>> expPreSm = shared_ptr<vector<double>>(
new vector<double>);
412 expPreSm->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
413 for (
size_t i = 0; i < expPreSm->size(); ++i)
415 expPreSm->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
419 trajSimGrade->trajSim()->dtBase() = _dt * 10.;
420 trajSimGrade->trajSim()->dsBase() = -1;
421 trajSimGrade->evaluateTrajectory();
422 shared_ptr<vector<double>> expPreGr = shared_ptr<vector<double>>(
new vector<double>);
423 expPreGr->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
424 for (
size_t i = 0; i < expPreGr->size(); ++i)
426 expPreGr->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
432 shared_ptr<vector<double>> ansOnline = shared_ptr<vector<double>>(
new vector<double>);
434 for (
size_t i = 0; i < funcKnotsLattice[0].size(); ++i)
436 funcKnotsLattice[0][i] = &funcs->
funcsArc(0, i);
438 trajSimGrade->trajSim()->setUserDefLattice(funcKnotsLattice);
439 trajSimGrade->trajSim()->dtBase() = _dt;
440 trajSimGrade->trajSim()->dsBase() = -1;
441 trajSimGrade->evaluateTrajectory();
443 ansOnline->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
444 for (
size_t i = 0; i < ansOnline->size(); ++i)
446 ansOnline->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
450 ASSERT_EQ(expPreEq->size(), ansOnline->size());
452 for (
size_t i = 0; i < ansOnline->size(); ++i)
454 EXPECT_TRUE(ansOnline->at(i) >= 0);
455 EXPECT_DOUBLE_EQ(expPreEq->at(i), ansOnline->at(i));
458 for (
size_t i = 0; i < funcKnotsLattice[0].size(); ++i)
460 funcKnotsLattice[0][i] = &funcs->
funcsArc(0, i);
462 trajSimGrade->trajSim()->setUserDefLattice(funcKnotsLattice);
463 trajSimGrade->trajSim()->dtBase() = _dt / 10.;
464 trajSimGrade->trajSim()->dsBase() = _ds;
465 trajSimGrade->evaluateTrajectory();
467 ansOnline->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
468 for (
size_t i = 0; i < ansOnline->size(); ++i)
470 ansOnline->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
474 ASSERT_EQ(expPreSm->size(), ansOnline->size());
476 for (
size_t i = 0; i < ansOnline->size(); ++i)
478 EXPECT_TRUE(ansOnline->at(i) >= 0);
479 EXPECT_DOUBLE_EQ(expPreSm->at(i), ansOnline->at(i));
482 for (
size_t i = 0; i < funcKnotsLattice[0].size(); ++i)
484 funcKnotsLattice[0][i] = &funcs->
funcsArc(0, i);
486 trajSimGrade->trajSim()->setUserDefLattice(funcKnotsLattice);
487 trajSimGrade->trajSim()->dtBase() = _dt * 10;
488 trajSimGrade->trajSim()->dsBase() = -1;
489 trajSimGrade->evaluateTrajectory();
491 ansOnline->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
492 for (
size_t i = 0; i < ansOnline->size(); ++i)
494 ansOnline->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
498 ASSERT_EQ(expPreGr->size(), ansOnline->size());
500 for (
size_t i = 0; i < ansOnline->size(); ++i)
502 EXPECT_TRUE(ansOnline->at(i) >= 0);
503 EXPECT_DOUBLE_EQ(expPreGr->at(i), ansOnline->at(i));
506 for (
size_t i = 0; i < funcKnotsLattice[0].size(); ++i)
508 funcKnotsLattice[0][i] = &funcs->
funcsArc(0, i);
510 trajSimGrade->trajSim()->setUserDefLattice(funcKnotsLattice);
511 trajSimGrade->trajSim()->dtBase() = _dt / 10.;
512 trajSimGrade->trajSim()->dsBase() = _ds;
513 trajSimGrade->evaluateTrajectory();
515 ansOnline->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
516 for (
size_t i = 0; i < ansOnline->size(); ++i)
518 ansOnline->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
522 ASSERT_EQ(expPreEq->size(), ansOnline->size());
524 for (
size_t i = 0; i < ansOnline->size(); ++i)
526 EXPECT_TRUE(ansOnline->at(i) >= 0);
527 EXPECT_DOUBLE_EQ(expPreSm->at(i), ansOnline->at(i));
531 template <
typename CostEvalType>
532 void multiCheckCostFuncArrayKnotOnlyDt(
const double& _dt)
534 trajSimGrade = shared_ptr<TrajectorySimGrade>(
new TrajectorySimGrade(stateSimPtr, std::make_unique<CostEvalType>(dummyMapData)));
538 trajSimGrade->trajSim()->dtBase() = _dt;
539 trajSimGrade->evaluateTrajectory();
540 shared_ptr<vector<double>> expPreEq = shared_ptr<vector<double>>(
new vector<double>);
541 expPreEq->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
542 for (
size_t i = 0; i < expPreEq->size(); ++i)
544 expPreEq->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
548 trajSimGrade->trajSim()->dtBase() = _dt / 10.;
549 trajSimGrade->evaluateTrajectory();
550 shared_ptr<vector<double>> expPreSm = shared_ptr<vector<double>>(
new vector<double>);
551 expPreSm->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
552 for (
size_t i = 0; i < expPreSm->size(); ++i)
554 expPreSm->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
558 trajSimGrade->trajSim()->dtBase() = _dt * 10.;
559 trajSimGrade->evaluateTrajectory();
560 shared_ptr<vector<double>> expPreGr = shared_ptr<vector<double>>(
new vector<double>);
561 expPreGr->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
562 for (
size_t i = 0; i < expPreGr->size(); ++i)
564 expPreGr->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
570 shared_ptr<vector<double>> ansOnline = shared_ptr<vector<double>>(
new vector<double>);
572 trajSimGrade->trajSim()->dtBase() = _dt;
573 trajSimGrade->evaluateTrajectory();
575 ansOnline->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
576 for (
size_t i = 0; i < ansOnline->size(); ++i)
578 ansOnline->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
580 for (
size_t i = 0; i < ansOnline->size(); ++i)
582 EXPECT_TRUE(ansOnline->at(i) >= 0);
583 EXPECT_DOUBLE_EQ(expPreEq->at(i), ansOnline->at(i));
586 trajSimGrade->trajSim()->dtBase() = _dt / 10.;
587 trajSimGrade->evaluateTrajectory();
589 ansOnline->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
590 for (
size_t i = 0; i < ansOnline->size(); ++i)
592 ansOnline->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
594 for (
size_t i = 0; i < ansOnline->size(); ++i)
596 EXPECT_TRUE(ansOnline->at(i) >= 0);
597 EXPECT_DOUBLE_EQ(expPreSm->at(i), ansOnline->at(i));
600 trajSimGrade->trajSim()->dtBase() = _dt * 10;
601 trajSimGrade->evaluateTrajectory();
603 ansOnline->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
604 for (
size_t i = 0; i < ansOnline->size(); ++i)
606 ansOnline->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
608 for (
size_t i = 0; i < ansOnline->size(); ++i)
610 EXPECT_TRUE(ansOnline->at(i) >= 0);
611 EXPECT_DOUBLE_EQ(expPreGr->at(i), ansOnline->at(i));
614 trajSimGrade->trajSim()->dtBase() = _dt / 10.;
615 trajSimGrade->evaluateTrajectory();
617 ansOnline->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
618 for (
size_t i = 0; i < ansOnline->size(); ++i)
620 ansOnline->at(i) = trajSimGrade->trajSim()->costsEvaluator_->h[i];
622 for (
size_t i = 0; i < ansOnline->size(); ++i)
624 EXPECT_TRUE(ansOnline->at(i) >= 0);
625 EXPECT_DOUBLE_EQ(expPreSm->at(i), ansOnline->at(i));
633 using TSBSLT = TS::BaseSimLatticeType;
634 using TSLatVec = TS::LatticeVec;
636 using MapData = double;
645 stAcc = [
this](
const size_t& _i)
647 return latticePtr_->at(_i).statePtr->value(
asInt(SNF::T));
649 funcPredef_FL1::lin(
this);
650 funcPredef_FL2::sum(
this);
651 funcPredef_FL3::weight(
this);
661 TestCost_LinSumWNorm()
663 stAcc = [
this](
const size_t& _i)
665 return latticePtr_->at(_i).statePtr->value(
asInt(SNF::T));
667 funcPredef_FL1::lin(
this);
668 funcPredef_FL2::sum(
this);
669 funcPredef_FL3::weightNorm(
this);
678 TestCost_LinIntWNorm()
680 stAcc = [
this](
const size_t& _i)
682 return latticePtr_->at(_i).statePtr->value(
asInt(SNF::T));
684 funcPredef_FL1::lin(
this);
685 funcPredef_FL2::intTrap(
this);
686 funcPredef_FL3::weightNorm(
this);
693 class Test1CostArray_LinSumW :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumW>
695 size_t latFuncLayerIdx()
override 697 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
699 size_t latKnotLayerIdx()
override 701 return TS::lattTypeIdx(
asInt(TSBSLT::ARC_BG_BK));
704 class Test1CostArray_LinSumWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumWNorm>
706 size_t latFuncLayerIdx()
override 708 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
710 size_t latKnotLayerIdx()
override 712 return TS::lattTypeIdx(
asInt(TSBSLT::ARC_BG_BK));
715 class Test1CostArray_LinIntWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinIntWNorm>
717 size_t latFuncLayerIdx()
override 719 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
721 size_t latKnotLayerIdx()
override 723 return TS::lattTypeIdx(
asInt(TSBSLT::ARC_BG_BK));
727 class TestCostsEvaluatorT1C1 :
public CostsEvaluator<TSLatVec, MapData>
730 TestCostsEvaluatorT1C1(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
735 void loadCostFunctions()
override 741 class TestCostsEvaluatorT1C2 :
public CostsEvaluator<TSLatVec, MapData>
744 TestCostsEvaluatorT1C2(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
749 void loadCostFunctions()
override 755 class TestCostsEvaluatorT1C3 :
public CostsEvaluator<TSLatVec, MapData>
758 TestCostsEvaluatorT1C3(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
763 void loadCostFunctions()
override 770 TEST_F(TrajSimGradeTest, CostFuncsOnTOnT)
775 auto sumeEndExpFunc = [
this](
double dt,
double ds)
777 double sumEndExp = 0;
779 for (; i <= 1. / trajSimGrade->trajSim()->dt(); ++i)
781 sumEndExp += (double)i * dt;
788 multiCheckCostFunc<TestCostsEvaluatorT1C1>(dt, ds, sumeEndExpFunc);
791 multiCheckCostFunc<TestCostsEvaluatorT1C1>(dt, ds, sumeEndExpFunc);
794 multiCheckCostFunc<TestCostsEvaluatorT1C1>(dt, ds, sumeEndExpFunc);
797 multiCheckCostFunc<TestCostsEvaluatorT1C1>(dt, ds, sumeEndExpFunc);
801 auto sumeEndExpFunc = [
this](
double dt,
double ds)
803 double sumEndExp = 0;
805 for (; i <= 1. / trajSimGrade->trajSim()->dt(); ++i)
807 sumEndExp += (double)i * dt;
809 return sumEndExp / ((double)--i * dt);
814 multiCheckCostFunc<TestCostsEvaluatorT1C2>(dt, ds, sumeEndExpFunc);
817 multiCheckCostFunc<TestCostsEvaluatorT1C2>(dt, ds, sumeEndExpFunc);
820 multiCheckCostFunc<TestCostsEvaluatorT1C2>(dt, ds, sumeEndExpFunc);
823 multiCheckCostFunc<TestCostsEvaluatorT1C2>(dt, ds, sumeEndExpFunc);
827 auto sumeEndExpFunc = [
this](
double dt,
double ds)
829 double sumEndExp = 0;
831 for (; i <= 1. / trajSimGrade->trajSim()->dt(); ++i)
833 sumEndExp += 0.5 * dt * ((i + i - 1) * dt);
835 return sumEndExp / ((double)--i * dt);
840 multiCheckCostFunc<TestCostsEvaluatorT1C3>(dt, ds, sumeEndExpFunc);
843 multiCheckCostFunc<TestCostsEvaluatorT1C3>(dt, ds, sumeEndExpFunc);
846 multiCheckCostFunc<TestCostsEvaluatorT1C3>(dt, ds, sumeEndExpFunc);
849 multiCheckCostFunc<TestCostsEvaluatorT1C3>(dt, ds, sumeEndExpFunc);
853 class Test2CostArray_LinSumW :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumW>
855 size_t latFuncLayerIdx()
override 857 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
859 size_t latKnotLayerIdx()
override 861 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
864 class Test2CostArray_LinSumWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumWNorm>
866 size_t latFuncLayerIdx()
override 868 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
870 size_t latKnotLayerIdx()
override 872 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
875 class Test2CostArray_LinIntWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinIntWNorm>
877 size_t latFuncLayerIdx()
override 879 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
881 size_t latKnotLayerIdx()
override 883 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
887 class TestCostsEvaluatorT2C1 :
public CostsEvaluator<TSLatVec, MapData>
890 TestCostsEvaluatorT2C1(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
895 void loadCostFunctions()
override 901 class TestCostsEvaluatorT2C2 :
public CostsEvaluator<TSLatVec, MapData>
904 TestCostsEvaluatorT2C2(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
909 void loadCostFunctions()
override 915 class TestCostsEvaluatorT2C3 :
public CostsEvaluator<TSLatVec, MapData>
918 TestCostsEvaluatorT2C3(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
923 void loadCostFunctions()
override 930 TEST_F(TrajSimGradeTest, CostFuncsArrayOnTOnTLat)
935 auto sumeEndExpFunc = [
this](
double dt,
double ds)
937 shared_ptr<vector<double>> costsExp =
938 shared_ptr<vector<double>>(
new vector<double>(trajSimGrade->trajSim()->stateSim()->paramFuncs()->funcsArcEnd() / (double)dt));
939 for (
size_t i = 1; i <= 1. / trajSimGrade->trajSim()->dt(); ++i)
941 costsExp->at(i - 1) = (double)i * dt;
948 multiCheckCostFuncArray<TestCostsEvaluatorT2C1>(dt, ds, sumeEndExpFunc);
951 multiCheckCostFuncArray<TestCostsEvaluatorT2C1>(dt, ds, sumeEndExpFunc);
954 multiCheckCostFuncArray<TestCostsEvaluatorT2C1>(dt, ds, sumeEndExpFunc);
957 multiCheckCostFuncArray<TestCostsEvaluatorT2C1>(dt, ds, sumeEndExpFunc);
961 auto sumeEndExpFunc = [
this](
double dt,
double ds)
963 shared_ptr<vector<double>> costsExp =
964 shared_ptr<vector<double>>(
new vector<double>(trajSimGrade->trajSim()->stateSim()->paramFuncs()->funcsArcEnd() / (double)dt));
965 for (
size_t i = 1; i <= 1. / trajSimGrade->trajSim()->dt(); ++i)
967 costsExp->at(i - 1) = (double)i * dt / (i * dt - (i - 1) * dt);
974 multiCheckCostFuncArray<TestCostsEvaluatorT2C2>(dt, ds, sumeEndExpFunc);
977 multiCheckCostFuncArray<TestCostsEvaluatorT2C2>(dt, ds, sumeEndExpFunc);
980 multiCheckCostFuncArray<TestCostsEvaluatorT2C2>(dt, ds, sumeEndExpFunc);
983 multiCheckCostFuncArray<TestCostsEvaluatorT2C2>(dt, ds, sumeEndExpFunc);
987 auto sumeEndExpFunc = [
this](
double dt,
double ds)
989 shared_ptr<vector<double>> costsExp =
990 shared_ptr<vector<double>>(
new vector<double>(trajSimGrade->trajSim()->stateSim()->paramFuncs()->funcsArcEnd() / (double)dt));
991 for (
size_t i = 1; i <= 1. / trajSimGrade->trajSim()->dt(); ++i)
994 costsExp->at(i - 1) = (ii * dt - (ii - 1) * dt) * (ii * dt + (ii - 1) * dt) / (ii * dt - (ii - 1) * dt) / 2.;
1001 multiCheckCostFuncArray<TestCostsEvaluatorT2C3>(dt, ds, sumeEndExpFunc);
1004 multiCheckCostFuncArray<TestCostsEvaluatorT2C3>(dt, ds, sumeEndExpFunc);
1007 multiCheckCostFuncArray<TestCostsEvaluatorT2C3>(dt, ds, sumeEndExpFunc);
1010 multiCheckCostFuncArray<TestCostsEvaluatorT2C3>(dt, ds, sumeEndExpFunc);
1014 class Test3CostArray_LinSumW :
public Test2CostArray_LinSumW
1016 size_t latKnotLayerIdx()
override 1018 return TS::lattTypeIdx(0);
1021 class Test3CostArray_LinSumWNorm :
public Test2CostArray_LinSumWNorm
1023 size_t latKnotLayerIdx()
override 1025 return TS::lattTypeIdx(0);
1028 class Test3CostArray_LinIntWNorm :
public Test2CostArray_LinIntWNorm
1030 size_t latKnotLayerIdx()
override 1032 return TS::lattTypeIdx(0);
1036 class TestCostsEvaluatorT3C1 :
public CostsEvaluator<TSLatVec, MapData>
1039 TestCostsEvaluatorT3C1(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1044 void loadCostFunctions()
override 1050 class TestCostsEvaluatorT3C2 :
public CostsEvaluator<TSLatVec, MapData>
1053 TestCostsEvaluatorT3C2(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1058 void loadCostFunctions()
override 1064 class TestCostsEvaluatorT3C3 :
public CostsEvaluator<TSLatVec, MapData>
1067 TestCostsEvaluatorT3C3(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1072 void loadCostFunctions()
override 1079 TEST_F(TrajSimGradeTest, CostFuncsArrayOnTOnTLatFuncKnots)
1085 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT3C1>(dt, ds,
true);
1088 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT3C1>(dt, ds,
true);
1091 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT3C1>(dt, ds,
true);
1095 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT3C2>(dt, ds,
true);
1098 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT3C2>(dt, ds,
true);
1101 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT3C2>(dt, ds,
true);
1105 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT3C3>(dt, ds,
true);
1108 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT3C3>(dt, ds,
true);
1111 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT3C3>(dt, ds,
true);
1114 class TestCost_LinSumW_onX :
public TestCost_LinSumW
1117 TestCost_LinSumW_onX() : TestCost_LinSumW()
1119 stAcc = [
this](
const size_t& _i)
1121 return latticePtr_->at(_i).statePtr->value(
asInt(SNF::X));
1125 class TestCost_LinSumWNorm_onX :
public TestCost_LinSumWNorm
1128 TestCost_LinSumWNorm_onX() : TestCost_LinSumWNorm()
1130 stAcc = [
this](
const size_t& _i)
1132 return latticePtr_->at(_i).statePtr->value(
asInt(SNF::X));
1136 class TestCost_LinIntWNorm_onX :
public TestCost_LinIntWNorm
1139 TestCost_LinIntWNorm_onX() : TestCost_LinIntWNorm()
1141 stAcc = [
this](
const size_t& _i)
1143 return latticePtr_->at(_i).statePtr->value(
asInt(SNF::X));
1148 class Test4CostArray_LinSumW :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumW_onX>
1150 size_t latFuncLayerIdx()
override 1152 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1154 size_t latKnotLayerIdx()
override 1156 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1159 class Test4CostArray_LinSumWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumWNorm_onX>
1161 size_t latFuncLayerIdx()
override 1163 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1165 size_t latKnotLayerIdx()
override 1167 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1170 class Test4CostArray_LinIntWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinIntWNorm_onX>
1172 size_t latFuncLayerIdx()
override 1174 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1176 size_t latKnotLayerIdx()
override 1178 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1182 class TestCostsEvaluatorT4C1 :
public CostsEvaluator<TSLatVec, MapData>
1185 TestCostsEvaluatorT4C1(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1190 void loadCostFunctions()
override 1196 class TestCostsEvaluatorT4C2 :
public CostsEvaluator<TSLatVec, MapData>
1199 TestCostsEvaluatorT4C2(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1204 void loadCostFunctions()
override 1210 class TestCostsEvaluatorT4C3 :
public CostsEvaluator<TSLatVec, MapData>
1213 TestCostsEvaluatorT4C3(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1218 void loadCostFunctions()
override 1225 TEST_F(TrajSimGradeTest, CostFuncsArrayOnTOnTLatFuncKnotsOnlineInterrupt)
1231 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT4C1>(dt, ds,
false);
1234 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT4C1>(dt, ds,
false);
1237 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT4C1>(dt, ds,
false);
1241 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT4C2>(dt, ds,
false);
1244 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT4C2>(dt, ds,
false);
1247 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT4C2>(dt, ds,
false);
1251 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT4C3>(dt, ds,
false);
1254 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT4C3>(dt, ds,
false);
1257 multiCheckCostFuncArrayKnot<TestCostsEvaluatorT4C3>(dt, ds,
false);
1260 TEST_F(TrajSimGradeTest, CostFuncsArrayOnTOnTLatFuncKnotsOnlineInterruptOnlyT)
1265 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT4C1>(dt);
1267 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT4C1>(dt);
1270 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT4C2>(dt);
1272 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT4C2>(dt);
1275 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT4C3>(dt);
1277 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT4C3>(dt);
1280 class Test6CostArray_LinSumW :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumW_onX>
1282 size_t latFuncLayerIdx()
override 1284 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1286 size_t latKnotLayerIdx()
override 1288 return TS::lattTypeIdx(
asInt(TSBSLT::ARC_BG_BK));
1291 class Test6CostArray_LinSumWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumWNorm_onX>
1293 size_t latFuncLayerIdx()
override 1295 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1297 size_t latKnotLayerIdx()
override 1299 return TS::lattTypeIdx(
asInt(TSBSLT::ARC_BG_BK));
1302 class Test6CostArray_LinIntWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinIntWNorm_onX>
1304 size_t latFuncLayerIdx()
override 1306 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1308 size_t latKnotLayerIdx()
override 1310 return TS::lattTypeIdx(
asInt(TSBSLT::ARC_BG_BK));
1314 class TestCostsEvaluatorT6C1 :
public CostsEvaluator<TSLatVec, MapData>
1317 TestCostsEvaluatorT6C1(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1322 void loadCostFunctions()
override 1328 class TestCostsEvaluatorT6C2 :
public CostsEvaluator<TSLatVec, MapData>
1331 TestCostsEvaluatorT6C2(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1336 void loadCostFunctions()
override 1342 class TestCostsEvaluatorT6C3 :
public CostsEvaluator<TSLatVec, MapData>
1345 TestCostsEvaluatorT6C3(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1350 void loadCostFunctions()
override 1357 TEST_F(TrajSimGradeTest, CostFuncsArrayOnTOnTLatFuncKnotsOnlineInterruptOnlyTSmallerKnots)
1362 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT6C1>(dt);
1364 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT6C1>(dt);
1367 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT6C2>(dt);
1369 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT6C2>(dt);
1372 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT6C3>(dt);
1374 multiCheckCostFuncArrayKnotOnlyDt<TestCostsEvaluatorT6C3>(dt);
1377 class Test7CostArray_LinSumW :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumW_onX>
1379 size_t latFuncLayerIdx()
override 1381 return TS::lattTypeIdx(
asInt(TSBSLT::ARC_BG_BK));
1383 size_t latKnotLayerIdx()
override 1385 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1388 class Test7CostArray_LinSumWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinSumWNorm_onX>
1390 size_t latFuncLayerIdx()
override 1392 return TS::lattTypeIdx(
asInt(TSBSLT::ARC_BG_BK));
1394 size_t latKnotLayerIdx()
override 1396 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1399 class Test7CostArray_LinIntWNorm :
public CostsArrayLat<TSLatVec, MapData, TestCost_LinIntWNorm_onX>
1401 size_t latFuncLayerIdx()
override 1403 return TS::lattTypeIdx(
asInt(TSBSLT::ARC_BG_BK));
1405 size_t latKnotLayerIdx()
override 1407 return TS::lattTypeIdx(
asInt(TSBSLT::LATTICE_ARC_EQ_DT));
1411 class TestCostsEvaluatorT7C1 :
public CostsEvaluator<TSLatVec, MapData>
1414 TestCostsEvaluatorT7C1(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1419 void loadCostFunctions()
override 1425 class TestCostsEvaluatorT7C2 :
public CostsEvaluator<TSLatVec, MapData>
1428 TestCostsEvaluatorT7C2(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1433 void loadCostFunctions()
override 1439 class TestCostsEvaluatorT7C3 :
public CostsEvaluator<TSLatVec, MapData>
1442 TestCostsEvaluatorT7C3(std::shared_ptr<MapData>& _mapDataPtr) :
CostsEvaluator(_mapDataPtr)
1447 void loadCostFunctions()
override 1454 TEST_F(TrajSimGradeTest, CostFuncsArrayOnTOnBELatPrecalc)
1456 trajSimGrade = shared_ptr<TrajectorySimGrade>(
new TrajectorySimGrade(stateSimPtr, std::make_unique<TestCostsEvaluatorT7C1>(dummyMapData)));
1460 trajSimGrade->trajSim()->dtBase() = 0.1;
1461 trajSimGrade->evaluateTrajectory();
1462 shared_ptr<vector<double>> expPreEq = shared_ptr<vector<double>>(
new vector<double>);
1463 expPreEq->resize(trajSimGrade->trajSim()->costsEvaluator_->h.size());
1464 for (
size_t i = 0; i < expPreEq->size(); ++i)
1466 expPreEq->at(i) = trajSimGrade->trajSim()->costsEvaluator_->
h[i];
1477 ::testing::InitGoogleTest(&argc, argv);
1478 return RUN_ALL_TESTS();
double & funcsArc(const std::size_t &_i, const std::size_t &_j)
Access to the arc parameter vector at index _i, control point _j.
int main(int argc, char **argv)
previous evaluation arc <= this evaluation arc
virtual double & value(const std::size_t &_i)=0
Access state variable based on index _i.
std::unique_ptr< StateSim > StateSimUPtr
control point arc parameter
Helper function needed to upgrade c++ 2011.
constexpr auto asInt(Enumeration const value) -> typename std::underlying_type< Enumeration >::type
Templated partial implementation of StateSim.
EvalArcGuarantee
Flags if any guarantees about evaluation arc relative to last evaluation arc are present.
agent base center linear velocity is parametric function
Containts parametric function initialization data.
Generic tree-like recursive structure that allows sub-structure access as well as ordered (array-like...
double & ctrlPtVal(const std::size_t &_funcIdx, const std::size_t &_funcCtrlPtIdx, const CtrlPtDim &_ctrlPtDim=CtrlPtDim::VAL)
Access of a parametric function control point dimension.
std::shared_ptr< TrajectorySimGrade > TrajectorySimGradeSPtr
CtrlPtDim
Control point variable dimension.
Extends manipulation of parametric functions collection with closed-form arc length (distance) comput...
FuncEvalMode
Required type of computation relative to the parametric function.
std::size_t funcsArcSize() const
Number of arc parametrizations.
std::shared_ptr< StateSim > StateSimPtr
virtual void precompute()=0
Precomputes cached data.
agent base center linear velocity is parametric function
virtual void setEvalArc(const double &_funcsArcEval, const EvalArcGuarantee &_evalArcGuarantee=EvalArcGuarantee::NONE)=0
Sets parametric function evaluation arc.
Storage and manipulation of parametric functions collection.