graph_manager.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. * @file tests/pdevs/graph_manager.cpp
  3. * @author The PARADEVS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * PARADEVS - the multimodeling and simulation environment
  8. * This file is a part of the PARADEVS environment
  9. *
  10. * Copyright (C) 2013-2015 ULCO http://www.univ-litoral.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 1
  27. #include <tests/pdevs/models.hpp>
  28. #include <paradevs/kernel/pdevs/Coordinator.hpp>
  29. #include <paradevs/kernel/pdevs/GraphManager.hpp>
  30. #include <paradevs/kernel/pdevs/Simulator.hpp>
  31. namespace paradevs { namespace tests { namespace pdevs {
  32. class S1GraphManager :
  33. public paradevs::pdevs::GraphManager < common::DoubleTime >
  34. {
  35. public:
  36. S1GraphManager(common::Coordinator < common::DoubleTime >* coordinator,
  37. const paradevs::common::NoParameters& parameters) :
  38. paradevs::pdevs::GraphManager < common::DoubleTime >(coordinator,
  39. parameters),
  40. a("a1", common::NoParameters()), b("b1", common::NoParameters())
  41. {
  42. add_child(&a);
  43. add_child(&b);
  44. a.add_out_port("out");
  45. b.add_in_port("in");
  46. b.add_out_port("out");
  47. coordinator->add_out_port("out");
  48. add_link(&a, "out", &b, "in");
  49. add_link(&b, "out", coordinator, "out");
  50. }
  51. virtual ~S1GraphManager()
  52. { }
  53. private:
  54. paradevs::pdevs::Simulator < common::DoubleTime, A > a;
  55. paradevs::pdevs::Simulator < common::DoubleTime, B > b;
  56. };
  57. class S2GraphManager :
  58. public paradevs::pdevs::GraphManager < common::DoubleTime >
  59. {
  60. public:
  61. S2GraphManager(common::Coordinator < common::DoubleTime >* coordinator,
  62. const paradevs::common::NoParameters& parameters) :
  63. paradevs::pdevs::GraphManager < common::DoubleTime >(coordinator,
  64. parameters),
  65. a("a2", common::NoParameters()), b("b2", common::NoParameters())
  66. {
  67. add_child(&a);
  68. add_child(&b);
  69. a.add_in_port("in");
  70. a.add_out_port("out");
  71. b.add_in_port("in");
  72. coordinator->add_in_port("in");
  73. add_link(&a, "out", &b, "in");
  74. add_link(coordinator, "in", &a, "in");
  75. }
  76. virtual ~S2GraphManager()
  77. { }
  78. private:
  79. paradevs::pdevs::Simulator < common::DoubleTime, A > a;
  80. paradevs::pdevs::Simulator < common::DoubleTime, B > b;
  81. };
  82. class RootGraphManager :
  83. public paradevs::pdevs::GraphManager < common::DoubleTime >
  84. {
  85. public:
  86. RootGraphManager(
  87. common::Coordinator < common::DoubleTime >* coordinator,
  88. const paradevs::common::NoParameters& parameters) :
  89. paradevs::pdevs::GraphManager < common::DoubleTime >(
  90. coordinator, parameters),
  91. S1("S1", paradevs::common::NoParameters(),
  92. paradevs::common::NoParameters()),
  93. S2("S2", paradevs::common::NoParameters(),
  94. paradevs::common::NoParameters())
  95. {
  96. add_child(&S1);
  97. add_child(&S2);
  98. add_link(&S1, "out", &S2, "in");
  99. }
  100. virtual ~RootGraphManager()
  101. { }
  102. private:
  103. paradevs::pdevs::Coordinator <
  104. common::DoubleTime,
  105. S1GraphManager > S1;
  106. paradevs::pdevs::Coordinator <
  107. common::DoubleTime,
  108. S2GraphManager > S2;
  109. };
  110. template < typename M >
  111. class OnlyOneGraphManager :
  112. public paradevs::pdevs::GraphManager < common::DoubleTime >
  113. {
  114. public:
  115. OnlyOneGraphManager(common::Coordinator < common::DoubleTime >* coordinator,
  116. const paradevs::common::NoParameters& parameters) :
  117. paradevs::pdevs::GraphManager < common::DoubleTime >(coordinator,
  118. parameters),
  119. model("m", common::NoParameters())
  120. {
  121. add_child(&model);
  122. }
  123. virtual ~OnlyOneGraphManager()
  124. { }
  125. private:
  126. paradevs::pdevs::Simulator < common::DoubleTime, M > model;
  127. };
  128. class FlatGraphManager :
  129. public paradevs::pdevs::GraphManager < common::DoubleTime >
  130. {
  131. public:
  132. FlatGraphManager(common::Coordinator < common::DoubleTime >* coordinator,
  133. const paradevs::common::NoParameters& parameters) :
  134. paradevs::pdevs::GraphManager < common::DoubleTime >(coordinator,
  135. parameters),
  136. a1("a1", common::NoParameters()), b1("b1", common::NoParameters()),
  137. a2("a2", common::NoParameters()), b2("b2", common::NoParameters())
  138. {
  139. add_child(&a1);
  140. add_child(&b1);
  141. add_child(&a2);
  142. add_child(&b2);
  143. a1.add_out_port("out");
  144. b1.add_in_port("in");
  145. b1.add_out_port("out");
  146. a2.add_in_port("in");
  147. a2.add_out_port("out");
  148. b2.add_in_port("in");
  149. add_link(&a1, "out", &b1, "in");
  150. add_link(&b1, "out", &a2, "in");
  151. add_link(&a2, "out", &b2, "in");
  152. }
  153. virtual ~FlatGraphManager()
  154. { }
  155. private:
  156. paradevs::pdevs::Simulator < common::DoubleTime, A > a1;
  157. paradevs::pdevs::Simulator < common::DoubleTime, B > b1;
  158. paradevs::pdevs::Simulator < common::DoubleTime, A > a2;
  159. paradevs::pdevs::Simulator < common::DoubleTime, B > b2;
  160. };
  161. } } } // namespace paradevs tests pdevs
  162. #endif