From 19808c4f0de08c2ebc4b2b08d1ef1932ae7fd522 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 12 Jun 2019 16:29:18 +0200 Subject: [PATCH] lmm testing: - Refactoring - Add tests for FATPIPE lmm systems --- teshsuite/surf/lmm_usage/lmm_solve.cpp | 122 +++++++++++++++++++++++++ tools/cmake/Tests.cmake | 2 +- 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/teshsuite/surf/lmm_usage/lmm_solve.cpp b/teshsuite/surf/lmm_usage/lmm_solve.cpp index fce074dd08..a45df91f6b 100644 --- a/teshsuite/surf/lmm_usage/lmm_solve.cpp +++ b/teshsuite/surf/lmm_usage/lmm_solve.cpp @@ -125,3 +125,125 @@ TEST_CASE("kernel::lmm Multiple constraint shared systems", "[kernel-lmm-shared- REQUIRE(double_equals(sys_var_5->get_value(), 1.166667, sg_maxmin_precision)); } } + +TEST_CASE("kernel::lmm Single constraint unshared systems", "[kernel-lmm-unshared-single-sys]") +{ + lmm::System* Sys = lmm::make_new_maxmin_system(false); + + SECTION("Variable weight") + { + /* + * System under consideration: + * 1\times\rho_1^{1} + 1\times\rho_2^{2} + 1\times\rho_3^{3} \le 10 + */ + + lmm::Constraint* sys_cnst = Sys->constraint_new(nullptr, 10); + sys_cnst->unshare(); // FATPIPE + lmm::Variable* sys_var_1 = Sys->variable_new(nullptr, 1, 0.0, 1); + lmm::Variable* sys_var_2 = Sys->variable_new(nullptr, 2, 0.0, 1); + lmm::Variable* sys_var_3 = Sys->variable_new(nullptr, 3, 0.0, 1); + + Sys->expand(sys_cnst, sys_var_1, 1); + Sys->expand(sys_cnst, sys_var_2, 1); + Sys->expand(sys_cnst, sys_var_3, 1); + Sys->solve(); + + REQUIRE(double_equals(sys_var_1->get_value(), 10, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_2->get_value(), 5, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_3->get_value(), 3.333333, sg_maxmin_precision)); + } + + SECTION("Consumption weight") + { + /* + * System under consideration: + * 1\times\rho_1^{1} + 2\times\rho_2^{1} + 3\times\rho_3^{1} \le 10 + */ + + lmm::Constraint* sys_cnst = Sys->constraint_new(nullptr, 10); + sys_cnst->unshare(); + lmm::Variable* sys_var_1 = Sys->variable_new(nullptr, 1, 0.0, 1); + lmm::Variable* sys_var_2 = Sys->variable_new(nullptr, 1, 0.0, 1); + lmm::Variable* sys_var_3 = Sys->variable_new(nullptr, 1, 0.0, 1); + + Sys->expand(sys_cnst, sys_var_1, 1); + Sys->expand(sys_cnst, sys_var_2, 2); + Sys->expand(sys_cnst, sys_var_3, 3); + Sys->solve(); + + REQUIRE(double_equals(sys_var_1->get_value(), 3.333333, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_2->get_value(), 3.333333, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_3->get_value(), 3.333333, sg_maxmin_precision)); + } + + SECTION("Consumption weight + variable weight") + { + /* + * Strange system under consideration: + * 56\times\rho_1^{74} + 21\times\rho_2^{6} + 2\times\rho_3^{2} \le 123 + */ + + lmm::Constraint* sys_cnst = Sys->constraint_new(nullptr, 123); + sys_cnst->unshare(); + lmm::Variable* sys_var_1 = Sys->variable_new(nullptr, 56, 0.0, 1); + lmm::Variable* sys_var_2 = Sys->variable_new(nullptr, 21, 0.0, 1); + lmm::Variable* sys_var_3 = Sys->variable_new(nullptr, 3, 0.0, 1); + + Sys->expand(sys_cnst, sys_var_1, 74); + Sys->expand(sys_cnst, sys_var_2, 6); + Sys->expand(sys_cnst, sys_var_3, 2); + Sys->solve(); + + REQUIRE(double_equals(sys_var_1->get_value(), 1.662162, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_2->get_value(), 4.432432, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_3->get_value(), 31.02703, sg_maxmin_precision)); + } +} + +TEST_CASE("kernel::lmm Multiple constraint unshared systems", "[kernel-lmm-unshared-multiple-sys]") +{ + + lmm::System* Sys = lmm::make_new_maxmin_system(false); + + SECTION("3 Constraints system") + { + + /* + * System under consideration: + * 4\times\rho_1^{5.1} + 2.6\times\rho_2^{7} + 1.2\times\rho_3^{8.5} \le 14.6 \\ + * 5\times\rho_4^{6.2} + 2\times\rho_2^{7} + 4.1\times\rho_3^{8.5} \le 40.7 \\ + * 6\times\rho_5^1 \le 7 + */ + + lmm::Constraint* sys_cnst_1 = Sys->constraint_new(nullptr, 14.6); + sys_cnst_1->unshare(); + lmm::Constraint* sys_cnst_2 = Sys->constraint_new(nullptr, 10.7); + sys_cnst_2->unshare(); + lmm::Constraint* sys_cnst_3 = Sys->constraint_new(nullptr, 7); + sys_cnst_3->unshare(); + + lmm::Variable* sys_var_1 = Sys->variable_new(nullptr, 5.1, 0.0, 1); + lmm::Variable* sys_var_2 = Sys->variable_new(nullptr, 7, 0.0, 2); + lmm::Variable* sys_var_3 = Sys->variable_new(nullptr, 8.5, 0.0, 2); + lmm::Variable* sys_var_4 = Sys->variable_new(nullptr, 6.2, 0.0, 1); + lmm::Variable* sys_var_5 = Sys->variable_new(nullptr, 1, 0.0, 1); + + // Constraint 1 + Sys->expand(sys_cnst_1, sys_var_1, 4); + Sys->expand(sys_cnst_1, sys_var_2, 2.6); + Sys->expand(sys_cnst_1, sys_var_3, 1.2); + // Constraint 2 + Sys->expand(sys_cnst_2, sys_var_4, 5); + Sys->expand(sys_cnst_2, sys_var_2, 2); + Sys->expand(sys_cnst_2, sys_var_3, 4.1); + // Constraint 3 + Sys->expand(sys_cnst_3, sys_var_5, 6); + Sys->solve(); + + REQUIRE(double_equals(sys_var_1->get_value(), 3.65, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_2->get_value(), 1.895429, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_3->get_value(), 1.560941, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_4->get_value(), 2.14, sg_maxmin_precision)); + REQUIRE(double_equals(sys_var_5->get_value(), 1.166667, sg_maxmin_precision)); + } +} diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index 085a6359b5..30b8665427 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -101,7 +101,7 @@ set(UNIT_TESTS src/xbt/unit-tests_main.cpp src/xbt/dict_test.cpp src/xbt/dynar_test.cpp src/xbt/xbt_str_test.cpp - teshsuite/surf/lmm_usage/lmm_basic.cpp) + teshsuite/surf/lmm_usage/lmm_solve.cpp) if (SIMGRID_HAVE_MC) set(UNIT_TESTS ${UNIT_TESTS} src/mc/sosp/Snapshot_test.cpp src/mc/sosp/PageStore_test.cpp) else() -- 2.20.1