test.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "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 >;
  32. using Factory = ModelFactory < Model, int, Creator >;
  33. DECLARE_MODEL(AModel, ::Model, ::Factory);
  34. DECLARE_MODEL(BModel, ::Model, ::Factory);
  35. DECLARE_MODEL(RootModel, ::Model, ::Factory);
  36. typedef artis::kernel::Simulator < RootModel,
  37. artis::utils::DoubleTime,
  38. ModelParameters,
  39. GlobalParameters > ASimulator;
  40. typedef artis::builder::Builder < ::Factory,
  41. RootModel,
  42. artis::utils::DoubleTime,
  43. ModelParameters,
  44. GlobalParameters > ABuilder;
  45. typedef artis::context::Context < artis::utils::DoubleTime > AContext;
  46. class AView : public artis::observer::View < artis::utils::DoubleTime,
  47. ModelParameters >
  48. {
  49. public:
  50. AView()
  51. {
  52. selector("A::I", INT, { RootModel::A, AModel::IX });
  53. selector("A::B", BOOL, { RootModel::A, AModel::BX });
  54. selector("A::D", DOUBLE, { RootModel::A, AModel::DX });
  55. selector("B::I", INT, { RootModel::B, BModel::IY });
  56. selector("B::B", BOOL, { RootModel::B, BModel::BY });
  57. selector("B::D", DOUBLE, { RootModel::B, BModel::DY });
  58. }
  59. virtual ~AView()
  60. { }
  61. };
  62. typedef artis::observer::Output < artis::utils::DoubleTime,
  63. ModelParameters > AnOutput;
  64. //TEST_CASE("Simulator_tests", "simple")
  65. int main()
  66. {
  67. GlobalParameters globalParameters;
  68. ModelParameters modelParameters;
  69. /**********************/
  70. // AModel a;
  71. // artis::kernel::Any v(&AModel::_ix);
  72. // a.init(0, modelParameters);
  73. // artis::kernel::to_value < AModel >(v, &a);
  74. /**********************/
  75. ABuilder builder("{ \"type\": \"RootModel\", " \
  76. "\"name\": \"root\", " \
  77. "\"states\": [ " \
  78. "{ \"name\":\"_i\", \"type\":\"int\"} " \
  79. "]," \
  80. "\"submodels\": [ " \
  81. "{ \"type\": \"AModel\", " \
  82. "\"name\": \"_a\", " \
  83. "\"internals\": [" \
  84. "{ \"name\":\"_ix\", \"type\":\"int\"}, " \
  85. "{ \"name\":\"_bx\", \"type\":\"bool\"}, " \
  86. "{ \"name\":\"_dx\", \"type\":\"double\"} " \
  87. "] }, " \
  88. "{ \"type\": \"BModel\", " \
  89. "\"name\": \"_b\", " \
  90. "\"internals\": [" \
  91. "{ \"name\":\"_iy\", \"type\":\"int\"}, " \
  92. "{ \"name\":\"_by\", \"type\":\"bool\"}, " \
  93. "{ \"name\":\"_dy\", \"type\":\"double\"} " \
  94. "], " \
  95. "\"externals\": [" \
  96. "{ \"name\":\"_ix\", \"type\":\"int\"}, " \
  97. "{ \"name\":\"_bx\", \"type\":\"bool\"}, " \
  98. "{ \"name\":\"_dx\", \"type\":\"double\"} " \
  99. "], " \
  100. "\"states\": [ " \
  101. "{ \"name\":\"_n\", \"type\":\"int\"} " \
  102. "] }" \
  103. "] }");
  104. AContext context(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
  105. artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
  106. ASimulator simulator(builder.build(), globalParameters);
  107. simulator.attachView("Root", new AView);
  108. ::Trace::trace().clear();
  109. simulator.init(0, modelParameters);
  110. simulator.run(context);
  111. std::cout << ::Trace::trace().elements().to_string() << std::endl;
  112. AnOutput output(simulator.observer());
  113. output();
  114. return 0;
  115. }