graph_manager.hpp 7.3 KB

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