graph_manager.hpp 5.3 KB

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