Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix error find by IO test.
authorBruno Donassolo <bruno.donassolo@inria.fr>
Wed, 2 Mar 2022 14:34:08 +0000 (15:34 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 7 Mar 2022 09:23:25 +0000 (10:23 +0100)
Wrong sharing of saturated (but not selected resources)
UT for it

src/kernel/lmm/bmf.cpp
src/kernel/lmm/bmf_test.cpp

index d984788..27f4736 100644 (file)
@@ -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];
index b04c19a..184eb04 100644 (file)
@@ -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();
 }