Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
BMF: Fix bug with threads
authorBruno Donassolo <bruno.donassolo@inria.fr>
Wed, 16 Mar 2022 14:59:25 +0000 (15:59 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Fri, 18 Mar 2022 08:24:44 +0000 (09:24 +0100)
Our fair sharing is related to maxA_ not A_

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

index 1400aaf..0abe968 100644 (file)
@@ -251,7 +251,7 @@ bool BmfSolver::get_alloc(const Eigen::VectorXd& fair_sharing, const allocation_
       if (A_(cnst_idx, player_idx) <= 0.0)
         continue;
 
-      double rate = fair_sharing[cnst_idx] / A_(cnst_idx, player_idx);
+      double rate = fair_sharing[cnst_idx] / maxA_(cnst_idx, player_idx);
       if (min_rate == -1 || rate < min_rate) {
         selected_resource = cnst_idx;
         min_rate          = rate;
@@ -286,7 +286,7 @@ void BmfSolver::set_fair_sharing(const allocation_map_t& alloc, const Eigen::Vec
       if (rho[player] < 0) { // negative rho doesn't make sense, consider the resource is saturated in this case
         fair_sharing[r] = get_maxmin_share(r);
       } else {
-        fair_sharing[r] = A_(r, player) * rho[player];
+        fair_sharing[r] = maxA_(r, player) * rho[player];
       }
     } else { // nobody selects this resource, fair_sharing depends on resource saturation
       // resource r is saturated (A[r,*] * rho > C), divide it among players
index eb3c824..5d04c03 100644 (file)
@@ -609,6 +609,25 @@ TEST_CASE("kernel::bmf Bugs", "[kernel-bmf-bug]")
     REQUIRE(double_equals(rho_2->get_value(), 3, sg_maxmin_precision));
   }
 
+  SECTION("Variable penalty with bounds: thread bug")
+  {
+    /*
+     * Detected by exec-thread.
+     * Fair-sharing vector depends on the penalty too.
+     */
+
+    /* don't change the order of creation, important to trigger the bug */
+    lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 4e8);
+    lmm::Variable* rho_2      = Sys.variable_new(nullptr, .25, 4e8, 1);
+    lmm::Variable* rho_1      = Sys.variable_new(nullptr, 1, 1e8, 1);
+    Sys.expand(sys_cnst, rho_2, 1);
+    Sys.expand(sys_cnst, rho_1, 1);
+    Sys.solve();
+
+    REQUIRE(double_equals(rho_1->get_value(), 8e7, sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), 3.2e8, sg_maxmin_precision));
+  }
+
   Sys.variable_free_all();
 }