Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9129ce6a66960d7b3b90ec32663e52e94ac738fb
[simgrid.git] / teshsuite / surf / lmm_usage / lmm_basic.cpp
1 #include "src/include/catch.hpp"
2 #include "src/kernel/lmm/maxmin.hpp"
3 #include "src/surf/surf_interface.hpp"
4 #include "xbt/log.h"
5
6 #define DOUBLE_PRECISION 0.00001
7
8 // Namespace shortcut
9 namespace lmm = simgrid::kernel::lmm;
10
11 // XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
12 // XBT_INFO("V1=%g V2=%g V3=%g",V1->get_value(),V2->get_value(),V3->get_value());
13
14 TEST_CASE("Test on small systems", "[lmm-small-systems]")
15 {
16   lmm::System* Sys = lmm::make_new_maxmin_system(false);
17
18   SECTION("Check variables weight (sharing_weight)")
19   {
20
21     // Create constraint
22     lmm::Constraint* C = Sys->constraint_new(nullptr, 10);
23
24     // Create the 3 variables (with increasing weight from 1 to 3)
25     lmm::Variable* V1 =
26         Sys->variable_new(nullptr, 1, 0.0, 1); // id=nullptr, weight_value=1, bound=0, number_of_constraints=1
27     lmm::Variable* V2 = Sys->variable_new(nullptr, 2, 0.0, 1);
28     lmm::Variable* V3 = Sys->variable_new(nullptr, 3, 0.0, 1);
29
30     // Link Variables to Constraint with constant weight 1
31     Sys->expand(C, V1, 1);
32     Sys->expand(C, V2, 1);
33     Sys->expand(C, V3, 1);
34
35     Sys->solve();
36
37     // Compare with theorical values
38     REQUIRE(double_equals(V1->get_value(), 5.45455, DOUBLE_PRECISION));
39     REQUIRE(double_equals(V2->get_value(), 2.72727, DOUBLE_PRECISION));
40     REQUIRE(double_equals(V3->get_value(), 1.81818, DOUBLE_PRECISION));
41   }
42 }