From 055d4854bd276b9851df81ef5210d8c101ce8589 Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Wed, 2 Mar 2022 15:34:08 +0100 Subject: [PATCH] Fix error find by IO test. Wrong sharing of saturated (but not selected resources) UT for it --- src/kernel/lmm/bmf.cpp | 3 +-- src/kernel/lmm/bmf_test.cpp | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/kernel/lmm/bmf.cpp b/src/kernel/lmm/bmf.cpp index d984788845..27f4736e77 100644 --- a/src/kernel/lmm/bmf.cpp +++ b/src/kernel/lmm/bmf.cpp @@ -245,8 +245,7 @@ void BmfSolver::set_fair_sharing(const allocation_map_t& alloc, const Eigen::Vec double consumption_r = A_.row(r) * rho; double_update(&consumption_r, C_[r], sg_maxmin_precision); if (consumption_r > 0.0) { - int n_players = std::count_if(A_.row(r).data(), A_.row(r).data() + A_.row(r).size(), - [](double v) { return double_positive(v, sg_maxmin_precision); }); + int n_players = (A_.row(r).array() > 0).count(); fair_sharing[r] = C_[r] / n_players; } else { fair_sharing[r] = C_[r]; diff --git a/src/kernel/lmm/bmf_test.cpp b/src/kernel/lmm/bmf_test.cpp index b04c19a839..184eb04da7 100644 --- a/src/kernel/lmm/bmf_test.cpp +++ b/src/kernel/lmm/bmf_test.cpp @@ -307,6 +307,46 @@ TEST_CASE("kernel::bmf Advanced tests", "[kernel-bmf-advanced]") REQUIRE(double_equals(rho_3->get_value(), 4.0 / 9.0, sg_maxmin_precision)); } + SECTION("IO - example") + { + /* + * Two flows sharing 1 disk + * read, write and readwrite constraint + * + * In details: + * o System: a1 * p1 * \rho1 + a2 * p2 * \rho2 < C1 + * o System: a1 * p1 * \rho1 + a2 * p2 * \rho2 < C2 + * o System: a1 * p1 * \rho1 + a2 * p2 * \rho2 < C3 + * o C1 == C2 == C3 + * o consumption_weight: a1=1, a2=1 + * o sharing_penalty: p1=1, p2=1 + * + * Expectations + * o rho1 = rho2 = C/2 + + * Matrices: + * [1 10] * [rho1 rho2] = [1] + * [10 1] [1] + */ + + lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 1e6); + lmm::Constraint* sys_cnst2 = Sys.constraint_new(nullptr, 1e6); + lmm::Constraint* sys_cnst3 = Sys.constraint_new(nullptr, 1e6); + lmm::Variable* rho_1 = Sys.variable_new(nullptr, 1, -1, 3); + lmm::Variable* rho_2 = Sys.variable_new(nullptr, 1, -1, 3); + + /* A' and C' matrices are dependent on the order of initialization + * this order is needed to identify a bug in the solver */ + Sys.expand(sys_cnst2, rho_2, 1); + Sys.expand(sys_cnst, rho_1, 1); + Sys.expand(sys_cnst3, rho_1, 1); + Sys.expand(sys_cnst3, rho_2, 1); + Sys.solve(); + + REQUIRE(double_equals(rho_1->get_value(), 1e6 / 2.0, sg_maxmin_precision)); + REQUIRE(double_equals(rho_2->get_value(), 1e6 / 2.0, sg_maxmin_precision)); + } + Sys.variable_free_all(); } -- 2.20.1