Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define FairBottleneck and Lagrange as subclasses of lmm::System.
[simgrid.git] / src / kernel / lmm / lagrange.cpp
index c244c67..bebf316 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2018. 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. */
@@ -33,11 +33,14 @@ double (*func_f_def)(const Variable&, double);
 double (*func_fp_def)(const Variable&, double);
 double (*func_fpi_def)(const Variable&, double);
 
+System* make_new_lagrange_system(bool selective_update)
+{
+  return new Lagrange(selective_update);
+}
+
 /*
  * Local prototypes to implement the Lagrangian optimization with optimal step, also called dichotomy.
  */
-// solves the proportional fairness using a Lagrangian optimization with dichotomy step
-void lagrange_solve(lmm_system_t sys);
 // computes the value of the dichotomy using a initial values, init, with a specific variable or constraint
 static double dichotomy(double init, double diff(double, const Constraint&), const Constraint& cnst, double min_error);
 // computes the value of the differential of constraint cnst applied to lambda
@@ -49,7 +52,7 @@ static int __check_feasible(const CnstList& cnst_list, const VarList& var_list,
   for (Constraint const& cnst : cnst_list) {
     double tmp = 0;
     for (Element const& elem : cnst.enabled_element_set) {
-      lmm_variable_t var = elem.variable;
+      Variable* var = elem.variable;
       xbt_assert(var->sharing_weight > 0);
       tmp += var->value;
     }
@@ -137,7 +140,8 @@ static double dual_objective(const VarList& var_list, const CnstList& cnst_list)
   return obj;
 }
 
-void lagrange_solve(lmm_system_t sys)
+// solves the proportional fairness using a Lagrangian optimization with dichotomy step
+void Lagrange::lagrange_solve()
 {
   /* Lagrange Variables. */
   int max_iterations       = 100;
@@ -152,14 +156,14 @@ void lagrange_solve(lmm_system_t sys)
   XBT_DEBUG("#### Minimum error tolerated (dichotomy) : %e", dichotomy_min_error);
 
   if (XBT_LOG_ISENABLED(surf_lagrange, xbt_log_priority_debug)) {
-    sys->print();
+    print();
   }
 
-  if (not sys->modified)
+  if (not modified)
     return;
 
   /* Initialize lambda. */
-  auto& cnst_list = sys->active_constraint_set;
+  auto& cnst_list = active_constraint_set;
   for (Constraint& cnst : cnst_list) {
     cnst.lambda     = 1.0;
     cnst.new_lambda = 2.0;
@@ -169,7 +173,7 @@ void lagrange_solve(lmm_system_t sys)
   /*
    * Initialize the var_list variable with only the active variables. Initialize mu.
    */
-  auto& var_list = sys->variable_set;
+  auto& var_list = variable_set;
   for (Variable& var : var_list) {
     if (not var.sharing_weight)
       var.value = 0.0;
@@ -263,7 +267,7 @@ void lagrange_solve(lmm_system_t sys)
   }
 
   if (XBT_LOG_ISENABLED(surf_lagrange, xbt_log_priority_debug)) {
-    sys->print();
+    print();
   }
 }
 
@@ -422,9 +426,9 @@ static double partial_diff_lambda(double lambda, const Constraint& cnst)
  *  programming.
  *
  */
-void lmm_set_default_protocol_function(double (*func_f)(const Variable& var, double x),
-                                       double (*func_fp)(const Variable& var, double x),
-                                       double (*func_fpi)(const Variable& var, double x))
+void set_default_protocol_function(double (*func_f)(const Variable& var, double x),
+                                   double (*func_fp)(const Variable& var, double x),
+                                   double (*func_fpi)(const Variable& var, double x))
 {
   func_f_def   = func_f;
   func_fp_def  = func_fp;