test.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * @file test/test.cpp
  3. * @author See the AUTHORS file
  4. */
  5. /*
  6. * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. //#define CATCH_CONFIG_MAIN
  22. //#include <test/catch.hpp>
  23. #include <test/models.hpp>
  24. #include <artis/builder/Builder.hpp>
  25. #include <artis/builder/ModelFactory.hpp>
  26. #include <artis/kernel/Simulator.hpp>
  27. #include <artis/observer/Output.hpp>
  28. #include <artis/utils/DateTime.hpp>
  29. using namespace artis::kernel;
  30. using namespace artis::builder;
  31. using Creator = ObjectCreator < Model, artis::utils::DoubleTime,
  32. ModelParameters >;
  33. using Factory = ModelFactory < Model, int, Creator, artis::utils::DoubleTime,
  34. ModelParameters >;
  35. DECLARE_MODEL(AModel, ::Model, ::Factory, artis::utils::DoubleTime,
  36. ModelParameters);
  37. DECLARE_MODEL(BModel, ::Model, ::Factory, artis::utils::DoubleTime,
  38. ModelParameters);
  39. DECLARE_MODEL(RootModel, ::Model, ::Factory, artis::utils::DoubleTime,
  40. ModelParameters);
  41. typedef artis::kernel::Simulator < RootModel,
  42. artis::utils::DoubleTime,
  43. ModelParameters,
  44. GlobalParameters > ASimulator;
  45. typedef artis::builder::Builder < ::Factory,
  46. RootModel,
  47. artis::utils::DoubleTime,
  48. ModelParameters,
  49. GlobalParameters > ABuilder;
  50. typedef artis::context::Context < artis::utils::DoubleTime > AContext;
  51. class AView : public artis::observer::View < artis::utils::DoubleTime,
  52. ModelParameters >
  53. {
  54. public:
  55. AView()
  56. {
  57. selector("A::I", INT, { RootModel::A, AModel::IX });
  58. selector("A::B", BOOL, { RootModel::A, AModel::BX });
  59. selector("A::D", DOUBLE, { RootModel::A, AModel::DX });
  60. selector("B::I", INT, { RootModel::B, BModel::IY });
  61. selector("B::B", BOOL, { RootModel::B, BModel::BY });
  62. selector("B::D", DOUBLE, { RootModel::B, BModel::DY });
  63. }
  64. virtual ~AView()
  65. { }
  66. };
  67. typedef artis::observer::Output < artis::utils::DoubleTime,
  68. ModelParameters > AnOutput;
  69. //TEST_CASE("Simulator_tests", "simple")
  70. int main()
  71. {
  72. GlobalParameters globalParameters;
  73. ModelParameters modelParameters;
  74. /**********************/
  75. // AModel a;
  76. // artis::kernel::Any v(&AModel::_ix);
  77. // a.init(0, modelParameters);
  78. // artis::kernel::to_value < AModel >(v, &a);
  79. /**********************/
  80. ABuilder builder("{ \"type\": \"RootModel\", " \
  81. "\"name\": \"root\", " \
  82. "\"states\": [ " \
  83. "{ \"name\":\"_i\", \"type\":\"int\"} " \
  84. "]," \
  85. "\"submodels\": [ " \
  86. "{ \"type\": \"AModel\", " \
  87. "\"name\": \"_a\", " \
  88. "\"internals\": [" \
  89. "{ \"name\":\"_ix\", \"type\":\"int\"}, " \
  90. "{ \"name\":\"_bx\", \"type\":\"bool\"}, " \
  91. "{ \"name\":\"_dx\", \"type\":\"double\"} " \
  92. "] }, " \
  93. "{ \"type\": \"BModel\", " \
  94. "\"name\": \"_b\", " \
  95. "\"internals\": [" \
  96. "{ \"name\":\"_iy\", \"type\":\"int\"}, " \
  97. "{ \"name\":\"_by\", \"type\":\"bool\"}, " \
  98. "{ \"name\":\"_dy\", \"type\":\"double\"} " \
  99. "], " \
  100. "\"externals\": [" \
  101. "{ \"name\":\"_ix\", \"type\":\"int\"}, " \
  102. "{ \"name\":\"_bx\", \"type\":\"bool\"}, " \
  103. "{ \"name\":\"_dx\", \"type\":\"double\"} " \
  104. "], " \
  105. "\"states\": [ " \
  106. "{ \"name\":\"_n\", \"type\":\"int\"} " \
  107. "] }" \
  108. "] }");
  109. AContext context(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
  110. artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
  111. ASimulator simulator(builder.build(), globalParameters);
  112. simulator.attachView("Root", new AView);
  113. ::Trace::trace().clear();
  114. simulator.init(0, modelParameters);
  115. simulator.run(context);
  116. std::cout << ::Trace::trace().elements().to_string() << std::endl;
  117. AnOutput output(simulator.observer());
  118. output();
  119. return 0;
  120. }