tests.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * @file tests/boost_graph/tests.cpp
  3. * @author The PARADEVS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * PARADEVS - the multimodeling and simulation environment
  8. * This file is a part of the PARADEVS environment
  9. *
  10. * Copyright (C) 2013 ULCO http://www.univ-litoral.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 <common/RootCoordinator.hpp>
  26. #include <tests/boost_graph/models.hpp>
  27. #include <tests/boost_graph/graph_manager.hpp>
  28. using namespace paradevs::common;
  29. using namespace paradevs::common::scheduler;
  30. using namespace paradevs::pdevs;
  31. using namespace paradevs::tests::boost_graph;
  32. void flat_test()
  33. {
  34. RootCoordinator < MyTime, paradevs::pdevs::Coordinator <
  35. MyTime, VectorScheduler < MyTime >, InBuildFlatGraphManager <
  36. FlatGraphBuilder >, paradevs::common::NoParameters,
  37. paradevs::common::NoParameters >
  38. > rc(0, 100, "root", NoParameters(), NoParameters());
  39. rc.run();
  40. }
  41. void hierarchical_test()
  42. {
  43. RootCoordinator < MyTime, paradevs::pdevs::Coordinator <
  44. MyTime, VectorScheduler < MyTime >, HierarchicalGraphManager <
  45. HierarchicalGraphBuilder >, paradevs::common::NoParameters,
  46. paradevs::common::NoParameters > > rc(0, 100, "root",
  47. NoParameters(), NoParameters());
  48. rc.run();
  49. }
  50. int main()
  51. {
  52. // flat_test();
  53. // hierarchical_test();
  54. class M;
  55. struct A
  56. {
  57. double time;
  58. M* model;
  59. A(double _time, M* _model)
  60. {
  61. time = _time;
  62. model = _model;
  63. }
  64. };
  65. struct ACompare
  66. : std::binary_function < A, A, bool >
  67. {
  68. bool operator()(const A &left, const A &right) const
  69. { return left.time > right.time; }
  70. };
  71. typedef boost::heap::fibonacci_heap < A, boost::heap::compare <
  72. ACompare > > Heap;
  73. typedef Heap::handle_type HeapHandle;
  74. class M
  75. {
  76. public:
  77. M(int a)
  78. {
  79. _a = a;
  80. }
  81. int a() const
  82. { return _a; }
  83. HeapHandle heap_id() const
  84. { return _heap_id; }
  85. void heap_id(HeapHandle id)
  86. { _heap_id = id; }
  87. private:
  88. int _a;
  89. HeapHandle _heap_id;
  90. };
  91. Heap heap;
  92. M* m1 = new M(1);
  93. M* m2 = new M(2);
  94. m1->heap_id(heap.push(A(0, m1)));
  95. m2->heap_id(heap.push(A(0, m2)));
  96. (*m1->heap_id()).time = 1;
  97. heap.decrease(m1->heap_id());
  98. (*m2->heap_id()).time = 1;
  99. heap.decrease(m2->heap_id());
  100. std::cout << "Scheduler = { ";
  101. while (not heap.empty()) {
  102. std::cout << "(" << heap.top().time << "," << heap.top().model->a()
  103. << ") ";
  104. heap.pop();
  105. }
  106. std::cout << "}" << std::endl;
  107. return 0;
  108. }