Dynamics.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. typedef fddevs::Simulator<Time, Dyn, Parameters> Simulator;
  39. public:
  40. Dynamics(const std::string& name, const Context<Time, Dyn, Parameters>& context)
  41. :
  42. _name(name), _simulator(context.simulator()) { }
  43. virtual ~Dynamics() { }
  44. // definition
  45. void initial_state(const StateValues& state)
  46. { _initial_state = state; }
  47. // < X, Y, S, s0, tau, delta_x, sigma, delta_tau, lambda >
  48. virtual void delta_tau(typename Time::type /* t */) { }
  49. virtual void delta_x(typename Time::type /* t */, typename Time::type /* e */,
  50. const common::Bag<Time>& /* bag */) { }
  51. virtual void initial_state(typename Time::type /* time */)
  52. { state(_initial_state); }
  53. virtual common::Bag<Time>
  54. lambda(typename Time::type /* time */) const { return common::Bag<Time>(); }
  55. virtual bool rho(typename Time::type /* time */,
  56. const common::Bag<common::DoubleTime>& /* bag */) const { return false; }
  57. virtual typename Time::type
  58. tau(typename Time::type /* time */) const { return Time::infinity; }
  59. virtual typename Time::type lookahead(const typename Time::type& t) const
  60. { return t; }
  61. // observation
  62. virtual common::Value observe(const typename Time::type& /* t */,
  63. unsigned int /* index */) const { return common::Value(); }
  64. // structure
  65. const std::string& get_name() const { return _name; }
  66. void input_port(common::Port p)
  67. {
  68. _simulator->add_in_port(p);
  69. }
  70. size_t input_port_number() const { return _simulator->get_in_port_number(); }
  71. void input_ports(std::initializer_list<common::Port> list)
  72. {
  73. for (typename std::initializer_list<common::Port>::iterator it = list.begin();
  74. it != list.end();
  75. ++it) {
  76. _simulator->add_in_port(*it);
  77. }
  78. }
  79. void output_port(common::Port p)
  80. {
  81. _simulator->add_out_port(p);
  82. }
  83. size_t output_port_number() const { return _simulator->get_out_port_number(); }
  84. void output_ports(std::initializer_list<common::Port> list)
  85. {
  86. for (typename std::initializer_list<common::Port>::iterator it =
  87. list.begin(); it != list.end(); ++it) {
  88. _simulator->add_out_port(*it);
  89. }
  90. }
  91. // state
  92. void restore(const common::context::State<Time>& state)
  93. {
  94. common::States<Time, Dyn>::restore(static_cast<Dyn*>(this), state);
  95. }
  96. void save(common::context::State<Time>& state) const
  97. {
  98. common::States<Time, Dyn>::save(static_cast<const Dyn*>(this), state);
  99. }
  100. void state(const StateValues& new_state)
  101. {
  102. _state = new_state;
  103. }
  104. const StateValues& state() const { return _state; }
  105. private:
  106. std::string _name;
  107. Simulator* _simulator;
  108. // definition
  109. StateValues _initial_state;
  110. // state
  111. StateValues _state;
  112. };
  113. }
  114. } // namespace artis fddevs
  115. #endif