graph_manager.hpp 6.1 KB

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