Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove useless function pointer.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 14 Mar 2019 13:53:33 +0000 (14:53 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 14 Mar 2019 14:43:46 +0000 (15:43 +0100)
src/kernel/lmm/lagrange.cpp
src/kernel/lmm/maxmin.hpp
teshsuite/surf/lmm_usage/lmm_usage.cpp

index 9df8fb4..fdab111 100644 (file)
@@ -207,7 +207,7 @@ void Lagrange::lagrange_solve()
     /* Improve the value of lambda_i */
     for (Constraint& cnst : active_constraint_set) {
       XBT_DEBUG("Working on cnst (%p)", &cnst);
     /* Improve the value of lambda_i */
     for (Constraint& cnst : active_constraint_set) {
       XBT_DEBUG("Working on cnst (%p)", &cnst);
-      cnst.new_lambda = dichotomy(cnst.lambda, partial_diff_lambda, cnst, dichotomy_min_error);
+      cnst.new_lambda = dichotomy(cnst.lambda, cnst, dichotomy_min_error);
       XBT_DEBUG("Updating lambda : cnst->lambda (%p) : %1.20f -> %1.20f", &cnst, cnst.lambda, cnst.new_lambda);
       cnst.lambda = cnst.new_lambda;
 
       XBT_DEBUG("Updating lambda : cnst->lambda (%p) : %1.20f -> %1.20f", &cnst, cnst.lambda, cnst.new_lambda);
       cnst.lambda = cnst.new_lambda;
 
@@ -264,8 +264,7 @@ void Lagrange::lagrange_solve()
  *
  * @return a double corresponding to the result of the dichotomy process
  */
  *
  * @return a double corresponding to the result of the dichotomy process
  */
-double Lagrange::dichotomy(double init, double diff(double, const Constraint&), const Constraint& cnst,
-                           double min_error)
+double Lagrange::dichotomy(double init, const Constraint& cnst, double min_error)
 {
   double min = init;
   double max = init;
 {
   double min = init;
   double max = init;
@@ -283,15 +282,15 @@ double Lagrange::dichotomy(double init, double diff(double, const Constraint&),
 
   overall_error = 1;
 
 
   overall_error = 1;
 
-  diff_0 = diff(1e-16, cnst);
+  diff_0 = partial_diff_lambda(1e-16, cnst);
   if (diff_0 >= 0) {
     XBT_CDEBUG(surf_lagrange_dichotomy, "returning 0.0 (diff = %e)", diff_0);
     XBT_OUT();
     return 0.0;
   }
 
   if (diff_0 >= 0) {
     XBT_CDEBUG(surf_lagrange_dichotomy, "returning 0.0 (diff = %e)", diff_0);
     XBT_OUT();
     return 0.0;
   }
 
-  double min_diff = diff(min, cnst);
-  double max_diff = diff(max, cnst);
+  double min_diff = partial_diff_lambda(min, cnst);
+  double max_diff = partial_diff_lambda(max, cnst);
 
   while (overall_error > min_error) {
     XBT_CDEBUG(surf_lagrange_dichotomy, "[min, max] = [%1.20f, %1.20f] || diffmin, diffmax = %1.20f, %1.20f", min, max,
 
   while (overall_error > min_error) {
     XBT_CDEBUG(surf_lagrange_dichotomy, "[min, max] = [%1.20f, %1.20f] || diffmin, diffmax = %1.20f, %1.20f", min, max,
@@ -301,7 +300,7 @@ double Lagrange::dichotomy(double init, double diff(double, const Constraint&),
       if (min == max) {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Decreasing min");
         min      = min / 2.0;
       if (min == max) {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Decreasing min");
         min      = min / 2.0;
-        min_diff = diff(min, cnst);
+        min_diff = partial_diff_lambda(min, cnst);
       } else {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Decreasing max");
         max      = min;
       } else {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Decreasing max");
         max      = min;
@@ -311,7 +310,7 @@ double Lagrange::dichotomy(double init, double diff(double, const Constraint&),
       if (min == max) {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing max");
         max      = max * 2.0;
       if (min == max) {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing max");
         max      = max * 2.0;
-        max_diff = diff(max, cnst);
+        max_diff = partial_diff_lambda(max, cnst);
       } else {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing min");
         min      = max;
       } else {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing min");
         min      = max;
@@ -328,7 +327,7 @@ double Lagrange::dichotomy(double init, double diff(double, const Constraint&),
                   min, max - min, min_diff, max_diff);
         break;
       }
                   min, max - min, min_diff, max_diff);
         break;
       }
-      middle_diff = diff(middle, cnst);
+      middle_diff = partial_diff_lambda(middle, cnst);
 
       if (middle_diff < 0) {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing min");
 
       if (middle_diff < 0) {
         XBT_CDEBUG(surf_lagrange_dichotomy, "Increasing min");
index 1e3b0d3..123169d 100644 (file)
@@ -633,8 +633,7 @@ private:
    * Local prototypes to implement the Lagrangian optimization with optimal step, also called dichotomy.
    */
   // computes the value of the dichotomy using a initial values, init, with a specific variable or constraint
    * Local prototypes to implement the Lagrangian optimization with optimal step, also called dichotomy.
    */
   // 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);
+  static double dichotomy(double init, const Constraint& cnst, double min_error);
   // computes the value of the differential of constraint cnst applied to lambda
   static double partial_diff_lambda(double lambda, const Constraint& cnst);
 
   // computes the value of the differential of constraint cnst applied to lambda
   static double partial_diff_lambda(double lambda, const Constraint& cnst);
 
index ff7a329..7c7c8c6 100644 (file)
@@ -41,12 +41,20 @@ static lmm::System* new_system(method_t method)
   }
 }
 
   }
 }
 
-static double dichotomy(double func(double), double min, double max, double min_error)
+double a_test_1 = 0;
+double b_test_1 = 0;
+static double diff_lagrange_test_1(double x)
+{
+  return -(3 / (1 + 3 * x * x / 2) - 3 / (2 * (3 * (a_test_1 - x) * (a_test_1 - x) / 2 + 1)) +
+           3 / (2 * (3 * (b_test_1 - a_test_1 + x) * (b_test_1 - a_test_1 + x) / 2 + 1)));
+}
+
+static double dichotomy(double min, double max, double min_error)
 {
   double overall_error = 2 * min_error;
 
 {
   double overall_error = 2 * min_error;
 
-  double min_func = func(min);
-  double max_func = func(max);
+  double min_func = diff_lagrange_test_1(min);
+  double max_func = diff_lagrange_test_1(max);
 
   if (min_func > 0 && max_func > 0)
     return min - 1.0;
 
   if (min_func > 0 && max_func > 0)
     return min - 1.0;
@@ -72,7 +80,7 @@ static double dichotomy(double func(double), double min, double max, double min_
     if (fabs(min - middle) < 1e-12 || fabs(max - middle) < 1e-12) {
       break;
     }
     if (fabs(min - middle) < 1e-12 || fabs(max - middle) < 1e-12) {
       break;
     }
-    double middle_func = func(middle);
+    double middle_func = diff_lagrange_test_1(middle);
     SHOW_EXPR(middle);
     SHOW_EXPR(middle_func);
 
     SHOW_EXPR(middle);
     SHOW_EXPR(middle_func);
 
@@ -91,14 +99,6 @@ static double dichotomy(double func(double), double min, double max, double min_
   return ((min + max) / 2.0);
 }
 
   return ((min + max) / 2.0);
 }
 
-double a_test_1 = 0;
-double b_test_1 = 0;
-static double diff_lagrange_test_1(double x)
-{
-  return -(3 / (1 + 3 * x * x / 2) - 3 / (2 * (3 * (a_test_1 - x) * (a_test_1 - x) / 2 + 1)) +
-           3 / (2 * (3 * (b_test_1 - a_test_1 + x) * (b_test_1 - a_test_1 + x) / 2 + 1)));
-}
-
 static void test1(method_t method)
 {
   double a = 1.0;
 static void test1(method_t method)
 {
   double a = 1.0;
@@ -148,7 +148,7 @@ static void test1(method_t method)
     } else if (method == LAGRANGE_RENO) {
       a_test_1 = a;
       b_test_1 = b;
     } else if (method == LAGRANGE_RENO) {
       a_test_1 = a;
       b_test_1 = b;
-      x = dichotomy(diff_lagrange_test_1, 0, a, 1e-13);
+      x        = dichotomy(0, a, 1e-13);
 
       if (x < 0)
         x = 0;
 
       if (x < 0)
         x = 0;