]> AND Public Git Repository - simgrid.git/blobdiff - src/kernel/lmm/maxmin.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
easy sonar fixes
[simgrid.git] / src / kernel / lmm / maxmin.cpp
index a7514dead9e9eefc95548d7b220dd0138aa63995..be1490391aa4ebb1108a3a58c24ce583259d0aad 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2004-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -7,7 +7,7 @@
 #include <boost/core/demangle.hpp>
 #include <typeinfo>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf, "Logging specific to SURF (maxmin)");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_lmm, kernel, "Kernel Linear Max-Min solver");
 
 double sg_maxmin_precision = 1E-5; /* Change this with --cfg=maxmin/precision:VALUE */
 double sg_surf_precision   = 1E-9; /* Change this with --cfg=surf/precision:VALUE */
@@ -22,6 +22,11 @@ using dyn_light_t = std::vector<int>;
 int Variable::next_rank_   = 1;
 int Constraint::next_rank_ = 1;
 
+Element::Element(Constraint* constraint, Variable* variable, double cweight)
+    : constraint(constraint), variable(variable), consumption_weight(cweight), max_consumption_weight(cweight)
+{
+}
+
 int Element::get_concurrency() const
 {
   // Ignore element with weight less than one (e.g. cross-traffic)
@@ -55,7 +60,7 @@ void Element::increase_concurrency()
 void System::check_concurrency() const
 {
   // These checks are very expensive, so do them only if we want to debug SURF LMM
-  if (not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug))
+  if (not XBT_LOG_ISENABLED(ker_lmm, xbt_log_priority_debug))
     return;
 
   for (Constraint const& cnst : constraint_set) {
@@ -236,13 +241,9 @@ void System::expand(Constraint* cnst, Variable* var, double consumption_weight)
 
   xbt_assert(var->cnsts_.size() < var->cnsts_.capacity(), "Too much constraints");
 
-  var->cnsts_.emplace_back();
+  var->cnsts_.emplace_back(cnst, var, consumption_weight);
   Element& elem = var->cnsts_.back();
 
-  elem.consumption_weight = consumption_weight;
-  elem.constraint         = cnst;
-  elem.variable           = var;
-
   if (var->sharing_penalty_ != 0.0) {
     elem.constraint->enabled_element_set_.push_front(elem);
     elem.increase_concurrency();
@@ -276,6 +277,7 @@ void System::expand_add(Constraint* cnst, Variable* var, double value)
     if (var->sharing_penalty_ != 0.0)
       elem.decrease_concurrency();
 
+    elem.max_consumption_weight = std::max(elem.max_consumption_weight, value);
     if (cnst->sharing_policy_ != Constraint::SharingPolicy::FATPIPE)
       elem.consumption_weight += value;
     else
@@ -657,7 +659,7 @@ template <class CnstList> void System::lmm_solve(CnstList& cnst_list)
   if (selective_update_active)
     remove_all_modified_set();
 
-  if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
+  if (XBT_LOG_ISENABLED(ker_lmm, xbt_log_priority_debug)) {
     print();
   }
 
@@ -720,7 +722,7 @@ int Variable::get_min_concurrency_slack() const
 // loops (after doing the first for enabling==1, and before doing the last for disabling==1)
 void System::enable_var(Variable* var)
 {
-  xbt_assert(not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug) || var->can_enable());
+  xbt_assert(not XBT_LOG_ISENABLED(ker_lmm, xbt_log_priority_debug) || var->can_enable());
 
   var->sharing_penalty_ = var->staged_penalty_;
   var->staged_penalty_  = 0;