graph_manager.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**
  2. * @file tests/pdevs/graph_manager.cpp
  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 TESTS_PDEVS_GRAPH_MANAGER_HPP
  26. #define TESTS_PDEVS_GRAPH_MANAGER_HPP
  27. #include <tests/pdevs/models.hpp>
  28. #include <artis-star/kernel/pdevs/Coordinator.hpp>
  29. #include <artis-star/kernel/pdevs/GraphManager.hpp>
  30. #include <artis-star/kernel/pdevs/Simulator.hpp>
  31. namespace artis {
  32. namespace tests {
  33. namespace pdevs {
  34. class S1GraphManager : public artis::pdevs::GraphManager<common::DoubleTime>
  35. {
  36. public:
  37. enum submodels
  38. {
  39. OneA, OneB
  40. };
  41. enum outputs
  42. {
  43. OUT
  44. };
  45. S1GraphManager(common::Coordinator<common::DoubleTime> *coordinator,
  46. const artis::common::NoParameters &parameters,
  47. const artis::common::NoParameters &graph_parameters)
  48. :
  49. artis::pdevs::GraphManager<common::DoubleTime>(coordinator, parameters, graph_parameters),
  50. a("a1", parameters), b("b1", parameters)
  51. {
  52. add_child(OneA, &a);
  53. add_child(OneB, &b);
  54. coordinator->output_port({OUT, "out"});
  55. out({&a, A::OUT}) >> in({&b, B::IN});
  56. out({&b, B::OUT}) >> out({coordinator, OUT});
  57. }
  58. ~S1GraphManager() override = default;
  59. private:
  60. artis::pdevs::Simulator<common::DoubleTime, A> a;
  61. artis::pdevs::Simulator<common::DoubleTime, B> b;
  62. };
  63. class S2GraphManager : public artis::pdevs::GraphManager<common::DoubleTime>
  64. {
  65. public:
  66. enum submodels
  67. {
  68. OneA, OneB
  69. };
  70. enum inputs
  71. {
  72. IN
  73. };
  74. S2GraphManager(common::Coordinator<common::DoubleTime> *coordinator,
  75. const artis::common::NoParameters &parameters,
  76. const artis::common::NoParameters &graph_parameters)
  77. :
  78. artis::pdevs::GraphManager<common::DoubleTime>(coordinator, parameters, graph_parameters),
  79. a("a2", parameters), b("b2", parameters)
  80. {
  81. add_child(OneA, &a);
  82. add_child(OneB, &b);
  83. coordinator->input_port({IN, "in"});
  84. in({coordinator, IN}) >> in({&a, A::IN});
  85. out({&a, A::OUT}) >> in({&b, B::IN});
  86. }
  87. ~S2GraphManager() override = default;
  88. private:
  89. artis::pdevs::Simulator<common::DoubleTime, A> a;
  90. artis::pdevs::Simulator<common::DoubleTime, B> b;
  91. };
  92. class RootGraphManager :
  93. public artis::pdevs::GraphManager<common::DoubleTime>
  94. {
  95. public:
  96. enum submodels
  97. {
  98. OneS1, OneS2
  99. };
  100. RootGraphManager(
  101. common::Coordinator<common::DoubleTime> *coordinator,
  102. const artis::common::NoParameters &parameters,
  103. const artis::common::NoParameters &graph_parameters)
  104. :
  105. artis::pdevs::GraphManager<common::DoubleTime>(coordinator, parameters, graph_parameters),
  106. S1("S1", parameters, graph_parameters),
  107. S2("S2", parameters, graph_parameters)
  108. {
  109. add_child(OneS1, &S1);
  110. add_child(OneS2, &S2);
  111. out({&S1, S1GraphManager::OUT}) >> in({&S2, S2GraphManager::IN});
  112. }
  113. ~RootGraphManager() override = default;
  114. private:
  115. artis::pdevs::Coordinator<common::DoubleTime, S1GraphManager> S1;
  116. artis::pdevs::Coordinator<common::DoubleTime, S2GraphManager> S2;
  117. };
  118. template<typename M>
  119. class OnlyOneGraphManager :
  120. public artis::pdevs::GraphManager<common::DoubleTime>
  121. {
  122. public:
  123. enum submodels
  124. {
  125. OneM
  126. };
  127. OnlyOneGraphManager(common::Coordinator<common::DoubleTime> *coordinator,
  128. const artis::common::NoParameters &parameters,
  129. const artis::common::NoParameters &graph_parameters)
  130. :
  131. artis::pdevs::GraphManager<common::DoubleTime>(coordinator, parameters, graph_parameters),
  132. model("a", parameters)
  133. {
  134. add_child(OneM, &model);
  135. }
  136. ~OnlyOneGraphManager() override = default;
  137. private:
  138. artis::pdevs::Simulator<common::DoubleTime, M> model;
  139. };
  140. class FlatGraphManager :
  141. public artis::pdevs::GraphManager<common::DoubleTime>
  142. {
  143. public:
  144. enum submodels
  145. {
  146. FirstA, SecondA,
  147. FirstB, SecondB
  148. };
  149. FlatGraphManager(common::Coordinator<common::DoubleTime> *coordinator,
  150. const artis::common::NoParameters &parameters,
  151. const artis::common::NoParameters &graph_parameters)
  152. :
  153. artis::pdevs::GraphManager<common::DoubleTime>(coordinator, parameters, graph_parameters),
  154. a1("a1", parameters), b1("b1", parameters),
  155. a2("a2", parameters), b2("b2", parameters)
  156. {
  157. add_child(FirstA, &a1);
  158. add_child(FirstB, &b1);
  159. add_child(SecondA, &a2);
  160. add_child(SecondB, &b2);
  161. out({&a1, A::OUT}) >> in({&b1, B::IN});
  162. out({&b1, B::OUT}) >> in({&a2, A::IN});
  163. out({&a2, A::OUT}) >> in({&b2, B::IN});
  164. }
  165. ~FlatGraphManager() override = default;
  166. private:
  167. artis::pdevs::Simulator<common::DoubleTime, A> a1;
  168. artis::pdevs::Simulator<common::DoubleTime, B> b1;
  169. artis::pdevs::Simulator<common::DoubleTime, A> a2;
  170. artis::pdevs::Simulator<common::DoubleTime, B> b2;
  171. };
  172. }
  173. }
  174. } // namespace artis tests pdevs
  175. #endif