Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make func_f/fp/fpi static methods of lmm::Lagrange.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 28 Mar 2018 08:53:57 +0000 (10:53 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 28 Mar 2018 09:06:32 +0000 (11:06 +0200)
src/kernel/lmm/lagrange.cpp
src/kernel/lmm/maxmin.cpp
src/kernel/lmm/maxmin.hpp
src/surf/network_cm02.cpp
teshsuite/surf/lmm_usage/lmm_usage.cpp

index db92f1e..37143ad 100644 (file)
@@ -26,10 +26,6 @@ namespace simgrid {
 namespace kernel {
 namespace lmm {
 
 namespace kernel {
 namespace lmm {
 
-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);
 System* make_new_lagrange_system(bool selective_update)
 {
   return new Lagrange(selective_update);
@@ -80,7 +76,7 @@ double Lagrange::new_value(const Variable& var)
     tmp += var.mu;
   XBT_DEBUG("\t Working on var (%p). cost = %e; Weight = %e", &var, tmp, var.sharing_weight);
   // uses the partial differential inverse function
     tmp += var.mu;
   XBT_DEBUG("\t Working on var (%p). cost = %e; Weight = %e", &var, tmp, var.sharing_weight);
   // uses the partial differential inverse function
-  return var.func_fpi(var, tmp);
+  return func_fpi(var, tmp);
 }
 
 double Lagrange::new_mu(const Variable& var)
 }
 
 double Lagrange::new_mu(const Variable& var)
@@ -91,7 +87,7 @@ double Lagrange::new_mu(const Variable& var)
   for (Element const& elem : var.cnsts) {
     sigma_i += elem.constraint->lambda;
   }
   for (Element const& elem : var.cnsts) {
     sigma_i += elem.constraint->lambda;
   }
-  mu_i = var.func_fp(var, var.bound) - sigma_i;
+  mu_i = func_fp(var, var.bound) - sigma_i;
   if (mu_i < 0.0)
     return 0.0;
   return mu_i;
   if (mu_i < 0.0)
     return 0.0;
   return mu_i;
@@ -115,7 +111,7 @@ double Lagrange::dual_objective()
 
     XBT_DEBUG("var %p : sigma_i = %1.20f", &var, sigma_i);
 
 
     XBT_DEBUG("var %p : sigma_i = %1.20f", &var, sigma_i);
 
-    obj += var.func_f(var, var.func_fpi(var, sigma_i)) - sigma_i * var.func_fpi(var, sigma_i);
+    obj += func_f(var, func_fpi(var, sigma_i)) - sigma_i * func_fpi(var, sigma_i);
 
     if (var.bound > 0)
       obj += var.mu * var.bound;
 
     if (var.bound > 0)
       obj += var.mu * var.bound;
@@ -396,7 +392,7 @@ double Lagrange::partial_diff_lambda(double lambda, const Constraint& cnst)
     // replace value of cnst.lambda by the value of parameter lambda
     sigma_i = (sigma_i - cnst.lambda) + lambda;
 
     // replace value of cnst.lambda by the value of parameter lambda
     sigma_i = (sigma_i - cnst.lambda) + lambda;
 
-    diff += -var.func_fpi(var, sigma_i);
+    diff += -func_fpi(var, sigma_i);
   }
 
   diff += cnst.bound;
   }
 
   diff += cnst.bound;
@@ -410,19 +406,21 @@ double Lagrange::partial_diff_lambda(double lambda, const Constraint& cnst)
  *
  *  \param func_fpi  inverse of the partial differential of f (f prime inverse, (f')^{-1})
  *
  *
  *  \param func_fpi  inverse of the partial differential of f (f prime inverse, (f')^{-1})
  *
- *  Set default functions to the ones passed as parameters. This is a polymorphism in C pure, enjoy the roots of
- *  programming.
- *
+ *  Set default functions to the ones passed as parameters.
  */
  */
-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))
+void Lagrange::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;
-  func_fpi_def = func_fpi;
+  Lagrange::func_f   = func_f;
+  Lagrange::func_fp  = func_fp;
+  Lagrange::func_fpi = func_fpi;
 }
 
 }
 
+double (*Lagrange::func_f)(const Variable&, double);
+double (*Lagrange::func_fp)(const Variable&, double);
+double (*Lagrange::func_fpi)(const Variable&, double);
+
 /**************** Vegas and Reno functions *************************/
 /* NOTE for Reno: all functions consider the network coefficient (alpha) equal to 1. */
 
 /**************** Vegas and Reno functions *************************/
 /* NOTE for Reno: all functions consider the network coefficient (alpha) equal to 1. */
 
index 42de206..0b27a67 100644 (file)
@@ -725,9 +725,6 @@ void Variable::initialize(simgrid::kernel::resource::Action* id_value, double sh
   visited           = visited_value;
   mu                = 0.0;
   new_mu            = 0.0;
   visited           = visited_value;
   mu                = 0.0;
   new_mu            = 0.0;
-  func_f            = func_f_def;
-  func_fp           = func_fp_def;
-  func_fpi          = func_fpi_def;
 
   xbt_assert(not variable_set_hook.is_linked());
   xbt_assert(not saturated_variable_set_hook.is_linked());
 
   xbt_assert(not variable_set_hook.is_linked());
   xbt_assert(not saturated_variable_set_hook.is_linked());
index f0cafe7..8c006f5 100644 (file)
@@ -137,10 +137,6 @@ namespace lmm {
 
 /** Default functions associated to the chosen protocol. When using the lagrangian approach. */
 
 
 /** Default functions associated to the chosen protocol. When using the lagrangian approach. */
 
-XBT_PUBLIC 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));
-
 XBT_PUBLIC double func_reno_f(const Variable& var, double x);
 XBT_PUBLIC double func_reno_fp(const Variable& var, double x);
 XBT_PUBLIC double func_reno_fpi(const Variable& var, double x);
 XBT_PUBLIC double func_reno_f(const Variable& var, double x);
 XBT_PUBLIC double func_reno_fp(const Variable& var, double x);
 XBT_PUBLIC double func_reno_fpi(const Variable& var, double x);
@@ -409,9 +405,6 @@ public:
   /* \begin{For Lagrange only} */
   double mu;
   double new_mu;
   /* \begin{For Lagrange only} */
   double mu;
   double new_mu;
-  double (*func_f)(const Variable& var, double x);   /* (f)    */
-  double (*func_fp)(const Variable& var, double x);  /* (f')    */
-  double (*func_fpi)(const Variable& var, double x); /* (f')^{-1}    */
   /* \end{For Lagrange only} */
 
 private:
   /* \end{For Lagrange only} */
 
 private:
@@ -625,12 +618,20 @@ public:
   explicit Lagrange(bool selective_update) : System(selective_update) {}
   void solve() final { lagrange_solve(); }
 
   explicit Lagrange(bool selective_update) : System(selective_update) {}
   void solve() final { lagrange_solve(); }
 
+  static 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));
+
 private:
   void lagrange_solve();
 
   bool check_feasible(bool warn);
   double dual_objective();
 
 private:
   void lagrange_solve();
 
   bool check_feasible(bool warn);
   double dual_objective();
 
+  static double (*func_f)(const Variable& var, double x);   /* (f)    */
+  static double (*func_fp)(const Variable& var, double x);  /* (f')    */
+  static double (*func_fpi)(const Variable& var, double x); /* (f')^{-1}    */
+
   /*
    * Local prototypes to implement the Lagrangian optimization with optimal step, also called dichotomy.
    */
   /*
    * Local prototypes to implement the Lagrangian optimization with optimal step, also called dichotomy.
    */
@@ -648,10 +649,6 @@ XBT_PUBLIC System* make_new_maxmin_system(bool selective_update);
 XBT_PUBLIC System* make_new_fair_bottleneck_system(bool selective_update);
 XBT_PUBLIC System* make_new_lagrange_system(bool selective_update);
 
 XBT_PUBLIC System* make_new_fair_bottleneck_system(bool selective_update);
 XBT_PUBLIC System* make_new_lagrange_system(bool selective_update);
 
-extern XBT_PRIVATE double (*func_f_def)(const Variable&, double);
-extern XBT_PRIVATE double (*func_fp_def)(const Variable&, double);
-extern XBT_PRIVATE double (*func_fpi_def)(const Variable&, double);
-
 /** @} */
 }
 }
 /** @} */
 }
 }
index b4c77ac..72bce21 100644 (file)
@@ -87,8 +87,8 @@ void surf_network_model_init_Reno()
   if (surf_network_model)
     return;
 
   if (surf_network_model)
     return;
 
-  set_default_protocol_function(simgrid::kernel::lmm::func_reno_f, simgrid::kernel::lmm::func_reno_fp,
-                                simgrid::kernel::lmm::func_reno_fpi);
+  using namespace simgrid::kernel;
+  lmm::Lagrange::set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi);
 
   xbt_cfg_setdefault_double("network/latency-factor", 13.01);
   xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
 
   xbt_cfg_setdefault_double("network/latency-factor", 13.01);
   xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
@@ -104,8 +104,8 @@ void surf_network_model_init_Reno2()
   if (surf_network_model)
     return;
 
   if (surf_network_model)
     return;
 
-  set_default_protocol_function(simgrid::kernel::lmm::func_reno2_f, simgrid::kernel::lmm::func_reno2_fp,
-                                simgrid::kernel::lmm::func_reno2_fpi);
+  using namespace simgrid::kernel;
+  lmm::Lagrange::set_default_protocol_function(lmm::func_reno2_f, lmm::func_reno2_fp, lmm::func_reno2_fpi);
 
   xbt_cfg_setdefault_double("network/latency-factor", 13.01);
   xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
 
   xbt_cfg_setdefault_double("network/latency-factor", 13.01);
   xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
@@ -120,8 +120,8 @@ void surf_network_model_init_Vegas()
   if (surf_network_model)
     return;
 
   if (surf_network_model)
     return;
 
-  set_default_protocol_function(simgrid::kernel::lmm::func_vegas_f, simgrid::kernel::lmm::func_vegas_fp,
-                                simgrid::kernel::lmm::func_vegas_fpi);
+  using namespace simgrid::kernel;
+  lmm::Lagrange::set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi);
 
   xbt_cfg_setdefault_double("network/latency-factor", 13.01);
   xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
 
   xbt_cfg_setdefault_double("network/latency-factor", 13.01);
   xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97);
index 02d5eae..6bfc152 100644 (file)
@@ -104,9 +104,9 @@ static void test1(method_t method)
   double b = 10.0;
 
   if (method == LAGRANGE_VEGAS)
   double b = 10.0;
 
   if (method == LAGRANGE_VEGAS)
-    set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi);
+    lmm::Lagrange::set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi);
   else if (method == LAGRANGE_RENO)
   else if (method == LAGRANGE_RENO)
-    set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi);
+    lmm::Lagrange::set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi);
 
   lmm::System* Sys    = new_system(method, true);
   lmm::Constraint* L1 = Sys->constraint_new(nullptr, a);
 
   lmm::System* Sys    = new_system(method, true);
   lmm::Constraint* L1 = Sys->constraint_new(nullptr, a);
@@ -190,9 +190,9 @@ static void test1(method_t method)
 static void test2(method_t method)
 {
   if (method == LAGRANGE_VEGAS)
 static void test2(method_t method)
 {
   if (method == LAGRANGE_VEGAS)
-    set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi);
+    lmm::Lagrange::set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi);
   if (method == LAGRANGE_RENO)
   if (method == LAGRANGE_RENO)
-    set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi);
+    lmm::Lagrange::set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi);
 
   lmm::System* Sys = new_system(method, true);
 
 
   lmm::System* Sys = new_system(method, true);
 
@@ -256,9 +256,9 @@ static void test3(method_t method)
   A[14][15] =                                        1.0;
 
   if (method == LAGRANGE_VEGAS)
   A[14][15] =                                        1.0;
 
   if (method == LAGRANGE_VEGAS)
-    set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi);
+    lmm::Lagrange::set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi);
   if (method == LAGRANGE_RENO)
   if (method == LAGRANGE_RENO)
-    set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi);
+    lmm::Lagrange::set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi);
 
   lmm::System* Sys = new_system(method, true);
 
 
   lmm::System* Sys = new_system(method, true);