state_sim.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_HPP
34 #define STATE_SIM_HPP
35 
38 
39 namespace tuw
40 {
41 template <class TNum, class TStateNm, class TStateCf>
42 class StateMapBase : public StateMapTuple<TNum, TStateNm, TStateCf>
43 {
44 public:
46 
47 public:
49 
50 public:
52 
53 public:
54  auto& stateNm()
55  {
56  return this->template sub<0>();
57  }
58 
59 public:
60  const auto& stateNm() const
61  {
62  return this->template sub<0>();
63  }
64 
65 public:
66  auto& stateCf()
67  {
68  return this->template sub<1>();
69  }
70 
71 public:
72  const auto& stateCf() const
73  {
74  return this->template sub<1>();
75  }
76 
77 public:
78  auto& state()
79  {
80  return *this;
81  }
82 
83 public:
84  const auto& state() const
85  {
86  return *this;
87  }
88 };
89 
90 template <class TNum, template <class, class> class TStateNm, template <class, class> class TStateCf>
91 using StateMap = StateMapBase<TNum, TStateNm<TNum, TNum>, TStateCf<TNum, TNum>>;
92 
93 template <class TNum, class TStateNmByOptVar, class TStateCfByOptVar>
94 class StateGradMapBase : public StateMapBase<TNum, TStateNmByOptVar, TStateCfByOptVar>
95 {
96 public:
98 
99 public:
101 
102 public:
104  : StateMapBase<TNum, TStateNmByOptVar, TStateCfByOptVar>::StateMapBase(), gradMatMap_(nullptr, 0, 0)
105  {
106  }
107 
108 public:
109  StateGradMapBase(auto&& _a, auto&& _b)
110  : StateMapBase<TNum, TStateNmByOptVar, TStateCfByOptVar>::StateMapBase(_a, _b), gradMatMap_(nullptr, 0, 0)
111  {
112  }
113 
114 public:
115  auto& mat()
116  {
117  return gradMatMap_;
118  }
119 
120 public:
121  const auto& mat() const
122  {
123  return gradMatMap_;
124  }
125 
126 public:
127  void bindMat()
128  {
129 
130 #ifdef USE_MAP_ALIGNMENT
131  new (&gradMatMap_) Eigen::Map<Eigen::Matrix<TNum, -1, -1, Eigen::RowMajor>, MapAlignment>(
132  this->memStartRef(), this->stateNm().subSize() + this->stateCf().subSize(),
133  this->stateNm().sub(0).data().size());
134 #else
135  new (&gradMatMap_) Eigen::Map<Eigen::Matrix<TNum, -1, -1, Eigen::RowMajor>>(
136  this->memStartRef(), this->stateNm().subSize() + this->stateCf().subSize(),
137  this->stateNm().sub(0).data().size());
138 #endif
139  this->stateNm().bindMat();
140  this->stateCf().bindMat();
141  }
142 
143 private:
144 #ifdef USE_MAP_ALIGNMENT
145  Eigen::Map<Eigen::Matrix<TNum, -1, -1, Eigen::RowMajor>, MapAlignment> gradMatMap_;
146 #else
147  Eigen::Map<Eigen::Matrix<TNum, -1, -1, Eigen::RowMajor>> gradMatMap_;
148 #endif
149 };
150 
151 template <class TNum, class TstateGrad>
152 class StateGradWithMatMap : public TstateGrad
153 {
154 public:
155  StateGradWithMatMap() : TstateGrad(), gradMatMap_(nullptr, 0, 0)
156  {
157  }
158 
159 public:
160  StateGradWithMatMap(auto&& _a, auto&& _b) : TstateGrad(_a, _b), gradMatMap_(nullptr, 0, 0)
161  {
162  }
163 
164 public:
165  StateGradWithMatMap(const StateGradWithMatMap& _rhs) : TstateGrad(_rhs), gradMatMap_(nullptr, 0, 0)
166  {
167  }
168 
169 public:
171  {
172  TstateGrad::operator=(_rhs);
173  return *this;
174  }
175 
176 public:
178 
179 public:
181 
182 public:
183  auto& mat()
184  {
185  return gradMatMap_;
186  }
187 
188 public:
189  const auto& mat() const
190  {
191  return gradMatMap_;
192  }
193 
194 public:
195  void bindMat()
196  {
197 #ifdef USE_MAP_ALIGNMENT
198  new (&gradMatMap_) Eigen::Map<Eigen::Matrix<TNum, -1, -1, Eigen::RowMajor>, MapAlignment>(
199  this->memStartRef(), this->subSize(), this->sub(0).data().size());
200 #else
201  new (&gradMatMap_) Eigen::Map<Eigen::Matrix<TNum, -1, -1, Eigen::RowMajor>>(
202  this->memStartRef(), this->subSize(), this->sub(0).data().size());
203 #endif
204  }
205 
206 private:
207 #ifdef USE_MAP_ALIGNMENT
208  Eigen::Map<Eigen::Matrix<TNum, -1, -1, Eigen::RowMajor>, MapAlignment> gradMatMap_;
209 #else
210  Eigen::Map<Eigen::Matrix<TNum, -1, -1, Eigen::RowMajor>> gradMatMap_;
211 #endif
212 };
213 
214 namespace /*<anonymous>*/
215 {
216 template <class TNum, class TStateNm, class TStateCf>
217 struct StateMapBaseTraits<StateMapBase<TNum, TStateNm, TStateCf>>
218 {
219 public:
220  using StateType = StateMapBase<TNum, TStateNm, TStateCf>;
221 
222 public:
223  using StateForSimType = StateMapBase<TNum, TStateNm, TStateCf>;
224 
225 public:
226  using NumType = TNum;
227 
228 public:
229  using StateCfType = TStateCf;
230 
231 public:
232  using StateNmType = TStateNm;
233 
234 public:
235  using StateVirtType = StateMapBaseVirt<TNum>;
236 
237 public:
238  using StateNmNumType = typename TStateNm::StateMapBaseCRTP::MatrixTypeCRTP;
239 
240 public:
241  using StateWithGradNmType = EmptyGradType;
242 
243 public:
244  using StateWithGradCfType = EmptyGradType;
245 
246 public:
247  using StateWithGradNmNumType = EmptyGradType;
248 };
249 template <class TNum, class TStateNm, class TStateCf>
250 struct StateMapBaseTraits<StateGradMapBase<TNum, TStateNm, TStateCf>>
251 {
252 public:
254 
255 public:
256  using StateForSimType = StateMapBase<TNum, TStateNm, TStateCf>;
257 
258 public:
259  using NumType = TNum;
260 
261 public:
262  using StateCfType = TStateCf;
263 
264 public:
265  using StateNmType = TStateNm;
266 
267 public:
268  using StateVirtType = StateMapBaseVirt<TNum>;
269 
270 public:
271  using StateNmNumType = typename TStateNm::StateMapBaseCRTP::MatrixTypeCRTP;
272 
273 public:
274  using StateWithGradNmType = EmptyGradType;
275 
276 public:
277  using StateWithGradCfType = EmptyGradType;
278 
279 public:
280  using StateWithGradNmNumType = EmptyGradType;
281 };
282 template <class TNum, class TstateGrad>
283 struct StateMapBaseTraits<StateGradWithMatMap<TNum, TstateGrad>>
284 {
285 public:
286  using StateType = typename StateMapBaseTraits<TstateGrad>::StateType;
287 
288 public:
289  using StateForSimType = typename StateMapBaseTraits<TstateGrad>::StateForSimType;
290 
291 public:
292  using NumType = typename StateMapBaseTraits<TstateGrad>::NumType;
293 
294 public:
295  using StateCfType = typename StateMapBaseTraits<TstateGrad>::StateCfType;
296 
297 public:
298  using StateNmType = typename StateMapBaseTraits<TstateGrad>::StateNmType;
299 
300 public:
301  using StateVirtType = typename StateMapBaseTraits<TstateGrad>::StateVirtType;
302 
303 public:
304  using StateNmNumType = typename StateMapBaseTraits<TstateGrad>::StateNmNumType;
305 
306 public:
307  using StateWithGradNmType = typename StateMapBaseTraits<TstateGrad>::StateWithGradNmType;
308 
309 public:
310  using StateWithGradCfType = typename StateMapBaseTraits<TstateGrad>::StateWithGradCfType;
311 
312 public:
313  using StateWithGradNmNumType = typename StateMapBaseTraits<TstateGrad>::StateWithGradNmNumType;
314 };
315 // template<class TNum, template<class> class TStateNm, template<class> class TStateCf>
316 // struct StateMapBaseTraits< StateMapBase<TNum, TStateNm, TStateCf> > {
317 // public : using StateType = StateMapBase<TNum, TStateNm<TNum>, TStateCf<TNum>>;
318 // public : using StateForSimType = StateMapBase<TNum, TStateNm<TNum>, TStateCf<TNum>>;
319 // public : using NumType = TNum;
320 // public : using StateCfType = TStateCf<TNum>;
321 // public : using StateNmType = TStateNm;
322 // public : using StateVirtType = StateMapBaseVirt<TNum>;
323 // public : using StateNmNumType = typename TStateNm::StateMapBaseCRTP::MatrixTypeCRTP;
324 // public : using StateWithGradNmType = EmptyGradType;
325 // public : using StateWithGradCfType = EmptyGradType;
326 // public : using StateWithGradNmNumType = EmptyGradType;
327 // };
328 
329 } // namespace <anonymous>
330 
331 namespace /*<anonymous>*/
332 {
333 template <class TStateWithGradMapType>
334 using StateMapTraits = StateMapBaseTraits<typename TStateWithGradMapType::StateMapBaseType>;
335 
336 } // namespace <anonymous>
337 
338 template <class TNum, class TState, class TStateGrad>
339 class StateWithGradMapSimBaseInternal : public StateMapTuple<TNum, TState, TStateGrad>
340 {
341 public:
343 
344 public:
345  auto& state()
346  {
347  return this->template sub<0>();
348  }
349 
350 public:
351  const auto& state() const
352  {
353  return this->template sub<0>();
354  }
355 
356 public:
357  auto& stateGrad()
358  {
359  return this->template sub<1>();
360  }
361 
362 public:
363  const auto& stateGrad() const
364  {
365  return this->template sub<1>();
366  }
367 };
368 
369 template <class TStateWithGradMapType>
371  : public StateMapTuple<
372  typename StateMapTraits<TStateWithGradMapType>::NumType,
374  typename StateMapTraits<TStateWithGradMapType>::StateNmType,
375  typename StateMapTraits<TStateWithGradMapType>::StateNmGradType>,
376  StateWithGradMapSimBaseInternal<typename StateMapTraits<TStateWithGradMapType>::NumType,
377  typename StateMapTraits<TStateWithGradMapType>::StateCfType,
378  typename StateMapTraits<TStateWithGradMapType>::StateCfGradType>>
379 {
380 public:
381  using StateMapBaseType = typename StateMapTraits<TStateWithGradMapType>::StateType;
382 
383 private:
384  using NumType = typename StateMapTraits<TStateWithGradMapType>::NumType;
385 
386 private:
387  using BaseClassType =
389  StateWithGradMapSimBaseInternal<typename StateMapTraits<TStateWithGradMapType>::NumType,
390  typename StateMapTraits<TStateWithGradMapType>::StateNmType,
391  typename StateMapTraits<TStateWithGradMapType>::StateNmGradType>,
392  StateWithGradMapSimBaseInternal<typename StateMapTraits<TStateWithGradMapType>::NumType,
393  typename StateMapTraits<TStateWithGradMapType>::StateCfType,
394  typename StateMapTraits<TStateWithGradMapType>::StateCfGradType>>;
395 
396 public:
398  {
399  }
400 
401 public:
403  {
404  }
405 
406 public:
408  {
409  BaseClassType::operator=(_rhs);
410  return *this;
411  }
412 
413 public:
415 
416 public:
418 
419 public:
421  {
422  return this->template sub<0>();
423  }
424 
425 public:
426  const auto& stateWithGradNm() const
427  {
428  return this->template sub<0>();
429  }
430 
431 public:
432  auto& stateNm()
433  {
434  return this->stateWithGradNm().template sub<0>();
435  }
436 
437 public:
438  const auto& stateNm() const
439  {
440  return this->stateWithGradNm().template sub<0>();
441  }
442 
443 public:
444  auto& stateGradNm()
445  {
446  return this->stateWithGradNm().template sub<1>();
447  }
448 
449 public:
450  const auto& stateGradNm() const
451  {
452  return this->stateWithGradNm().template sub<1>();
453  }
454 
455 public:
457  {
458  return this->template sub<1>();
459  }
460 
461 public:
462  const auto& stateWithGradCf() const
463  {
464  return this->template sub<1>();
465  }
466 
467 public:
468  auto& stateCf()
469  {
470  return this->stateWithGradCf().template sub<0>();
471  }
472 
473 public:
474  const auto& stateCf() const
475  {
476  return this->stateWithGradCf().template sub<0>();
477  }
478 
479 public:
480  auto& stateGradCf()
481  {
482  return this->stateWithGradCf().template sub<1>();
483  }
484 
485 public:
486  const auto& stateGradCf() const
487  {
488  return this->stateWithGradCf().template sub<1>();
489  }
490 };
491 
492 template <class TNum, template <class, class> class TStateNm, template <class, class> class TStateCf,
493  template <class, class> class TOptVarStruct>
495  : public StateMapTuple<TNum, StateMapBase<TNum, TStateNm<TNum, TNum>, TStateCf<TNum, TNum>>,
496  StateGradMapBase<TNum, StateGradWithMatMap<TNum, TStateNm<TNum, TOptVarStruct<TNum, TNum>>>,
497  StateGradWithMatMap<TNum, TStateCf<TNum, TOptVarStruct<TNum, TNum>>>>>
498 {
499 public:
501 
502 private:
503  using BaseClassType =
507 
508 public:
510  {
511  }
512 
513 public:
515  {
516  }
517 
518 public:
520  {
521  BaseClassType::operator=(_rhs);
522  return *this;
523  }
524 
525 public:
527 
528 public:
530 
531 public:
532  auto& stateNm()
533  {
534  return this->state().template sub<0>();
535  }
536 
537 public:
538  const auto& stateNm() const
539  {
540  return this->state().template sub<0>();
541  }
542 
543 public:
544  auto& stateCf()
545  {
546  return this->state().template sub<1>();
547  }
548 
549 public:
550  const auto& stateCf() const
551  {
552  return this->state().template sub<1>();
553  }
554 
555 public:
556  auto& stateGradNm()
557  {
558  return this->stateGrad().template sub<0>();
559  }
560 
561 public:
562  const auto& stateGradNm() const
563  {
564  return this->stateGrad().template sub<0>();
565  }
566 
567 public:
568  auto& stateGradCf()
569  {
570  return this->stateGrad().template sub<1>();
571  }
572 
573 public:
574  const auto& stateGradCf() const
575  {
576  return this->stateGrad().template sub<1>();
577  }
578 
579 public:
580  auto& state()
581  {
582  return this->template sub<0>();
583  }
584 
585 public:
586  const auto& state() const
587  {
588  return this->template sub<0>();
589  }
590 
591 public:
592  auto& stateGrad()
593  {
594  return this->template sub<1>();
595  }
596 
597 public:
598  const auto& stateGrad() const
599  {
600  return this->template sub<1>();
601  }
602 };
603 
604 template <class TNum, template <class, class> class TStateNm, template <class, class> class TStateCf,
605  template <class, class> class TOptVarStruct>
607 
608 namespace /*<anonymous>*/
609 {
610 template <class TNum, template <class, class> class TStateNm, template <class, class> class TStateCf,
611  template <class, class> class TOptVarStruct>
612 struct StateMapBaseTraits<StateWithGradMapBase<TNum, TStateNm, TStateCf, TOptVarStruct>>
613 {
614 public:
616 
617 public:
618  using StateForSimType = StateWithGradMapSimBase<StateType>;
619 
620 public:
621  using NumType = TNum;
622 
623 public:
624  using StateCfType = TStateCf<TNum, TNum>;
625 
626 public:
627  using StateNmType = TStateNm<TNum, TNum>;
628 
629 public:
631 
632 public:
634 
635 public:
638 
639 public:
640  using StateVirtType = StateMapBaseVirt<TNum>;
641 
642 public:
643  using StateNmNumType = typename TStateNm<TNum, TNum>::StateMapBaseCRTP::MatrixTypeCRTP;
644 
645 public:
647 
648 public:
650 
651 public:
652  using StateWithGradNmNumType = typename StateWithGradNmType::StateMapBaseCRTP::MatrixTypeCRTP;
653 };
654 
655 } // namespace <anonymous>
656 
657 template <class TNumType>
659 }
660 
661 #endif // STATE_SIM_HPP
const auto & mat() const
Definition: state_sim.hpp:189
StateMapTuple & operator=(const StateMapTuple &_rhs)
StateGradWithMatMap(const StateGradWithMatMap &_rhs)
Definition: state_sim.hpp:165
Eigen::Map< Eigen::Matrix< TNum,-1,-1, Eigen::RowMajor > > gradMatMap_
Definition: state_sim.hpp:210
const auto & stateCf() const
Definition: state_sim.hpp:550
StateGradWithMatMap & operator=(const StateGradWithMatMap &_rhs)
Definition: state_sim.hpp:170
Eigen::Map< Eigen::Matrix< TNum,-1,-1, Eigen::RowMajor > > gradMatMap_
Definition: state_sim.hpp:147
const auto & mat() const
Definition: state_sim.hpp:121
StateWithGradMapSimBase(const StateWithGradMapSimBase &_rhs)
Definition: state_sim.hpp:402
const auto & stateNm() const
Definition: state_sim.hpp:538
StateGradMapBase(auto &&_a, auto &&_b)
Definition: state_sim.hpp:109
typename StateMapTraits< TStateWithGradMapType >::StateType StateMapBaseType
Definition: state_sim.hpp:381
const auto & stateWithGradNm() const
Definition: state_sim.hpp:426
const auto & stateGrad() const
Definition: state_sim.hpp:598
const auto & stateWithGradCf() const
Definition: state_sim.hpp:462
const auto & stateGradCf() const
Definition: state_sim.hpp:574
const auto & stateGrad() const
Definition: state_sim.hpp:363
StateWithGradMapSimBase & operator=(const StateWithGradMapSimBase &_rhs)
Definition: state_sim.hpp:407
const auto & state() const
Definition: state_sim.hpp:84
StateGradWithMatMap(auto &&_a, auto &&_b)
Definition: state_sim.hpp:160
const auto & stateGradCf() const
Definition: state_sim.hpp:486
const auto & state() const
Definition: state_sim.hpp:586
const auto & stateNm() const
Definition: state_sim.hpp:60
const auto & stateCf() const
Definition: state_sim.hpp:72
const auto & stateGradNm() const
Definition: state_sim.hpp:562
auto & stateNm()
Definition: state_sim.hpp:54
StateWithGradMapBase & operator=(const StateWithGradMapBase &_rhs)
Definition: state_sim.hpp:519
StateWithGradMapBase(const StateWithGradMapBase &_rhs)
Definition: state_sim.hpp:514
typename StateMapTraits< TStateWithGradMapType >::NumType NumType
Definition: state_sim.hpp:384
auto & stateCf()
Definition: state_sim.hpp:66
const auto & stateGradNm() const
Definition: state_sim.hpp:450
const auto & stateCf() const
Definition: state_sim.hpp:474
const auto & stateNm() const
Definition: state_sim.hpp:438


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