graph_manager.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * @file tests/dsde/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_DSDE_GRAPH_MANAGER_HPP
  26. #define TESTS_DSDE_GRAPH_MANAGER_HPP
  27. #include <artis-star/kernel/dsde/Coordinator.hpp>
  28. #include <artis-star/kernel/dsde/GraphManager.hpp>
  29. #include <artis-star/kernel/pdevs/Simulator.hpp>
  30. #include <tests/dsde/models.hpp>
  31. namespace artis {
  32. namespace tests {
  33. namespace dsde {
  34. class FlatGraphManager :
  35. public artis::dsde::GraphManager<common::DoubleTime>
  36. {
  37. public:
  38. enum submodels
  39. {
  40. BEEP = 1
  41. };
  42. FlatGraphManager(common::Coordinator<common::DoubleTime> *coordinator,
  43. const artis::common::NoParameters &parameters,
  44. const artis::common::NoParameters &graph_parameters)
  45. :
  46. artis::dsde::GraphManager<common::DoubleTime>(coordinator, parameters,
  47. graph_parameters),
  48. _beep("beep", parameters)
  49. {
  50. add_child(BEEP, &_beep);
  51. }
  52. ~FlatGraphManager() override = default;
  53. private:
  54. artis::pdevs::Simulator<common::DoubleTime, Beep> _beep;
  55. };
  56. class Executive :
  57. public artis::dsde::Executive<common::DoubleTime, Executive>
  58. {
  59. public:
  60. Executive(
  61. const artis::dsde::ExecutiveContext<common::DoubleTime,
  62. Executive,
  63. artis::common::NoParameters,
  64. artis::common::NoParameters> &context,
  65. artis::dsde::GraphManager<common::DoubleTime,
  66. artis::common::NoParameters,
  67. artis::common::NoParameters> &graph_manager)
  68. :
  69. artis::dsde::Executive<common::DoubleTime, Executive>(context,
  70. graph_manager), _index(0), _up(true)
  71. {}
  72. ~Executive() override = default;
  73. void dint(typename common::DoubleTime::type t) override
  74. {
  75. #ifndef WITH_TRACE
  76. (void)t;
  77. #endif
  78. #ifdef WITH_TRACE
  79. common::Trace<common::DoubleTime>::trace()
  80. << common::TraceElement<common::DoubleTime>(get_name(), t,
  81. common::FormalismType::DSDE,
  82. common::FunctionType::DELTA_INT,
  83. common::LevelType::USER);
  84. common::Trace<common::DoubleTime>::trace().flush();
  85. #endif
  86. if (_up) {
  87. ++_index;
  88. } else {
  89. --_index;
  90. }
  91. if (_index == 4 and _up) {
  92. _up = false;
  93. --_index;
  94. }
  95. if (_up) {
  96. graph_manager().add_dynamic_child(_index,
  97. new artis::pdevs::Simulator<common::DoubleTime, Beep>(
  98. "beep" + std::to_string(_index),
  99. artis::common::NoParameters()));
  100. graph_manager().add_link(FlatGraphManager::BEEP, Beep::OUT, _index,
  101. Beep::IN);
  102. } else {
  103. if (_index == 3) {
  104. graph_manager().remove_dynamic_child(t, _index);
  105. } else if (_index == 2) {
  106. graph_manager().remove_link(FlatGraphManager::BEEP, Beep::OUT, _index,
  107. Beep::IN);
  108. }
  109. }
  110. }
  111. typename common::DoubleTime::type
  112. start(typename common::DoubleTime::type t) override
  113. {
  114. #ifndef WITH_TRACE
  115. (void)t;
  116. #endif
  117. #ifdef WITH_TRACE
  118. common::Trace<common::DoubleTime>::trace()
  119. << common::TraceElement<common::DoubleTime>(get_name(), t,
  120. common::FormalismType::DSDE,
  121. common::FunctionType::START,
  122. common::LevelType::USER);
  123. common::Trace<common::DoubleTime>::trace().flush();
  124. #endif
  125. _index = 1;
  126. _up = true;
  127. return 1;
  128. }
  129. typename common::DoubleTime::type
  130. ta(typename common::DoubleTime::type t) const override
  131. {
  132. #ifndef WITH_TRACE
  133. (void)t;
  134. #endif
  135. #ifdef WITH_TRACE
  136. common::Trace<common::DoubleTime>::trace()
  137. << common::TraceElement<common::DoubleTime>(get_name(), t,
  138. common::FormalismType::DSDE,
  139. common::FunctionType::TA,
  140. common::LevelType::USER);
  141. common::Trace<common::DoubleTime>::trace().flush();
  142. #endif
  143. return 2;
  144. }
  145. private:
  146. int _index;
  147. bool _up;
  148. };
  149. }
  150. }
  151. } // namespace artis tests dsde
  152. #endif