state_sim_base.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by Horatiu George Todoran <todorangrg@gmail.com> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
33 #ifndef STATE_SIM_BASE_HPP
34 #define STATE_SIM_BASE_HPP
35 
38 #include <eigen3/Eigen/Eigen>
39 
40 namespace tuw
41 {
42 namespace /*<anonymous>*/
43 {
44 using PfEaG = EvalArcGuarantee;
45 
46 template <class TDerived>
47 struct StateMapBaseTraits;
48 template <class TDerived>
49 struct StateMapBaseTraits
50 {
51 public:
52  using StateType = typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::StateType;
53 
54 public:
55  using StateForSimType = typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::StateForSimType;
56 
57 public:
58  using NumType = typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::NumType;
59 
60 public:
61  using StateCfType = typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::StateCfType;
62 
63 public:
64  using StateNmType = typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::StateNmType;
65 
66 public:
67  using StateVirtType = typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::StateVirtType;
68 
69 public:
70  using StateNmNumType = typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::StateNmNumType;
71 
72 public:
73  using StateWithGradNmType = typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::StateWithGradNmType;
74 
75 public:
76  using StateWithGradCfType = typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::StateWithGradCfType;
77 
78 public:
79  using StateWithGradNmNumType =
80  typename StateMapBaseTraits<typename TDerived::StateMapBaseType>::StateWithGradNmNumType;
81 };
82 
83 template <class TDerived>
84 struct StateSimBaseCRTPTraits;
85 
86 class EmptyGradType
87 {
88 };
89 
90 } // namespace <anonymous>
91 
92 template <class TDerived>
94 {
95 public:
96  using StateType = typename StateSimBaseCRTPTraits<TDerived>::StateType;
97 
98 public:
99  using StateForSimType = typename StateSimBaseCRTPTraits<TDerived>::StateForSimType;
100 
101 private:
102  using NumType = typename StateSimBaseCRTPTraits<TDerived>::NumType;
103 
104 private:
105  using StateNmType = typename StateSimBaseCRTPTraits<TDerived>::StateNmType;
106 
107 public:
108  static constexpr const bool hasStateGrad =
109  !std::is_same<EmptyGradType, typename StateSimBaseCRTPTraits<TDerived>::StateWithGradNmType>::value;
110 
111 public:
112  StateSimBaseCRTP() = default;
113 
114 public:
115  ~StateSimBaseCRTP() = default;
116 
117 public:
118  StateSimBaseCRTP(const StateSimBaseCRTP&) = default;
119 
120 public:
121  StateSimBaseCRTP& operator=(const StateSimBaseCRTP&) = default;
122 
123 public:
124  StateSimBaseCRTP(StateSimBaseCRTP&&) = default;
125 
126 public:
127  StateSimBaseCRTP& operator=(StateSimBaseCRTP&&) = default;
128 
129 public:
130  template <bool stateGradientRepresentation = hasStateGrad,
131  typename std::enable_if<(stateGradientRepresentation)>::type* = nullptr>
132  void advanceWithGrad(const NumType& _arc)
133  {
134  thisDerived().advanceWithGradImplCRTP(_arc);
135  }
136 
137 public:
138  void advance(const NumType& _arc)
139  {
140  thisDerived().advanceImplCRTP(_arc);
141  }
142 
143 public:
144  void simToT(const NumType& _arcEnd, const NumType& _dt)
145  {
146  thisDerived().simToTImplCRTP(_arcEnd, _dt);
147  }
148 
149 public:
150  void toState0()
151  {
152  thisDerived().toState0ImplCRTP();
153  }
154  // public : StateForSimType& state0 () { return thisDerived().state0ImplCRTP (); }
155  // public : const StateForSimType& state0 ()
156  // const { return thisDerived().state0ImplCRTP (); }
157 public:
159  {
160  return thisDerived().stateImplCRTP();
161  }
162 
163 public:
164  const StateForSimType& state() const
165  {
166  return thisDerived().stateImplCRTP();
167  }
168 
169 public:
170  void advanceSet0(auto& _state0, const NumType& _tEnd, const NumType& _dt)
171  {
172  thisDerived().advanceSet0ImplCRTP(_state0, _tEnd, _dt);
173  }
174 
175 private:
176  TDerived& thisDerived()
177  {
178  return static_cast<TDerived&>(*this);
179  }
180 
181 private:
182  const TDerived& thisDerived() const
183  {
184  return static_cast<const TDerived&>(*this);
185  }
186 };
187 
188 template <class TNumType, class StateVirtType>
190 {
191  // special class member functions
192 public:
193  StateSimBaseVirt() = default;
194 
195 public:
196  ~StateSimBaseVirt() = default;
197 
198 public:
199  StateSimBaseVirt(const StateSimBaseVirt&) = default;
200 
201 public:
202  StateSimBaseVirt& operator=(const StateSimBaseVirt&) = default;
203 
204 public:
205  StateSimBaseVirt(StateSimBaseVirt&&) = default;
206 
207 public:
208  StateSimBaseVirt& operator=(StateSimBaseVirt&&) = default;
209 
210 public:
211  void advance(const TNumType& _arc)
212  {
213  advanceImplVirt(_arc);
214  }
215 
216 public:
217  void advanceWithGrad(const TNumType& _arc)
218  {
219  advanceWithGradImplVirt(_arc);
220  }
221 
222 public:
223  void toState0()
224  {
225  toState0ImplVirt();
226  }
227 
228 public:
229  void toState()
230  {
231  toState0ImplVirt();
232  }
233 
234  // pure virtual functions
235 private:
236  virtual void advanceImplVirt(const TNumType& _arc) = 0;
237 
238 private:
239  virtual void advanceWithGradImplVirt(const TNumType& _arc) = 0;
240 
241 private:
242  virtual void toState0ImplVirt() = 0;
243 };
244 
245 template <class NumType, class StateWithGradNmNumType, template <class> class TDiscretizationType>
247 {
248  // private : using OdeStateGradSolverRKType = explicit_generic_rk_impl< TDiscretizationType,
249  // StateWithGradNmNumType,
250  // NumType,
251  // StateWithGradNmNumType,
252  // NumType,
253  // odeint::vector_space_algebra >;
254  // private : using OdeStateGradSolverType = explicit_adams_bashforth<5, OdeStateGradSolverRKType>;
255 private:
256  using OdeStateGradSolverType =
257  explicit_generic_rk_impl<TDiscretizationType, StateWithGradNmNumType, NumType, StateWithGradNmNumType, NumType,
258  odeint::vector_space_algebra>;
259 
260 private:
262 
263  template <class TDerived2, class TParamType2, class TStateType2, template <class> class TDiscretizationType2,
264  class... TFuncsType2>
265  friend class StateSimBase;
266 };
267 
269 {
270  using OdeStateGradSolverType = EmptyGradType;
271 
272  template <class TDerived2, class TParamType2, class TStateType2, template <class> class TDiscretizationType2,
273  class... TFuncsType2>
274  friend class StateSimBase;
275 };
276 
277 template <class TDerived, class TParamType, class TStateType, template <class> class TDiscretizationType,
278  class... TFuncsType>
280  : public StateSimBaseCRTP<StateSimBase<TDerived, TParamType, TStateType, TDiscretizationType, TFuncsType...>>,
281  public StateSimBaseVirt<typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::NumType,
282  typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateVirtType>,
283  public std::conditional<
284  !std::is_same<EmptyGradType,
285  typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateWithGradNmType>::value,
286  OdeStateSolverRealAlias<
287  typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::NumType,
288  typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateWithGradNmNumType,
289  TDiscretizationType>,
290  OdeStateSolverDummyAlias>::type
291 {
292 public:
293  using StateType = TStateType;
294 
295 public:
296  using StateForSimType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateForSimType;
297 
298 public:
299  using ParamStructType = TParamType;
300 
301 private:
302  using StateSimBaseType = StateSimBase<TDerived, TParamType, TStateType, TDiscretizationType, TFuncsType...>;
303 
304 private:
305  using NumType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::NumType;
306 
307 private:
308  using StateVirtType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateVirtType;
309 
310 private:
311  using StateNmType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateNmType;
312 
313 private:
314  using StateCfType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateCfType;
315 
316 private:
317  using StateNmNumType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateNmNumType;
318 
319 private:
320  using StateWithGradNmType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateWithGradNmType;
321 
322 private:
323  using StateWithGradCfType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateWithGradCfType;
324 
325 private:
326  using StateWithGradNmNumType =
327  typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateWithGradNmNumType;
328 
329 private:
330  using OdeStateSolverType /*OdeStateSolverRKType*/ =
331  explicit_generic_rk_impl<TDiscretizationType, StateNmNumType, NumType, StateNmNumType, NumType,
332  odeint::vector_space_algebra>;
333  // private : using OdeStateSolverType = explicit_adams_bashforth<5, OdeStateSolverRKType>;
334 public:
335  static constexpr const bool hasStateGrad = !std::is_same<EmptyGradType, StateWithGradNmType>::value;
336 
337 public:
338  using StateNumSimType = typename std::conditional<hasStateGrad, StateWithGradNmType, StateNmType>::type;
339 
340  // special class member functions
341 public:
342  StateSimBase() = default;
343 
344 public:
345  ~StateSimBase() = default;
346 
347 public:
348  StateSimBase(const StateSimBase&) = default;
349 
350 public:
351  StateSimBase& operator=(const StateSimBase&) = default;
352 
353 public:
354  StateSimBase(StateSimBase&&) = delete;
355 
356 public:
357  StateSimBase& operator=(StateSimBase&&) = delete;
358 
359 public:
361 
362 public:
364 
365 public:
367 
368 public:
370 
371 public:
373 
374 private:
375  void advanceImplVirt(const NumType& _arc) override final
376  {
377  advanceImplCRTP(_arc);
378  }
379 
380 private:
381  void advanceWithGradImplVirt(const NumType& _arc) override final
382  {
383  advanceWithGradImplVirtDispatch(_arc);
384  }
385 
386 private:
387  void toState0ImplVirt() override final
388  {
389  toState0ImplCRTP();
390  }
391 
392 private:
393  template <bool stateGradientRepresentation = hasStateGrad,
394  typename std::enable_if<(stateGradientRepresentation)>::type* = nullptr>
395  void advanceWithGradImplVirtDispatch(const NumType& _arc)
396  {
397  advanceWithGradImplCRTP(_arc);
398  }
399 
400 private:
401  template <bool stateGradientRepresentation = hasStateGrad,
402  typename std::enable_if<(!stateGradientRepresentation)>::type* = nullptr>
403  void advanceWithGradImplVirtDispatch(const NumType& _arc)
404  {
405  throw std::runtime_error("Cannot advance with gradient info (State class not suited)");
406  }
407 
408 private:
410  {
411  return state_;
412  }
413 
414 private:
416  {
417  return state_;
418  }
419 
420 private:
421  void advanceImplCRTP(const NumType& _arc)
422  {
423  rk_.do_step(
424  [this](const StateNmNumType& _x, StateNmNumType& _dxdt, const NumType _t)
425  {
426  static NumType* memStartRefNm;
427  memStartRefNm = state_.stateNm().memStartRef();
428  state_.stateNm().bindToMemory((NumType*)_x.data());
430 
431  _dxdt = stateWithGradNmDotCache_.state().data();
432  state_.stateNm().bindToMemory(memStartRefNm);
433  },
434  state_.stateNm().data(), arcOld_, _arc - arcOld_);
435  arcOld_ = _arc;
436  }
437 
438 private:
439  template <bool stateGradientRepresentation = hasStateGrad,
440  typename std::enable_if<(stateGradientRepresentation)>::type* = nullptr>
441  void advanceWithGradImplCRTP(const NumType& _arc)
442  {
443  this->rkGrad_.do_step(
444  [this](const StateWithGradNmNumType& _x, StateWithGradNmNumType& _dxdt, const NumType _t)
445  {
446  static NumType* memStartRefNm;
447  memStartRefNm = state_.stateWithGradNm().memStartRef();
448  state_.stateWithGradNm().bindToMemory((NumType*)_x.data());
450  setGradXNmDot(_t, PfEaG::NEAR_LAST);
451 
452  _dxdt = stateWithGradNmDotCache_.data();
453  state_.stateWithGradNm().bindToMemory(memStartRefNm);
454  },
455  state_.stateWithGradNm().data(), arcOld_, _arc - arcOld_);
456  arcOld_ = _arc;
457  }
458 
459 private:
460  template <bool stateGradientRepresentation = hasStateGrad,
461  typename std::enable_if<(!stateGradientRepresentation)>::type* = nullptr>
463  {
464  adjustXSize();
465 
466  for_each_tuple(funcs_, [this](auto& funcI)
467  {
468  funcI.precompute(*this);
469  });
470 
471  setXNm0();
472  stateWithGradNmDotCache_ = state_.stateNm();
473 
474  setXCf(0, PfEaG::AT_BEGIN);
476  arcOld_ = 0;
477 
478  rk_.adjust_size(state_.stateNm().data().size());
479  // rk_.reset();
480  }
481 
482 private:
483  template <bool stateGradientRepresentation = hasStateGrad,
484  typename std::enable_if<(stateGradientRepresentation)>::type* = nullptr>
486  {
487  adjustXSize();
488  adjustGradXSize();
489 
490  for_each_tuple(funcs_, [this](auto& funcI)
491  {
492  funcI.precompute(*this);
493  });
494 
495  setXNm0();
496  setGradXNm0();
497  stateWithGradNmDotCache_ = state_.stateWithGradNm();
498 
499  setXCf(0, PfEaG::AT_BEGIN);
500  setGradXCf(0, PfEaG::AT_BEGIN);
502  setGradXNmDot(0, PfEaG::AT_BEGIN);
503  arcOld_ = 0;
504 
505  rk_.adjust_size(state_.stateNm().data().size());
506  this->rkGrad_.adjust_size(state_.stateWithGradNm().data().size());
507  // rk_.reset();
508  // this->rkGrad_.reset();
509  }
510 
511 private:
512  void simToTImplCRTP(const NumType& _tEnd, const NumType& _dt)
513  {
514  toState0();
515  NumType tSim = _dt;
516  while (tSim < _tEnd)
517  {
518  advance(tSim);
519  tSim += _dt;
520  }
521  advance(_tEnd);
522  }
523 
524 private:
525  void advanceSet0ImplCRTP(auto& _state0, const NumType& _tEnd, const NumType& _dt)
526  {
527  simToTImplCRTP(_tEnd, _dt);
528  _state0.stateNm().data() = state_.stateNm().data();
529  _state0.stateCf().data() = state_.stateCf().data();
530  }
531 
532  // no guarantee on when it is called; for caching, parts of XCf might have been set by setXNmDot
533 public:
534  void setXCf(const NumType& _arc, const PfEaG& _eAG)
535  {
536  thisSimDerived().setXCfImpl(state_.stateCf(), _arc, _eAG);
537  }
538  // guaranteed to be called after setXCf
539 public:
540  void setXCfDot(const NumType& _arc, const PfEaG& _eAG)
541  {
542  thisSimDerived().setXCfDotImpl(stateCfDotCache_, state_.stateCf(), _arc, _eAG);
543  }
544  // no guarantee on when it is called; for caching, parts of XCf can be precalculated
545 public:
546  void setXNmDot(const NumType& _arc, const PfEaG& _eAG)
547  {
548  thisSimDerived().setXNmDotImpl(stateWithGradNmDotCache_.state(), state_.stateCf(), state_.stateNm(), _arc, _eAG);
549  for_each_tuple(funcs_, [this, &_arc](auto& funcI)
550  {
551  funcI.computeFuncDot(stateWithGradNmDotCache_.state(), state_.stateNm(), state_.stateCf(), *this,
552  _arc, PfEaG::NEAR_LAST);
553  });
554  }
555  // guaranteed to be called after setXCf; for caching, parts of gradXCf might have been set by setGradXNmDot
556 public:
557  template <bool stateGradientRepresentation = hasStateGrad,
558  typename std::enable_if<(stateGradientRepresentation)>::type* = nullptr>
559  void setGradXCf(const NumType& _arc, const PfEaG& _eAG)
560  {
561  thisSimDerived().setGradXCfImpl(state_.stateGradCf(), state_.stateCf(), _arc, _eAG);
562  }
563  // no guarantee on when it is called; for caching, parts of GradXCf can be precalculated
564 public:
565  template <bool stateGradientRepresentation = hasStateGrad,
566  typename std::enable_if<(stateGradientRepresentation)>::type* = nullptr>
567  void setGradXNmDot(const NumType& _arc, const PfEaG& _eAG)
568  {
569  thisSimDerived().setGradXNmDotImpl(stateWithGradNmDotCache_.stateGrad(), state_.stateWithGradCf(),
570  state_.stateWithGradNm(), _arc, _eAG);
571  for_each_tuple(funcs_, [this, &_arc](auto& funcI)
572  {
573  funcI.computeGradFuncDot(stateWithGradNmDotCache_.stateGrad(), state_.stateWithGradNm(),
574  state_.stateWithGradCf(), *this, _arc, PfEaG::NEAR_LAST);
575  });
576  }
577 
578 public:
579  void init(std::shared_ptr<TParamType> _paramStructPtr)
580  {
581  paramStruct = _paramStructPtr;
582  }
583 
584 private:
585  TDerived& thisSimDerived()
586  {
587  return static_cast<TDerived&>(*this);
588  }
589 
590 private:
591  const TDerived& thisSimDerived() const
592  {
593  return static_cast<const TDerived&>(*this);
594  }
595 
596 public:
598  {
599  return stateWithGradNmDotCache_.state();
600  }
601 
602 public:
604  {
605  return stateCfDotCache_;
606  }
607 
608 public:
609  NumType arc() const
610  {
611  return arcOld_;
612  }
613 
614 public:
615  void setXNm0()
616  {
617  thisSimDerived().setXNm0Impl(state_.stateNm());
618  }
619 
620 public:
621  void setGradXNm0()
622  {
623  thisSimDerived().setGradXNm0Impl(state_.stateGradNm(), state_.stateNm());
624  }
625 
626 public:
627  void adjustXSize()
628  {
629  thisSimDerived().adjustXSizeImpl(state_.stateNm(), state_.stateCf());
630  }
631 
632 public:
634  {
635  thisSimDerived().adjustGradXSizeImpl(state_.stateGradNm(), state_.stateGradCf());
636  }
637 
638 private:
640 
641 private:
643 
644 private:
645  NumType arcOld_;
646 
647 private:
649 
650 private:
652 
653 public:
654  std::shared_ptr<TParamType> paramStruct;
655 
656 private:
657  std::tuple<TFuncsType...> funcs_;
658 
659  template <class TNumType2, class StateVirtType2>
660  friend class StateSimBaseVirt;
661  template <class TDerived2>
662  friend class StateSimBaseCRTP;
663 };
664 
665 namespace /*<anonymous>*/
666 {
667 template <class TDerived, class TParamType, class TStateType, template <class> class TDiscretizationType,
668  class... TFuncsType>
669 struct StateSimBaseCRTPTraits<StateSimBase<TDerived, TParamType, TStateType, TDiscretizationType, TFuncsType...>>
670 {
671 public:
672  using StateType = TStateType;
673 
674 public:
675  using StateForSimType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateForSimType;
676 
677 public:
678  using NumType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::NumType;
679 
680 public:
681  using StateCfType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateCfType;
682 
683 public:
684  using StateNmType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateNmType;
685 
686 public:
687  using StateVirtType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateVirtType;
688 
689 public:
690  using StateNmNumType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateNmNumType;
691 
692 public:
693  using StateWithGradNmType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateWithGradNmType;
694 
695 public:
696  using StateWithGradCfType = typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateWithGradCfType;
697 
698 public:
699  using StateWithGradNmNumType =
700  typename StateMapBaseTraits<typename TStateType::StateMapBaseType>::StateWithGradNmNumType;
701 };
702 
703 } // namespace <anonymous>
704 }
705 
706 #endif // STATE_SIM_BASE_HPP
StateNumSimType stateWithGradNmDotCache_
std::tuple< TFuncsType... > funcs_
void advanceWithGrad(const TNumType &_arc)
const TDerived & thisSimDerived() const
typename StateSimBaseCRTPTraits< StateSimBase< StateSimE8Base< TNumType, MapDataType, TStateType, TDiscretizationType, TFuncsType... >, ParamType< TNumType, MapDataType >, TStateType, TDiscretizationType, TFuncsType... > >::NumType NumType
void simToT(const NumType &_arcEnd, const NumType &_dt)
void setXNmDot(const NumType &_arc, const PfEaG &_eAG)
StateForSimType & stateImplCRTP()
void setXCfDot(const NumType &_arc, const PfEaG &_eAG)
std::shared_ptr< TParamType > paramStruct
void init(std::shared_ptr< TParamType > _paramStructPtr)
void advanceWithGrad(const NumType &_arc)
typename StateSimBaseCRTPTraits< StateSimBase< StateSimE8Base< TNumType, MapDataType, TStateType, TDiscretizationType, TFuncsType... >, ParamType< TNumType, MapDataType >, TStateType, TDiscretizationType, TFuncsType... > >::StateType StateType
const StateNmType & stateNmDotCache() const
constexpr std::enable_if< II==sizeof...(Tp), void >::type for_each_tuple(std::tuple< Tp... > &, FuncT)
Definition: utils.h:101
void toState0ImplVirt() overridefinal
void advanceImplCRTP(const NumType &_arc)
void setGradXNmDot(const NumType &_arc, const PfEaG &_eAG)
StateCfType stateCfDotCache_
OdeStateSolverType rk_
const StateForSimType & stateImplCRTP() const
constexpr std::enable_if< II< sizeof...(Tp), void >::type for_each_tuple_class(std::tuple< Tp... > &t, FuncT &f){f[II]=[&t](const auto &_a, const auto &_b, const auto &_c, auto &_d){std::get< II >t).computeDArcIdPImpl(_a, _b, _c, _d);};for_each_tuple_class< II+1, FuncT, Tp... >t, f);}template< std::size_t IIMax, std::size_t II=0 >constexpr inline typename std::enable_if<(II==IIMax), void >::type get_costs_sizes(auto &partLatI, const size_t &_i, auto &_sizeCostsPerPartLattice, auto &_sizeCostsPerType){}template< std::size_t IIMax, std::size_t II=0 >constexpr inline typename std::enable_if<(II< IIMax), void >::type get_costs_sizes(auto &partLatI, const size_t &_i, auto &_sizeCostsPerPartLattice, auto &_sizeCostsPerType){size_t partLatICostsTypeJ=partLatI.lattice.size()*partLatI.template costFuncsNr< II >);_sizeCostsPerPartLattice[_i]+=partLatICostsTypeJ;_sizeCostsPerType[II]+=partLatICostsTypeJ;get_costs_sizes< IIMax, II+1 >partLatI, _i, _sizeCostsPerPartLattice, _sizeCostsPerType);}template< typename TNumType, typename TSimType, bool TUseStateNm, template< typename, typename > class...TLatticeTypes >class TrajectorySimulator{public:using StateSimSPtr=std::shared_ptr< TSimType >;public:using StateType=typename TSimType::StateType;public:using StateSPtr=std::shared_ptr< StateType >;public:using StateForSimType=typename TSimType::StateForSimType;public:using LatticePointType=LatticePoint< TNumType, StateType >;public:static constexpr const bool CanComputeStateGrad=!std::is_same< EmptyGradType, typename StateMapBaseTraits< StateType >::StateWithGradNmType >::value;public:static constexpr const size_t CostFuncsTypesNr=std::tuple_element< 0, std::tuple< TLatticeTypes< TNumType, TSimType >... > >::type::costFuncsTypesNr();public:TrajectorySimulator():stateSim_(std::shared_ptr< TSimType >new TSimType)){for_each_tuple_class(partialLattices_, correctStateGradFunc);for(size_t i=0;i< gradCostsMap_.size();++i){gradCostsMap_[i]=std::shared_ptr< Eigen::Map< Eigen::Matrix< TNumType,-1,-1, Eigen::RowMajor > > >new Eigen::Map< Eigen::Matrix< TNumType,-1,-1, Eigen::RowMajor > >nullptr, 0, 0));}}public:TrajectorySimulator(StateSimSPtr &_stateSim):stateSim_(_stateSim){for_each_tuple_class(partialLattices_, correctStateGradFunc);for(size_t i=0;i< gradCostsMap_.size();++i){gradCostsMap_[i]=std::shared_ptr< Eigen::Map< Eigen::Matrix< TNumType,-1,-1, Eigen::RowMajor > > >new Eigen::Map< Eigen::Matrix< TNumType,-1,-1, Eigen::RowMajor > >nullptr, 0, 0));}}public:StateSimSPtr &stateSim(){return stateSim_;}public:const StateSimSPtr &stateSim() const {return stateSim_;}public:LatticePointType &simLatticeI(const size_t &_i){return simulationLattice_[_i];}public:const LatticePointType &simLatticeI(const size_t &_i) const {return simulationLattice_[_i];}public:size_t simLatticeSize() const {return simulationLatticeActiveSize_;}public:template< template< typename, typename > class TLatticeType > TLatticeType< TNumType, TSimType > &partialLattice(){return std::get< TLatticeType< TNumType, TSimType > >partialLattices_);}public:template< template< typename, typename > class TLatticeType > const TLatticeType< TNumType, TSimType > &partialLattice() const {return std::get< TLatticeType< TNumType, TSimType > >partialLattices_);}public:template< size_t TLatticeIdx > auto &partialLattice(){return std::get< TLatticeIdx >partialLattices_);}public:template< size_t TLatticeIdx > const auto &partialLattice() const {return std::get< TLatticeIdx >partialLattices_);}private:using AdvanceFunction=void(TrajectorySimulator< TNumType, TSimType, TUseStateNm, TLatticeTypes... >::*)(const TNumType &);private:AdvanceFunction advanceFunc;private:void advanceFuncSimEmpty(const TNumType &_arcNow){}private:void advanceFuncSim(const TNumType &_arcNow){stateSim_-> advance(_arcNow)
TDerived & thisSimDerived()
void setXCf(const NumType &_arc, const PfEaG &_eAG)
static constexpr auto value
Definition: utils.h:205
typename StateSimBaseCRTPTraits< StateSimBase< StateSimE8Base< TNumType, MapDataType, TStateType, TDiscretizationType, TFuncsType... >, ParamType< TNumType, MapDataType >, TStateType, TDiscretizationType, TFuncsType... > >::StateForSimType StateForSimType
NumType arc() const
const TDerived & thisDerived() const
const StateCfType & stateCfDotCache() const
EvalArcGuarantee
Flags if any guarantees about evaluation arc relative to last evaluation arc are present.
Definition: param_func.hpp:61
void advanceSet0ImplCRTP(auto &_state0, const NumType &_tEnd, const NumType &_dt)
void advanceWithGradImplVirt(const NumType &_arc) overridefinal
OdeStateGradSolverType rkGrad_
void advanceImplVirt(const NumType &_arc) overridefinal
void setXNmDot(const TNumType &_arcNow)
StateForSimType state_
close to previous evaluation arc
StateForSimType & state()
void advanceWithGradImplVirtDispatch(const NumType &_arc)
void advance(const TNumType &_arc)
void advanceWithGradImplCRTP(const NumType &_arc)
void simToTImplCRTP(const NumType &_tEnd, const NumType &_dt)
void advance(const NumType &_arc)
this evaluation arc is at the arc parametrization begin
typename StateSimBaseCRTPTraits< StateSimBase< StateSimE8Base< TNumType, MapDataType, TStateType, TDiscretizationType, TFuncsType... >, ParamType< TNumType, MapDataType >, TStateType, TDiscretizationType, TFuncsType... > >::StateNmType StateNmType
void advanceSet0(auto &_state0, const NumType &_tEnd, const NumType &_dt)
void setGradXCf(const NumType &_arc, const PfEaG &_eAG)
const StateForSimType & state() const


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:22