main.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @file pdevs/tests.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. #include <tests/qss/graph_manager.hpp>
  26. #include <artis-star/common/RootCoordinator.hpp>
  27. #include <artis-star/common/observer/Iterator.hpp>
  28. using namespace artis::tests::qss;
  29. void test_parabola()
  30. {
  31. artis::pdevs::qss::QSSParameters<ParabolaParameters> parameters = {{0.5},
  32. {true, true, 0.001, 3},
  33. {0.2}};
  34. class View : public artis::observer::View<artis::common::DoubleTime> {
  35. public:
  36. View()
  37. {
  38. selector("Value", {OnlyOneParabolaGraphManager::A, ParabolaGraphManager::S_Integrator,
  39. artis::pdevs::qss::Integrator<artis::common::DoubleTime>::VALUE});
  40. }
  41. };
  42. artis::common::RootCoordinator<
  43. artis::common::DoubleTime, artis::pdevs::Coordinator<
  44. artis::common::DoubleTime,
  45. OnlyOneParabolaGraphManager,
  46. artis::pdevs::qss::QSSParameters<ParabolaParameters>>
  47. > rc(0, 5, "root", parameters, artis::common::NoParameters());
  48. rc.attachView("Value", new View());
  49. rc.run();
  50. const View::Values& values = rc.observer().view("Value").get("Value");
  51. for (const auto& value: values) {
  52. double v;
  53. value.second(v);
  54. std::cout << value.first << ": " << v << std::endl;
  55. }
  56. }
  57. void test_predator_prey()
  58. {
  59. PreyPredatorGraphManagerParameters parameters = {{{45.},
  60. {true, true, 0.1, 3},
  61. {0.5, 0.01, 0.01, 0.2}},
  62. {{5000.},
  63. {true, true, 1, 3},
  64. {0.5, 0.01, 0.01, 0.2}}};
  65. class View : public artis::observer::View<artis::common::DoubleTime> {
  66. public:
  67. View()
  68. {
  69. selector("PredatorView",
  70. {PreyPredatorGraphManager::PREDATOR, PredatorGraphManager::S_Integrator,
  71. artis::pdevs::qss::Integrator<artis::common::DoubleTime>::VALUE});
  72. selector("PreyView",
  73. {PreyPredatorGraphManager::PREY, PreyGraphManager::S_Integrator,
  74. artis::pdevs::qss::Integrator<artis::common::DoubleTime>::VALUE});
  75. }
  76. };
  77. artis::common::RootCoordinator<
  78. artis::common::DoubleTime, artis::pdevs::Coordinator<
  79. artis::common::DoubleTime,
  80. PreyPredatorGraphManager,
  81. PreyPredatorGraphManagerParameters>
  82. > rc(0, 100, "root", parameters, artis::common::NoParameters());
  83. rc.attachView("Value", new View());
  84. rc.run();
  85. {
  86. artis::observer::DiscreteTimeIterator<artis::common::DoubleTime> it(
  87. rc.observer().view("Value").get("PredatorView"), 0, 0.1);
  88. while (it.has_next()) {
  89. double v;
  90. (*it).second(v);
  91. std::cout << (*it).first << ";" << v << std::endl;
  92. ++it;
  93. }
  94. }
  95. {
  96. artis::observer::DiscreteTimeIterator<artis::common::DoubleTime> it(
  97. rc.observer().view("Value").get("PreyView"), 0, 0.1);
  98. while (it.has_next()) {
  99. double v;
  100. (*it).second(v);
  101. std::cout << (*it).first << ";" << v << std::endl;
  102. ++it;
  103. }
  104. }
  105. }
  106. int main()
  107. {
  108. // test_parabola();
  109. test_predator_prey();
  110. }