Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
LMM Testing:
[simgrid.git] / teshsuite / surf / lmm_usage / lmm_basic.cpp
1 /* Copyright (c) 2019. The SimGrid Team. All rights reserved.               */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/include/catch.hpp"
7 #include "src/kernel/lmm/maxmin.hpp"
8 #include "src/surf/surf_interface.hpp"
9 #include "xbt/log.h"
10
11 namespace lmm = simgrid::kernel::lmm;
12
13 TEST_CASE("kernel::lmm Test on small systems", "[kernel-lmm-small-sys]")
14 {
15   lmm::System* Sys = lmm::make_new_maxmin_system(false);
16
17   SECTION("Basic variable weight")
18   {
19     /*
20      * System under consideration:
21      * 1\times\rho_1^{1} + 1\times\rho_2^{2} + 1\times\rho_3^{3} \le 10
22      */
23
24     lmm::Constraint* sys_cnst = Sys->constraint_new(nullptr, 10);
25     lmm::Variable* sys_var_1  = Sys->variable_new(nullptr, 1, 0.0, 1);
26     lmm::Variable* sys_var_2  = Sys->variable_new(nullptr, 2, 0.0, 1);
27     lmm::Variable* sys_var_3  = Sys->variable_new(nullptr, 3, 0.0, 1);
28
29     Sys->expand(sys_cnst, sys_var_1, 1);
30     Sys->expand(sys_cnst, sys_var_2, 1);
31     Sys->expand(sys_cnst, sys_var_3, 1);
32     Sys->solve();
33
34     REQUIRE(double_equals(sys_var_1->get_value(), 5.45455, sg_maxmin_precision));
35     REQUIRE(double_equals(sys_var_2->get_value(), 2.72727, sg_maxmin_precision));
36     REQUIRE(double_equals(sys_var_3->get_value(), 1.81818, sg_maxmin_precision));
37   }
38 }