graph_manager.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @file tests/dtss/graph_manager.hpp
  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_DTSS_GRAPH_MANAGER_HPP
  26. #define TESTS_DTSS_GRAPH_MANAGER_HPP 1
  27. #include <tests/dtss/models.hpp>
  28. #include <artis-star/kernel/dtss/Coordinator.hpp>
  29. #include <artis-star/kernel/dtss/GraphManager.hpp>
  30. #include <artis-star/kernel/dtss/Simulator.hpp>
  31. namespace artis {
  32. namespace tests {
  33. namespace dtss {
  34. struct Policy {
  35. const common::Bag<common::DoubleTime>& bag() const { return _bag; }
  36. virtual void operator()(
  37. common::DoubleTime::type /* t */,
  38. const common::ExternalEvent<common::DoubleTime>& event,
  39. common::DoubleTime::type /* tl */,
  40. common::DoubleTime::type /* tn */)
  41. {
  42. _bag.clear();
  43. _bag.push_back(event);
  44. }
  45. private:
  46. common::Bag<common::DoubleTime> _bag;
  47. };
  48. class OnlyOneGraphManager :
  49. public artis::dtss::GraphManager<common::DoubleTime,
  50. artis::dtss::Parameters<common::DoubleTime>,
  51. artis::common::NoParameters> {
  52. public:
  53. enum submodels {
  54. OneA
  55. };
  56. OnlyOneGraphManager(common::Coordinator<common::DoubleTime>* coordinator,
  57. const artis::dtss::Parameters<common::DoubleTime>& parameters,
  58. const artis::common::NoParameters& graph_parameters)
  59. :
  60. artis::dtss::GraphManager<common::DoubleTime,
  61. artis::dtss::Parameters<common::DoubleTime>,
  62. artis::common::NoParameters>(
  63. coordinator, parameters, graph_parameters),
  64. a("a", parameters)
  65. {
  66. add_child(OneA, &a);
  67. }
  68. ~OnlyOneGraphManager() override = default;
  69. private:
  70. artis::dtss::Simulator<common::DoubleTime, A, artis::dtss::Parameters<common::DoubleTime>> a;
  71. };
  72. class TwoGraphManager :
  73. public artis::dtss::GraphManager<common::DoubleTime,
  74. artis::dtss::Parameters<common::DoubleTime>,
  75. artis::common::NoParameters> {
  76. public:
  77. enum submodels {
  78. OneA, OneB
  79. };
  80. TwoGraphManager(common::Coordinator<common::DoubleTime>* coordinator,
  81. const artis::dtss::Parameters<common::DoubleTime>& parameters,
  82. const artis::common::NoParameters& graph_parameters)
  83. :
  84. artis::dtss::GraphManager<common::DoubleTime,
  85. artis::dtss::Parameters<common::DoubleTime>,
  86. artis::common::NoParameters>(
  87. coordinator, parameters, graph_parameters),
  88. a("a", parameters),
  89. b("b", parameters)
  90. {
  91. add_child(OneA, &a);
  92. add_child(OneB, &b);
  93. out({&a, A::OUT}) >> in({&b, B::IN});
  94. }
  95. ~TwoGraphManager() override = default;
  96. private:
  97. artis::dtss::Simulator<common::DoubleTime, A, artis::dtss::Parameters<common::DoubleTime>> a;
  98. artis::dtss::Simulator<common::DoubleTime, B, artis::dtss::Parameters<common::DoubleTime>> b;
  99. };
  100. }
  101. }
  102. } // namespace artis tests dtss
  103. #endif