Dynamics.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * @file kernel/fddevs/Dynamics.hpp
  3. * @author The ARTIS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * ARTIS - the multimodeling and simulation environment
  8. * This file is a part of the ARTIS environment
  9. *
  10. * Copyright (C) 2013-2019 ULCO http://www.univ-littoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #ifndef FDDEVS_DYNAMICS
  26. #define FDDEVS_DYNAMICS
  27. #include <artis-star/common/Bag.hpp>
  28. #include <artis-star/common/ExternalEvent.hpp>
  29. #include <artis-star/common/Parameters.hpp>
  30. #include <artis-star/common/States.hpp>
  31. #include <artis-star/kernel/fddevs/Simulator.hpp>
  32. #include <string>
  33. #include <vector>
  34. namespace artis {
  35. namespace fddevs {
  36. template<class Time, class Dyn, class StateValues, class Parameters = common::NoParameters>
  37. class Dynamics : public common::States<Time, Dyn>
  38. {
  39. typedef fddevs::Simulator<Time, Dyn, Parameters> Simulator;
  40. public:
  41. Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
  42. :
  43. _name(name), _simulator(context.simulator())
  44. {}
  45. virtual ~Dynamics()
  46. {}
  47. // definition
  48. void initial_state(const StateValues &state)
  49. { _initial_state = state; }
  50. // < X, Y, S, s0, tau, delta_x, sigma, delta_tau, lambda >
  51. virtual void delta_tau(typename Time::type /* t */)
  52. {}
  53. virtual void delta_x(typename Time::type /* t */, typename Time::type /* e */,
  54. const common::Bag<Time> & /* bag */)
  55. {}
  56. virtual void initial_state(typename Time::type /* time */)
  57. { state(_initial_state); }
  58. virtual common::Bag<Time>
  59. lambda(typename Time::type /* time */) const
  60. { return common::Bag<Time>(); }
  61. virtual bool rho(typename Time::type /* time */,
  62. const common::Bag<common::DoubleTime> & /* bag */) const
  63. { return false; }
  64. virtual typename Time::type
  65. tau(typename Time::type /* time */) const
  66. { return Time::infinity; }
  67. virtual typename Time::type lookahead(const typename Time::type &t) const
  68. { return t; }
  69. // observation
  70. virtual common::Value observe(const typename Time::type & /* t */,
  71. unsigned int /* index */) const
  72. { return common::Value(); }
  73. // structure
  74. const std::string &get_name() const
  75. { return _name; }
  76. void input_port(common::Port p)
  77. {
  78. _simulator->add_in_port(p);
  79. }
  80. size_t input_port_number() const
  81. { return _simulator->get_in_port_number(); }
  82. void input_ports(std::initializer_list<common::Port> list)
  83. {
  84. for (typename std::initializer_list<common::Port>::iterator it = list.begin();
  85. it != list.end();
  86. ++it) {
  87. _simulator->add_in_port(*it);
  88. }
  89. }
  90. void output_port(common::Port p)
  91. {
  92. _simulator->add_out_port(p);
  93. }
  94. size_t output_port_number() const
  95. { return _simulator->get_out_port_number(); }
  96. void output_ports(std::initializer_list<common::Port> list)
  97. {
  98. for (typename std::initializer_list<common::Port>::iterator it =
  99. list.begin(); it != list.end(); ++it) {
  100. _simulator->add_out_port(*it);
  101. }
  102. }
  103. // state
  104. void restore(const common::context::State<Time> &state)
  105. {
  106. common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
  107. }
  108. void save(common::context::State<Time> &state) const
  109. {
  110. common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
  111. }
  112. void state(const StateValues &new_state)
  113. {
  114. _state = new_state;
  115. }
  116. const StateValues &state() const
  117. { return _state; }
  118. private:
  119. std::string _name;
  120. Simulator *_simulator;
  121. // definition
  122. StateValues _initial_state;
  123. // state
  124. StateValues _state;
  125. };
  126. }
  127. } // namespace artis fddevs
  128. #endif